Michael
Michael

Reputation: 6517

Swift 4.1 ABI forward compatibility: implement function that Apple will implement in the future

I don't care if I have to recompile my app next year, because Apple changed the Swift language again.

What I do care however, is if an app of mine that is already in the app store, stops working and crashes on app start during load time, because the user updated to the next iOS version. I'm coming from an Objective C background, but I don't understand what is happening in Swift applications on a binary level.

In an app that I am writing, I added a function that allows me to add two CGPoint values. It makes some sense to do this, e.g. when you are using pan gesture recognizers. The code is:

func +(_ a: CGPoint, _ b: CGPoint) -> CGPoint {
    return CGPoint(x: a.x+b.x, y: a.y+b.y)
}

The question is: if Apple decides in the future that they add a + function for CGPoint too, does it break my app? (I don't care if I have to remove this function and recompile, I only care if applications that are already deployed suddenly break after an iOS update.)

System: macOS 10.13.6 with Xcode 9.4, Swift 4.1, Deployment target iOS 9.0

Upvotes: 2

Views: 153

Answers (1)

Ole Begemann
Ole Begemann

Reputation: 135540

if Apple decides in the future that they add a + function for CGPoint too, does it break my app?

No. Firstly. the Swift overlays for system frameworks are currently shipped with your app. Evne if/when that changes in the future after ABI stability, existing apps will not be affected unless they are recompiled.

Secondly, overload resolution happens at compile time. I.e. the compiler picks the concrete function to call, and no dynamic linking will change it.


Things would be different if you conformed CGPoint to an existing protocol such as BinaryInteger that included the + operator in its requirements because protocol requirements can be dispatched dynamically. (Conforming CGPoint to BinaryInteger probably doesn't make sense, but bear with me for the sake of argument.)

In that case, a conflicting conformance from Apple added in a future release might cause conflicts.

There's an ongoing discussion on the Swift Forums about how Swift should handle this last issue: Retroactive Conformances vs. Swift-in-the-OS.

Upvotes: 4

Related Questions