我正在使用
NSString *str_Message;
if ([txt_NoOfPersons.text length] == 0){
bln_Validate = FALSE;
str_Message = [[NSString alloc]initWithString:@"Number of Persons field is required."];
}
else if ([txt_NoOfPersons.text intValue] == 0)
{
bln_Validate = FALSE;
str_Message = [[NSString alloc]initWithString:@"Please enter your guest count."];}
}
if ([txt_DateAndTime.text length] == 0)
{
bln_Validate = FALSE;
str_Message = [[NSStrin@"Date and Time field is required."];
}
如果我使用 Nsstring * str_Message = nil; '
if ([txt_NoOfPersons.text length] == 0)
{
bln_Validate = FALSE;
str_Message = @"Number of Persons field is required.";
}
else if ([txt_NoOfPersons.text intValue] == 0)
{
bln_Validate = FALSE;
str_Message = @"Please enter your guest count.";
}
那么 Nsstring * str会产生什么影响呢? Nsstring * str = nil
答案 0 :(得分:2)
使用ARC时,NSString *str;
和NSString *str = nil;
之间没有区别,所有指针在初始化时都保证为零。
当您不使用ARC时,指针可能指向垃圾值。