0

我想從字符串access_token創建一個新的對象。 我做了一個令牌:NSObject(.h + .m),我正在嘗試setAccessToken並在NSLog中顯示它。這是我LoginViewController.m代碼:無法登錄我的setAccessToken

NSString *token = responseObject[@"access_token"]; 

     Token *t = [[Token alloc]init]; 
     [t setAccessToken:token]; 
     NSLog(t); 

這是錯誤我得到:

創建[29485:770358] - [令牌_fastCStringContents:]:無法識別 選擇發送到實例0x7f8e815d0780 創建[29485:770358] *終止應用程序由於未捕獲的異常 'NSInvalidArgumentException' 的,原因是: ' - [令牌_fastCStringContents:]: 無法識別的選擇發送到實例0x7f8e815d0780' *首先噸HROW調用堆棧:(0的CoreFoundation 0x000000010149ff45 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000100f19deb objc_exception_throw + 48 2的CoreFoundation
0x00000001014a856d - [NSObject的(NSObject的)doesNotRecognizeSelector:] + 205 3的CoreFoundation 0x00000001013f5eea ___forwarding_
+ 970 4的CoreFoundation 0x00000001013f5a98 _CF_forwarding_prep_0 + 120 5
libsystem_trace.dylib 0x00000001036e8327 os_log_shim_with_CFString + 120 6的CoreFoundation
0x000000010148ef24 _CFLogvEx3 + 132 7基金會
0x0000000100b9489e _NSLo GV + 117 8基金會
0x0000000100ae40f2的NSLog + 152 9創建
0x00000001004d665b 21- [LoginVC用戶登陸:] _ block_invoke + 203 10 創建0x00000001004d7f18 __64- [AFHTTPRequestOperation setCompletionBlockWithSuccess:故障:] _ block_invoke49 + 40 11 libdispatch.dylib 0x00000001033fde5d _dispatch_call_block_and_release + 12 12 libdispatch.dylib 0x000000010341e49b _dispatch_client_callout + 8 13 libdispatch.dylib 0x00000001034062af _dispatch_main_queue_callback_4CF + 1738 14 的CoreFoundation 0x00000001014002e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 15 CoreFound通貨膨脹0x00000001013c18a9 __CFRunLoopRun + 2073 16的CoreFoundation 0x00000001013c0e08 CFRunLoopRunSpecific + 488個17 GraphicsServices
0x00000001056dcad2 GSEventRunModal + 161 18的UIKit
0x000000010184c30d UIApplicationMain + 171 19創建
0x00000001004d6a2f主+ 111 20 libdyld.dylib
0x000000010345292d啓動+ 1 21 ???
0x0000000000000001爲0x0 + 1)的libC++ abi.dylib:與類型NSException的 未捕獲的異常終止

希望有人能幫助我!

回答

1

NSLog(...)函數假定第一個參數是NSString的實例。如果您想使用不同的對象,請使用:

NSLog([t description])或格式字符串NSLog(@"%@", t)

+0

好吧!但我現在這樣做了,它給了我: <令牌:0x7f85e9cad610> :( –

+0

@這個絕對正確的行爲,你期望的結果是什麼?你是如何實現'令牌'的? – Sulthan

+0

我認爲它會記錄access_token ..實現?我已經導入了Token.h的一些屬性 –