函數返回「的NSArray * _Nonnull」(誰是不再左右),並試圖修復他們離開代碼中的一些警告。不兼容的指針類型從我從另一個開發的代碼工作的結果類型「ARArrayList *」
我已成功地修復所有的錯誤和警告,除了一個,這是本...
Incompatible pointer types returning 'NSArray * _Nonnull' from a function with result type 'ARArrayList *'
的Xcode點的此警告,以下代碼塊...
-(instancetype) split:(NSUInteger)numberOfPartitions
{
id result = [NSMutableArray new];
if (numberOfPartitions>0){
NSUInteger i = 0;
id subcollection = [[self class] emptyMutable];
for (id object in self){
[subcollection addObject:object];
i++;
if (i%numberOfPartitions==0) {
[result addObject:subcollection];
subcollection = [[self class] emptyMutable];
} else if (i==[self count]){
[result addObject:subcollection];
}
}
}
return [NSArray arrayWithArray:result];
}
而在Xcode工具條顯示了這個...
任何人都可以看到如何解決這個問題嗎?這最後的警告正在變得煩人!
爲什麼返回類型聲明的'instancetype'代替'的NSArray *'? – rmaddy
該代碼不是我的,我不是編碼方面的專家,所以我不知道! – Richard
@rmaddy,你有正確的答案。你能否將它作爲答案留下來,以便能夠提高和接受? – uliwitness