为什么是NULL?

扫码查看
object2为零.为什么 ?如何?? 解决方案 NSLog(@"array2的内容%@",[object2.array2 objectAtIndex:0]);//输出NULL 如果打印为NULL",则是以下四个原因之一: object2 为零 object2.array2 返回nil 索引为0的对象是字符串"NULL" 索引0的 description 方法中的对象返回字符串"NULL" 是哪个?对象2为零.我不知道为什么.最有可能是因为您没有首先对其进行初始化.显示您的初始化代码,并删除一条日志语句或断点,并确保它实际上已在执行.Can anyone tell me why this is NULL ?So Array1 is NSMutable, and has an NSString object "UserName" at index 0;NSLog (@"Contents of array1 %@", [array1 objectAtIndex:0]); //prints UserNameNow , I do this...array2 belongs to another class. I reference the class, import .h file, and add property and synthesize it. [object2.array2 addObject: array1]; //array2 is NSMutable properly initialized in it's respective class in the init methodNSLog (@"Contents of array2 %@", [object2.array2 objectAtIndex:0]); //prints (null)tempArray = [[NSMutableArray alloc] init];tempArray = [object2.array2 objectAtIndex:0];NSLog (@"%@", [tempArray objectAtIndex:0]); // Prints (null) // Should be UserNameAdding more information:object2 is an object of another class (which is a subclass of NSObject), and object2 contains array2 as it's property.object2 is nil. WHY ? HOW ?? 解决方案 NSLog (@"Contents of array2 %@", [object2.array2 objectAtIndex:0]); //prints NULLIf that 'prints NULL', then it is for one of four reasons:object2 is nilobject2.array2 returns nilthe object at index 0 is the string "NULL"the object at index 0's description method returns the string "NULL"Which is it? object 2 is nil. I wonder why.Most likely because you didn't initialize it in the first place. Show your initialization code and also drop a log statement or breakpoint and make sure it is actually being executed. 这篇关于为什么是NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 06:59
查看更多