-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Swift Package Manager #362
Conversation
fc1dea3
to
7833e8a
Compare
Unfortunately, that won’t be feasible as long as this library supports Objective-C. Would it be possible to maintain parallel types, with CocoaPods and Carthage using the Objective-C version and SPM using the Swift version? |
Great idea. That should be relatively straightforward, and only four duplicated data types in the shim, which shouldn't be too inconvenient to maintain. |
be1bc31
to
f2515a3
Compare
Package.swift
Outdated
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
.package(url: "../Polyline", .branch("fred/spm4.2")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to update this line before merging.
0321f46
to
1d59309
Compare
|
||
/** | ||
Initializes a new `Lane` using the given lane indications. | ||
*/ | ||
#if SWIFT_PACKAGE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely satisfied with this workaround, having to provide duplicated initializers.
What I would like to see is a pre-processor macro:
#if SWIFT_PACKAGE
#define OBJC_NO_SPM
#define OBJC_NO_SPM(x)
#else
#define OBJC_NO_SPM @objc
#define OBJC_NO_SPM(x) @objc(x)
#endif
but an Obj-C macro would not work with SPM and SPM doesn't support these macros.
@objcMembers
solves roughly half of the issues, since it ignores the @objc
-flag if it's not able to bridge properly to Obj-C, but it only works for some methods and properties.
OHHTTPStubs doesn't provide support for SPM so we're not running tests on the SPM flavor yet. |
3c9181d
to
3bc1d47
Compare
Package.swift
Outdated
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
.package(url: "https://github.com/raphaelmor/Polyline.git", .branch("master")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6b7a031
to
176c4bb
Compare
/** | ||
A component that represents a lane representation of an instruction. | ||
*/ | ||
@objc(MBLaneIndicationComponent) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@@ -219,6 +221,7 @@ public enum InstructionFormat: UInt, CustomStringConvertible { | |||
|
|||
You do not create instances of this class directly. Instead, create instances of `MatchOptions` or `RouteOptions`. | |||
*/ | |||
@objcMembers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, didn’t know about this annotation. Good find. There are still some bare @objc
keywords in the class; are they redundant now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@objc
is still needed for refinements. It's also useful for compile-time errors of unbridgeable types.
Only using @objcMembers
would fail silently if a type all of a sudden doesn't bridge to Objective-C. Haven't figured out a best practice yet, but as long as we have Obj-C bridging tests, a missing @objc
annotation is fine since it would get caught by the test at compile-time.
@@ -382,7 +390,12 @@ open class DirectionsOptions: NSObject, NSSecureCoding, NSCopying { | |||
|
|||
This property should be set to `MBDirectionsProfileIdentifierAutomobile`, `MBDirectionsProfileIdentifierAutomobileAvoidingTraffic`, `MBDirectionsProfileIdentifierCycling`, or `MBDirectionsProfileIdentifierWalking`. The default value of this property is `MBDirectionsProfileIdentifierAutomobile`, which specifies driving directions. | |||
*/ | |||
#if SWIFT_PACKAGE | |||
open var profileIdentifier: MBDirectionsProfileIdentifier | |||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this conditional compilation still necessary now that the overall class is annotated with @objcMembers
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, not needed.
We can put Obj-C++ inside a separate compat dependency in SPM and compile the Objective-C code along with the Swift framework and therefore support Objective-C w/o having to maintain duplicated types for the SPM version. |
6c22ddd
to
2265f23
Compare
@@ -418,7 +425,7 @@ open class DirectionsOptions: NSObject, NSSecureCoding, NSCopying { | |||
|
|||
By default, no attribute options are specified. It is recommended that `routeShapeResolution` be set to `.full`. | |||
*/ | |||
@objc open var attributeOptions: AttributeOptions = [] | |||
open var attributeOptions: MBAttributeOptions = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the type remain as AttributeOptions
, or does it have to be downgraded to MBAttributeOptions
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested changelog entry:
- Added support for Swift Package Manager. (#362)
Fixes 318 - Support for static library using CocoaPodsFixes #234 - Swift Package Manager on macOS
Deprecate MapboxDirections.swift on CocoaPods public repo in favor of MapboxDirections(Reverted pod rename to minimize the changes)cc @1ec5