OBJECTIVE C NULL定義
在程式裡
給與變數
a=NULL 等於 a=nil 就是沒有占任何記憶體
而這時取aCustNo.length 會為0
如果是給NULL物件
要打a=(id)[NSNull null]
但是如果如果取aCustNo.length 會產生錯誤
順便一提
textField 初始值不是(id)[NSNull null]
所以可以用aCustNo.length判斷
參考資料
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NumbersandValues/Articles/Null.html
Using NSNull
The NSNull class defines a singleton object you use to represent null values in situations where nilis prohibited as a value (typically in a collection object such as an array or a dictionary).
NSNull *nullValue = [NSNull null];
|
NSArray *arrayWithNull = @[nullValue];
|
NSLog(@"arrayWithNull: %@", arrayWithNull);
|
// Output: "arrayWithNull: (<null>)"
|
It is important to appreciate that the NSNull instance is semantically different from NO or false—these both represent a logical value; the NSNull instance represents the absence of a value. TheNSNull instance is semantically equivalent to nil, however it is also important to appreciate that it is not equal to nil. To test for a null object value, you must therefore make a direct object comparison.
id aValue = [arrayWithNull objectAtIndex:0];
|
if (aValue == nil) {
|
NSLog(@"equals nil");
|
}
|
else if (aValue == [NSNull null]) {
|
NSLog(@"equals NSNull instance");
|
if ([aValue isEqual:nil]) {
|
NSLog(@"isEqual:nil");
|
}
|
}
|
// Output: "equals NSNull instance"
|
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-02-08)