코어 데이터를 사용하고 있으며 속성을 읽으려고하면 0과 1 같은 숫자로 읽습니다. 여기에 내 핵심 데이터가 있습니다. 설정. 내 마지막 목표는 true 또는 false로 부울을 저장 한 다음 그 값을 읽는 것입니다. 설치 과정에서 잘못되었거나 뭔가 빠졌습니까? 나는 그 게시물을 보았습니다 iPhone: Save boolean into Core Data OBJ C에있는 것 외에도, 나는 이제 데이터 모델 옵션에서 부울을 사용할 수 있다고 믿습니다.코어 데이터를 사용하고 있으며 내 불리언 값은 숫자로 읽습니다.
func saveFilters(bathAny: Bool, bath1: Bool, bath2: Bool, bath3: Bool, bath4: Bool){
let context = getContext()
let entity = NSEntityDescription.entity(forEntityName: "FilterCoreDataObj", in: context)
let transc = NSManagedObject(entity: entity!, insertInto: context)
//SET ENTITY VALUES
transc.setValue(bathAny, forKey: "bathAny")
transc.setValue(bath1, forKey: "bath1")
transc.setValue(bath2, forKey: "bath2")
transc.setValue(bath3, forKey: "bath3")
transc.setValue(bath4, forKey: "bath4")
do {
try context.save()
print("saved")
} catch let error as NSError {
print("could not save \(error), \(error.userInfo)")
} catch {
}
}
읽기 Func을
func getTranscriptions(bathAny: Bool, bath1: Bool, bath2: Bool, bath3: Bool, bath4: Bool) {
let fetchRequest: NSFetchRequest<FilterCoreDataObj> = FilterCoreDataObj.fetchRequest()
do {
let searchResults = try getContext().fetch(fetchRequest)
print("num of results = \(searchResults.count)")
for trans in searchResults {
print("bath 1 \(trans.value(forKey: "bath1"))")
}
} catch {
print("Error with request: \(error)")
}
}
가능한 복제본 : [iPhone : 부울을 코어 데이터에 저장] (http://stackoverflow.com/questions/2937945/iphone-save-boolean-into-core-data) – keithbhunter
이것은 매우 신속하며 핵심 데이터가 lot 3을 사용하십시오. 또한 datModel에서 속성을 다음과 같이 설정할 수 있습니다. 부울 –