我在我的iOS應用中使用JSONModel,我正面臨一些警告,讓我自己解釋一下。JSONModel:填充泛型類型的NSArray
比方說,我有這個JSONModel
CTVContact.h
@interface CTVContact : JSONModel
@property (nonatomic, strong) NSArray<Optional, CTVPhone> *phone;
@end
CTVContact.m
NSMutableArray *phones = [[NSMutableArray alloc] init];
for(NSString *p in personPhones) {
CTVPhone *phn = [[CTVPhone alloc] init];
phn.original = p;
[phones addObject:phn];
}
phone = [NSArray arrayWithArray:phones];
基本上所有的工作就像一個魅力,但我得到一個警告陳述如下:
Incompatible pointer types assigning to 'NSArray<Optional,CTVEventParticipant> *' from 'NSArray *'
我該如何解決該警告?我無法找到正確的方式將所有陣列值分配給手機陣列,但沒有發出警告。
非常感謝!
如果我刪除協議,JSONModel將停止工作,並且它不會正確建模JSON,請參閱模型集合部分:https://github.com/icanzilb/JSONModel/blob/master/README.md#magical- data-modeling-framework-for-json – asheinfeld
夠公平的,添加了你的解決方法。 – Wain
工程就像一個魅力!謝謝! – asheinfeld