-
Notifications
You must be signed in to change notification settings - Fork 986
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
Expose CDVCommandStatus enum to Swift #254
Conversation
Current coverage is 56.95% (diff: 100%)@@ master #254 diff @@
==========================================
Files 12 12
Lines 1085 1085
Methods 169 169
Messages 0 0
Branches 174 174
==========================================
Hits 618 618
Misses 467 467
Partials 0 0
|
Haven't played much with Swift enums, is there a way to support both for now, and deprecate the old in Swift? |
This change isn't breaking old code. The enum is still called I would go even further and use |
@dpogue Can you confirm what @lucatorella said? In any case, we don't have any Swift tests yet, but that's easy to remedy for next release. |
Yes, the breaking change is only on the Swift side |
No, because now that enum is not accessible in Swift. So if we want to make it accessible, it's better to make it accessible with proper name conventions ( |
Sorry, I'm mistaken. The plain C enum is currently already available in Swift. So yes, it'll be a breaking change (just in Swift) as much as your proposal :) |
Sorry, Swift newbie here :) (waiting for it to be stable real soon now!). This will be slated for [email protected], I'll see how to add Swift tests in the current test project... |
@dpogue Reviewing PRs for next cordova-ios release. Am I correct to assume since this is a breaking change, it would be for a major version release (since we follow semver)? |
Yes, that is correct |
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.
This looks good to me. Are we still planning to release this in next major and when is the best time to merge?
This causes all existing Swift plugins to break with compiler errors and it's impossible to be backwards compatible and support both... so whenever we feel like that's a good idea 😬 Maybe now is the best time, since we're already changing how Bridging Headers and SwiftVersion are handled? |
@shazron @knight9999 Okay... I think I've come up with a (messy) solution to allow this to not be a breaking change. The existing ObjC enum values are exposed to Swift with friendly names, as per Swift convention: Then, we make a constant variable in ObjC for each of those enum values named It's very ugly and now we have a bunch of global constants sitting around that I don't think the compiler will optimize out :( That said, it seems to work, and I was able to take one of my existing Swift plugins and run it without changing any of the // Old/current style:
let result = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "AbortError");
// New style
let result = CDVPluginResult(status: .error, messageAs: "AbortError"); |
Codecov Report
@@ Coverage Diff @@
## master #254 +/- ##
=======================================
Coverage 74.29% 74.29%
=======================================
Files 12 12
Lines 1564 1564
=======================================
Hits 1162 1162
Misses 402 402 Continue to review full report at Codecov.
|
This allows Swift plugins to write code like `CDVPluginResult(status: .error)` rather than `CDVPluginResult(status: CDVCommandStatus_ERROR)`. However, for existing Swift plugins, it attempts to ensure that the old constants remain exposed with their original names. This is a bit messy and involves global constants in the Objective C code with aliased names exposed to Swift :(
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.
LGTM
This allows Swift plugins to write code like
rather than
Its use in Objective C is unchanged, but
this is a API breaking change as far as Swift plugins are concerned (so we'd be looking at cordova-ios 6 to land this)I've hacked it to support both the existing name and the "friendly" name in Swift, at the cost of the code making sense 😕