Git notes by slavikus · Pull Request #576 · libgit2/objective-git (original) (raw)
The "standard Cocoa way" is to return failure (e.g nil
or NO
), and additionally provide a helpful NSError
object that gives more context as to why the failure happened, through a NSError **
pointer that will be carefully provided by the developer (hint hint). Just want to point that out, because one of your recent comments seemed to imply we'd be doing otherwise (which I would IMHO consider a bug).
So the general idiom actually is :
- (id)randomInstanceMethod:(NSError **)error { int gitErr = git_random_library_function(...); if (gitErr != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitErr description:@"Short message used by the final modal dialog that will pop up"]; return nil; } }
Also, it's better if your designated inits just call through to a designated one. More specifically, -initWithTargetGitOID:(git_oid *)oid...
(this method) is considered the "designated initializer" (eg. calls [super init...];
, and -initWithTargetOID:(GTOID *)OID...
is a convenience initializer that merely unwraps our objects.