我一直都知道這種模式是管理的NSError**
參數(特別是BOOL
返回值和NSError* __autoreleasing *
參數的方式:NSError __autoreleasing VS _Nullable
-(BOOL)doSomethingWithString:(NSString*)string error:(NSError* __autoreleasing *)error {
if(![string length]) {
*error = [NSError blah blah];
return NO;
}
return YES;
}
要使用這個方法遵循了這一模式:
NSError* error = nil;
if([self doSomethingWithString:@"" error:&error]) {
//great success!!
} else {
//log error
}
目前看來,__autoreleasing
被替換_Nullable
?
我升從官方的Apple文檔中以這種方法進行處理:https://developer.apple.com/reference/foundation/nsfilemanager/1415371-createdirectoryaturl?language=objc
那麼,我是否簡單地將__autoreleasing
全部替換爲_Nullable
,並且在這種情況下一切都很好?如果不是,管理NSError**
參數的新模式是什麼?
該模式是,您成功返回YES或非零對象,並在失敗返回NO或無。 – gnasher729
@ gnasher729我修正了我的例子...謝謝你指出... –