开发者

pointer before declaration of object objective-c

开发者 https://www.devze.com 2023-03-17 13:25 出处:网络
can you tell me something : is it a mistake or can we write \"result\" without the \" * \" here : @implementation Person (Sorting)

can you tell me something : is it a mistake or can we write "result" without the " * " here :

@implementation Person (Sorting)  
   - (NSComparisonResult)compareByName:(Person *)person2 {    
        >>//here :  
        >>NSComparisonResult result = [self.lastN开发者_运维百科ame caseInsensitiveCompare:person2.lastName];  
        if (result == NSOrderedSame) {  
            return [self.firstName caseInsensitiveCompare:person2.firstName];  
        }  
        return result;  
   }  
@end  

Thanks


caseInsensitiveCompare method returns NSComparisonResult so not using * is absolutely correct.

In objective-c you must use pointers to obj-c objects, but NSComparisonResult is just an enum (i.e. plain integer) so you may freely use it without pointer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号