Skip to content

[ffigen] ObjC version compatibility runtime check #300

@liamappelbe

Description

@liamappelbe

Not all APIs are available on all versions of iOS. There are annotations in Objective C for this, so we can turn that into version checks, and throw user friendly exceptions rather than crashing. Suggestion from Brian:

  - (NSURLSessionWebSocketTask *)webSocketTaskWithURL:(NSURL *)url protocols:(NSArray<NSString *>*)protocols API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));

Could translate into:

webSocketTaskWithURL(NSURL url, NSArray<NSString> protocols) {
  if (platform.isIOS) {
    if (platform.version < 13.0) {
      throw UnsupportedError("webSocketTaskWithURL requires: macos > 10.15, ios >= 13.0, watchos >= 6.0 or tvos >= 13.0 [is ios ${platform.version}.")
    }
  } else ...
  <do the real work>
}

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions