UIKit 가져 오기 CoreData 가져 오기
class ViewController : UIViewController {
@IBAction func btnGood(sender: AnyObject) {
var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
var context: NSManagedObjectContext = appDel.managedObjectContext
var record = NSEntityDescription.insertNewObjectForEntityForName("Meals", inManagedObjectContext: context) as NSManagedObject
record.setValue(1, forKey: "data")
do {
try context.save()
} catch {
print("error")
}
print(record)
print("Object Saved")
}
오류-
2015-11-23 17:10:12.264 statsStoring[5355:669919] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "data"; desired type = NSString; given type = __NSCFNumber; value = 1.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101a3be65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010377adeb objc_exception_throw + 48
2 CoreData 0x00000001015d6990 _PFManagedObject_coerceValueForKeyWithDescription + 2864
3 CoreData 0x00000001015ae801 _sharedIMPL_setvfk_core + 177
4 statsStoring 0x00000001014c83ec _TFC12statsStoring14ViewController7btnGoodfS0_FPSs9AnyObject_T_ + 684
5 statsStoring 0x00000001014c8786 _TToFC12statsStoring14ViewController7btnGoodfS0_FPSs9AnyObject_T_ + 54
6 UIKit 0x000000010225c8c8 -[UIApplication sendAction:to:from:forEvent:] + 92
7 UIKit 0x00000001023cb328 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x00000001023cb5f4 -[UIControl _sendActionsForEvents:withEvent:] + 311
9 UIKit 0x00000001023ca724 -[UIControl touchesEnded:withEvent:] + 601
10 UIKit 0x00000001022cbbcf -[UIWindow _sendTouchesForEvent:] + 835
11 UIKit 0x00000001022cc904 -[UIWindow sendEvent:] + 865
12 UIKit 0x000000010227b29a -[UIApplication sendEvent:] + 263
13 UIKit 0x00000001022554cb _UIApplicationHandleEventQueue + 6844
14 CoreFoundation 0x0000000101967a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010195d95c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x000000010195ce13 __CFRunLoopRun + 867
17 CoreFoundation 0x000000010195c828 CFRunLoopRunSpecific + 488
18 GraphicsServices 0x00000001060b5ad2 GSEventRunModal + 161
19 UIKit 0x000000010225ad44 UIApplicationMain + 171
20 statsStoring 0x00000001014ca89d main + 109
21 libdyld.dylib 0x000000010429492d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
사용자가 btngood 버튼을 누르면 '1 (true)'값이 'data'속성에 저장되어야합니다! 이것을 위해 나는 1을 시도했지만 그것은 나에게 오류를주고 그것을하는 올바른 방법이 아니라는 것을 알고 있습니다.
@Jan Greve의 첫 번째 포인트에 동의했습니다. 로그로 숫자를 문자열 데이터 유형으로 저장하고 있음을 보여줍니다. 이 줄 변경
record.setValue(1, forKey: "data")
...에
record.setValue("1", forKey: "data")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다