[swift-evolution] Pre-proposal: Convert reference params to tuples
Brent Royal-Gordon
brent at architechies.com
Sat Jan 9 21:45:31 CST 2016
> I’m currently converting a class hierarchy from Obj-C to Swift that returns multiple values, but since this code still has to be interoperable with Obj-C (for now), I can’t move it to returning a tuple yet, and all these UnsafeMutablePointers are driving me *crazy*.
As an implementation strategy, you might want to consider writing the Swift interface you want to support, and then declaring Objective-C-compatible cover methods matching the old interface. You can even get the Obj-C ones out of the way in autocomplete by giving them a common prefix:
@nonobjc func getFooAndBar() -> (Int, Int) {
// Insert logic here
}
@objc(getFoo:andBar:) func _objc_getFoo(foo: UnsafeMutablePointer<Int>, andBar bar: UnsafeMutablePointer<Int>) {
(foo.memory, bar.memory) = getFooAndBar()
}
Once your code is all ported and using the Swifty interface, you can remove these cover methods. Or if they need to stay around, you could move them into extensions so they'll stay out of your way.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list