๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’š ๊ฐœ๋ฐœ/iOS

[iOS. Objective-C] NSString null ์ฒดํฌ / NSLog, printf ๋กœ ์ถœ๋ ฅ

by devshin.kr 2021. 12. 21.
728x90


์•„๋ž˜ ์˜ˆ์ œ์—์„œ ๋‘ ๊ฐ€์ง€๋ฅผ ์ •๋ฆฌํ–ˆ๋‹ค.

1.
NSString ์˜ ๊ฐ’์ด null ์ธ ๊ฒฝ์šฐ๋ฅผ ์ฒดํฌ.
nsStr ์ด๋ผ๋Š” ๋ณ€์ˆ˜์˜ ์ž๋ฃŒํ˜•์ด null ์ธ์ง€ ํ˜น์€ nsStr ์˜ ๊ธธ์ด๊ฐ€ 0 ์ธ์ง€ ์ฒดํฌํ•œ๋‹ค.


2.
NSString ์ž๋ฃŒํ˜•์˜ ๋ณ€์ˆ˜ nsStr ์„ NSLog ์™€ printf๋กœ ์ถœ๋ ฅํ•œ๋‹ค.

 

NSString *nsStr = nil;
nsStr = @"This Vlaue is not null";	// ์ด ๋ผ์ธ์ด ์—†์–ด์ง€๋ฉด else ๋กœ ๋ถ„๊ธฐ๋œ๋‹ค.

if (nsStr == (id)[NSNull null] || nsStr.length == 0 )
{
	NSLog(@"This Value is null\n");
	printf("This Value is null\n");
}
else
{
	NSLog(@"%@\n", nsStr);
	printf("%s\n", [nsStr UTF8String]);
}

๋Œ“๊ธ€