I'm currently a novice in Swift, but I'm a maintainer of an Objective-C framework which is a wrapper around a C library, for which I'd like to have the nicest API possible.
I'm looking at this kind of code
/// The index checksum
@property (nonatomic, readonly, strong) GTOID * _Nullable checksum;
and wondering if the nullable
annotation is warranted. Looking at the underlying C function,
const git_oid *git_index_checksum(git_index *index)
{
return &index->checksum;
}
it's pretty obvious that, modulo memory allocation failures in the Obj-C wrapper,
- (GTOID *)checksum {
const git_oid *oid = git_index_checksum(self.git_index);
if (oid != NULL) {
return [GTOID oidWithGitOid:oid];
}
return nil;
}
this is not nullable.
Or is it ?
Is there some specific guidelines into what's considered acceptable w.r.t nullability when bridging, especially in the face of allocation failures ? Would Swift's reaction be any different if I made that property nonnull
and memory failed ?