Objective-c: initialize the variable to zero

Does anyone know if the following code can be complicated:

NSString *addchar = nil;

if (case1)
addChar = [[firstname substringToIndex:1] capitalizedString];
else
addChar = [[fullname substringToIndex:1] capitalizedString];

Suppose the name and full name are not null or empty. Initializes an NSString object and sets it to "nil", causing some possible problems? It seems that my application is blocked, but only for very few users and only for these users, but it has nothing to do with various input lines or empty lines. Therefore, I am trying to isolate the problem, but I do not know the difference between

NSString *addChar;

and

NSString *addChar = nil;

Thanks.

+3
source share
5 answers

. , , . , , .

+7

nil, ( ). , , ( , ..) , , , .

, if addChar, , . , , - , , , !

+5

nil, .

, .

NSString * str = nil;
NSLog(@"%@", [str description]);

:

2009-12-15 08:59:03.352 x[11775] (nil)

, description, nil.

+2

, addChar . , addChar nil , ( addChar).

. .

+1

Source: https://habr.com/ru/post/1725664/


All Articles