mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

No ObjC compatibility in Mapbox v10?

Open NathanaelA opened this issue 3 years ago • 7 comments

Environment

  • Xcode version: 12
  • iOS version: 14
  • Devices affected: All
  • Maps SDK Version: v10

Observed behavior and steps to reproduce

Attempting to use the MapBox v10 in a OBJC app, doesn't work properly as virtually all the classes are not descended from a NSObject. Since Swift 4 or 5 Inference was changed, so less things are exposed.

Expected behavior

MapBox v10 to be compatible with ObjC programs...

Notes / preliminary analysis

Doing some initial tests, seems like if we take most the classes and make them descend from NSObject they can be usable from OBJC.

Additional links and references

https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#objc https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md

Additional Notes

I'm testing manually adding @objMembers and @objc, if this works, would you accept a PR that exposes the classes to ObjC?

Followup: I can do this on this repo; but quite a few classes descend from base classes in what appears to be only available as compiled libraries that I'm not sure the source code it available, these changes would have to be done in these base classes first as things that descend from the base class can't be tagged as they are then Swift only classes...

NathanaelA avatar May 15 '21 23:05 NathanaelA

I am not sure if it is possible to expose objc structs like Turf.Feature or the map options?

patrickkempff avatar Jun 07 '21 09:06 patrickkempff

I believe if a concerted effort was put into it, it could be. ObjC has enough data types that are directly cross-compatible with Swift, enums, ints, strings, etc. I believe Turf is under MapBox's control, so there is nothing stopping MapBox from adding additional functions that are fully objc compatible or updating it so that the existing functions are only using ObjC compatible types. I was able to write a Swift wrapper that exposed the functionality I needed to ObjC, it just was a lot more work as I could not just say call X with these values directly... I had to frequently create a wrapper function where I passed in the ObjC values and it called the swift version of the function.

NathanaelA avatar Jun 07 '21 15:06 NathanaelA

Thank you for your inputs @NathanaelA. We are aware of the lack of ObjC support at this time and are evaluating how to better support this need with v10.

knov avatar Jul 15 '21 19:07 knov

I believe if a concerted effort was put into it, it could be. ObjC has enough data types that are directly cross-compatible with Swift, enums, ints, strings, etc. I believe Turf is under MapBox's control, so there is nothing stopping MapBox from adding additional functions that are fully objc compatible or updating it so that the existing functions are only using ObjC compatible types. I was able to write a Swift wrapper that exposed the functionality I needed to ObjC, it just was a lot more work as I could not just say call X with these values directly... I had to frequently create a wrapper function where I passed in the ObjC values and it called the swift version of the function.

Hi @NathanaelA -- would you mind sharing the MB v10 Swift wrappers you have written for ObjC?

csaper avatar Jul 21 '21 13:07 csaper

Are there any news on this?

felixkrautschuk avatar Dec 13 '21 15:12 felixkrautschuk

@csaper - Sorry, I just saw your message. Unfortunately it was written for a specific client so I can't share the code.

Basically all I did was write several swift classes with the "objc" tag to expose it for the different pieces I needed. Most the time it was fairly simple direct wrapping but occasionally I had to actually do data conversions from a swift type to a OBJC dictionary or other like similar value. Anything that I didn't need on the ObjC side, I just stored in my Swift class as a reference that I used for additional calls.

NathanaelA avatar Dec 13 '21 17:12 NathanaelA

Is there an update regarding this or are current customers left alone with this problem?

obrhoff avatar Apr 14 '22 06:04 obrhoff