official examples of Deezer's api in swift向我们展示了getObject
中称为DeezerManager
的方法。
func getObject(identifier: String, callback: @escaping (_ object: Any?, _ error: Error?) -> Void) {
DZRObject.object(withIdentifier: identifier, requestManager: DZRRequestManager.default(), callback: callback)
}
我想播放ID为533609232(德雷克-神的计划)的单曲。
为此,我需要拥有DZRTrack
/ DZRObject
。所以我打电话给了
DZRObject.object(withIdentifier: "533609232", requestManager: DZRRequestManager.default(), callback: { (data, error) in
print(data, error)
//player stuff
})
但是我遇到了一个错误NSException
:
2019-05-02 22:50:23.845973+0200 my-app[51762:1318493] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010af7d6fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000109dd2ac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010aecbddc _CFThrowFormattedException + 194
3 CoreFoundation 0x000000010af5786d -[__NSPlaceholderArray initWithObjects:count:] + 237
4 CoreFoundation 0x000000010af6c2a4 +[NSArray arrayWithObjects:count:] + 52
5 my-app 0x0000000106af3ef5 +[DZRObject infoURLWithBaseURL:identifier:] + 134
6 my-app 0x0000000106af4062 +[DZRObject objectWithRequestManager:baseURL:identifier:callback:] + 123
7 my-app 0x0000000106af3fb3 +[DZRObject objectWithIdentifier:requestManager:callback:] + 80
8 my-app 0x00000001069cd93d $s10my_app30DeezerViewControllerC5testayyF + 461
9 my-app 0x00000001069cf75e $s10my_app30DeezerViewControllerC0C6ActionyyF + 46
10 my-app 0x00000001069cf794 $s10my_app30DeezerViewControllerC0C6ActionyyFTo + 36
11 UIKitCore 0x000000010fd73204 -[UIApplication sendAction:to:from:forEvent:] + 83
12 UIKitCore 0x000000010f7c8c19 -[UIControl sendAction:to:forEvent:] + 67
13 UIKitCore 0x000000010f7c8f36 -[UIControl _sendActionsForEvents:withEvent:] + 450
14 UIKitCore 0x000000010f7c7eec -[UIControl touchesEnded:withEvent:] + 583
15 UIKitCore 0x000000010fdabeee -[UIWindow _sendTouchesForEvent:] + 2547
16 UIKitCore 0x000000010fdad5d2 -[UIWindow sendEvent:] + 4079
17 UIKitCore 0x000000010fd8bd16 -[UIApplication sendEvent:] + 356
18 UIKitCore 0x000000010fe5c293 __dispatchPreprocessedEventFromEventQueue + 3232
19 UIKitCore 0x000000010fe5ebb9 __handleEventQueueInternal + 5911
20 CoreFoundation 0x000000010aee4be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010aee4463 __CFRunLoopDoSources0 + 243
22 CoreFoundation 0x000000010aedeb1f __CFRunLoopRun + 1231
23 CoreFoundation 0x000000010aede302 CFRunLoopRunSpecific + 626
24 GraphicsServices 0x00000001136072fe GSEventRunModal + 65
25 UIKitCore 0x000000010fd71ba2 UIApplicationMain + 140
26 my-app 0x00000001068d4ebb main + 75
27 libdyld.dylib 0x000000010cfc9541 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
所以我不明白为什么会出现此错误。 我做错了吗?是另一种方式吗?
答案 0 :(得分:0)
如Deezer SDK文档(DZRObject.h
)所述
您不应直接在DZRObject类上调用此方法,而应在一个 的具体子类(例如DZRUser,DZRTrack,DZRArtist等)
也许改为尝试DZRTrack.object(withIdentifier...
?