NSURLSession *session = [NSURLSession sharedSession];
初看这个方法是类方法调用,但sharedSession是property。
仔细查看这个属性的modifiers
@interface NSURLSession : NSObject
/*
* The shared session uses the currently set global NSURLCache,
* NSHTTPCookieStorage and NSURLCredentialStorage objects.
*/
@property (class, readonly, strong) NSURLSession *sharedSession;
懂了,里面有一个class关键字。
写个例子测试下
@interface SomeClass: NSObject
@property (class, nonatomic, strong) NSString *haha;
@end
@implementation SomeClass
+ (NSString *)haha {
return @"haha";
}
+ (void)setHaha:(NSString *)haha {
// 写不下去了
}
@end
查文档:http://clang.llvm.org/docs/AutomaticReferenceCounting.html#property-declarations
没找到解释……
最终得知是LLVM在Xcode8发布时的新特性,静态对象保存属性而已。
参考这片文章:https://useyourloaf.com/blog/objective-c-class-properties/
网友评论