私は(Xcode 7.3で)私が取り組んでいるSwiftアプリケーションを持っています。Swift + Parse: 'PFObjectのキーまたは値にnilを使用できません。値にNSNullを使用してください。
パースを使用していますが、タイトルに記載されているエラーメッセージが生成されています。
コードは次のようになります。
@IBAction func callUber(sender: AnyObject) {
let riderRequest = PFObject(className:"riderRequest")
riderRequest["username"] = PFUser.currentUser()?.username
riderRequest["location "] = PFGeoPoint(latitude:latitude, longitude:longitude)
riderRequest.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
self.callUberButton.setTitle("Cancel Uber", forState: UIControlState.Normal)
} else {
let alert = UIAlertController(title: "Could not call Uber", message: "Please try again", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
}
ここで、このコードのどこかにnilが値に適用されているため、エラーメッセージが表示されます(または考えられます)。私はこの問題の解決策をSOで探していましたが、このエラーメッセージとSwiftのObjective-Cだけの類似のスレッドは見つかりませんでした。
何らかのエラー処理を導入したり、オブジェクトの値がnilではないことを確認しなければならないと推測していますが、どこに適用するか、またはどのように適用するかはわかりません。
「callUber」ボタンを押すとエラーが発生し、デバッグコンソールからの完全な出力は以下のようになります。
2016-04-15 12:21:01.900 ParseStarterProject-Swift[8781:2591354] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ca98d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010eca0deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ca98cbd +[NSException raise:format:] + 205
3 ParseStarterProject-Swift 0x000000010c1042a8 -[PFObject(Private) _setObject:forKey:onlyIfDifferent:] + 122
4 ParseStarterProject-Swift 0x000000010c107d01 -[PFObject setObject:forKey:] + 53
5 ParseStarterProject-Swift 0x000000010c107d46 -[PFObject setObject:forKeyedSubscript:] + 50
6 ParseStarterProject-Swift 0x000000010c0c847f _TFC25ParseStarterProject_Swift19RiderViewController8callUberfPs9AnyObject_T_ + 671
7 ParseStarterProject-Swift 0x000000010c0c89d6 _TToFC25ParseStarterProject_Swift19RiderViewController8callUberfPs9AnyObject_T_ + 54
8 UIKit 0x000000010d726a8d -[UIApplication sendAction:to:from:forEvent:] + 92
9 UIKit 0x000000010d899e67 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x000000010d89a143 -[UIControl _sendActionsForEvents:withEvent:] + 327
11 UIKit 0x000000010d899263 -[UIControl touchesEnded:withEvent:] + 601
12 UIKit 0x000000010d79999f -[UIWindow _sendTouchesForEvent:] + 835
13 UIKit 0x000000010d79a6d4 -[UIWindow sendEvent:] + 865
14 UIKit 0x000000010d745dc6 -[UIApplication sendEvent:] + 263
15 UIKit 0x000000011dfe0b15 -[UIApplicationAccessibility sendEvent:] + 77
16 UIKit 0x000000010d71f553 _UIApplicationHandleEventQueue + 6660
17 CoreFoundation 0x000000010c9be301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18 CoreFoundation 0x000000010c9b422c __CFRunLoopDoSources0 + 556
19 CoreFoundation 0x000000010c9b36e3 __CFRunLoopRun + 867
20 CoreFoundation 0x000000010c9b30f8 CFRunLoopRunSpecific + 488
21 GraphicsServices 0x0000000111eb0ad2 GSEventRunModal + 161
22 UIKit 0x000000010d724f09 UIApplicationMain + 171
23 ParseStarterProject-Swift 0x000000010c0cc712 main + 114
24 libdyld.dylib 0x000000010f7a792d start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
をうん、それが問題でしたユーザ名変数でした。ログインビューコントローラーは「初期ビューコントローラー」ではなく、最初にサインインせずにアプリを開くことができました。愚かな私。 しかし、私は最初の問題を解決した後に新しい解析エラーを引き起こしました。 ** Swift [8903:2666826] [エラー]無効なキー名:場所(コード:105、バージョン:1.12.0) 5 ** "location"はriderRequestクラスの列なので、問題は、しかし、私はそれがこのエラーメッセージのいずれかについて不平を言うかどうか分からない。 – lundzern
ああ良い!私はあなたが問題を発見してうれしいです:) –
ああ、その場合はあなたの場所属性の名前をあなたの解析ダッシュボードを確認してください。 –