-1

可能重复:
iPhone Dev - NSString Creation

我在用

 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;之间的效果和区别是什么?字符串 *str=nil

4

1 回答 1

2

NSString *str;使用 ARC 时,和之间没有区别NSString *str = nil;,所有指针在初始化时都保证为 nil。

当您不使用 ARC 时,指针可能指向垃圾值。

于 2013-01-22T08:04:33.140 回答