我有一个已初始化的静态字典,并且数据已添加到不同的.m 文件中,现在在我的视图控制器中我需要该静态字典。字典实际上包含运营商名称作为键,它们各自的号码作为值,所以我最想做的是检查手机所属的运营商,然后获取相应的号码。已形成静态字典的 .m 文件是 Config.m,它有一个实际返回静态字典的方法。
+ (NSDictionary*) getMccMncToCodeDictionary
{
return mccMncLISDictionary;
}
我在 ViewController 中所做的是:“分配给不兼容的指针类型
Config* network_number = [[Config alloc] init];
network_number = [Config getMccMncToLISCodeDictionary];
NSLog(@"network number:::%@", network_number);
在我的控制台中显示
network number:::(null)
我得到的警告(黄色错误)是 ViewController 代码第二行中的“不兼容的指针类型从 NSDictionary* 分配给 'Config*_strong'”
我的 initLISDictionary 代码:
- (void) initLISDictionary
{
NSString* MCC = @"520";
NSString* CAT3G = [NSString stringWithFormat:@"%@00",MCC];
NSString* AIS = [NSString stringWithFormat:@"%@01",MCC];
NSString* CAT_CDMA =[NSString stringWithFormat:@"%@02",MCC];
NSString* TOT3G = [NSString stringWithFormat:@"%@15",MCC];
NSString* DTAC = [NSString stringWithFormat:@"%@18",MCC];
NSString* AIS_GSM_1800 = [NSString stringWithFormat:@"%@23",MCC];
NSString* TRUE_MOVE_H = [NSString stringWithFormat:@"%@88",MCC];
NSString* TRUE_MOVE = [NSString stringWithFormat:@"%@99",MCC];
mccMncLISCodeDictionary = [NSMutableDictionary dictionary];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:2] forKey:CAT3G];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:1] forKey:AIS];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:2] forKey:CAT_CDMA];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:4] forKey:TOT3G];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:3] forKey:DTAC];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:1] forKey:AIS_GSM_1800];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:5] forKey:TRUE_MOVE];
[mccMncLISCodeDictionary setValue:[NSNumber numberWithInt:5] forKey:TRUE_MOVE_H];
}