[iOS] Swift compatibility: All properties and return values in Geth.objc.h should be declared as nullable or nonnull
ronaldmannak opened this issue · 4 comments
System information
Geth version: iGeth/v1.7.0-stable/darwin-arm64/go1.7.1
OS & Version: iOS 11.0.2
Expected behaviour
Unless declared explicitly as nullable
, all properties and return values declared in the Geth.objc.h files are expected to be implicitly unwrapped optionals by default in Swift. No property or method in Geth.objc.h is marked nullable
and therefore Swift expects Geth to always return non-nil values and instances.
Actual behaviour
Occasionally, some properties or methods do return nil, which crashes the app with an "unexpectedly found nil" message.
One example is the string
property of GethBlock
which can return nil. String is currently declared as: - (NSString*)string;
which Swift will translate into func string() -> String
It should be declared as:
- (nullable NSString*)string;
which Swift will translate into func string() -> String?
One workaround is to assume every method can return nil and every property is optional, but that would require a lot of redundant code.
I assume this is limitation of the automatic Go to ObjC translation.
It's even worse: using Xcode 9 it translates to open func string() -> String!
(implicitly unwrapped optional)
@karalabe Péter, is there any easy way to have Gobind generate a Swift-friendly header file? If not, is there a list or overview which properties could return nil and which ones so we can anticipate better?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.