因爲你宣佈requestComment
是一個NSDictionary
哪些鍵NSNumbers
和值NSString
不會迫使它尊重它。
樣品:
_requestComments = [[NSMutableDictionary alloc] init];
[_requestComments setObject:[NSNumber numberWithInt:34] forKey:@"54"]; // => Warning: Incompatible pointer types sending 'NSNumber * _Nonnull' to parameter of type 'NSString * _Nonnull'
id obj = [NSNumber numberWithInt:35];
id key = @"55";
[_requestComments setObject:obj forKey:key];
NSLog(@"[_requestComments objectForKey:@\"55\"]: %@", [_requestComments objectForKey:@"55"]); //Warning: Incompatible pointer types sending 'NSString *' to parameter of type 'NSNumber * _Nonnull'
NSLog(@"[_requestComments objectForKey:@(55)]: %@", [_requestComments objectForKey:@(55)]);
日誌:
$>[_requestComments objectForKey:@"55"]: 35
$>[_requestComments objectForKey:@(55)]: (null)
好吧,我用id
引誘編譯器,但id
是一種常見的返回 「類」,在objectAtIndex:
,等,這是常見的JSON解析,當你認爲一個對象將是NSString
,但實際上是(反)的NSNumber
。
在做requestComments[serviceRequest.RequestId]
之前,枚舉所有鍵值& class和ALL object值& class。你可以這樣檢查:
for (id aKey in _requestComments)
{
id aValue = _requestComments[aKey];
NSLog(@"aKey %@ of class %@\naValue %@ of class %@", aKey, NSStringFromClass([aKey class]),aValue, NSStringFromClass([aValue class]));
}
然後你可以嘗試跟蹤你放錯鑰匙(class)的位置。
你可以顯示你的'requestComments'請打印在日誌中並加入問題 – Dhiru
它只是打印「2017-07-06 12:45:31.071 WorkForApp [6076:96649](null)」 –
什麼是輸出'[dataManager.requestComments objectForKey:serviceRequest.RequestId]'? – nayem