Xcode 10's base SDK?

Maybe I have missed some big change between Xcode 9 and 10, but I've noticed a couple of strange things:


Compiling our project with Xcode 10, we noticed that we were able to reference functions that are only available in Swift 4.x, where our Project Settings clearly have it set to Swift 3.3. We can call array.randomElement() etc, whereas in Xcode 9 (with Swift 3.3) we get the expected compilation error.


We also started noticing some behaviour in our UI that were not there previously - such as UIViewControllers with hidesBottomBarOnPush set to true in code not smoothly animating the tab bar out on push, and only doing so correctly when the property is set in Interface Builder. I determined this to be a bug on iOS 12, but actually it appears to be when building with Xcode 10.


I checked the Base SDK setting in Xcode 10 and it simply says "iOS". I opened Xcode 9.4.1 and it says "Latest iOS (iSO 11.4)" and allows me to change it.


Is the base SDK now forced to 12?

How can we not get compilation errors for using Swift 4 methods when our Swift version is 3.3?


Maybe I've missed something obvious but I'd be grateful if someone could explain how Xcode 10 is handling Base SDK and Swift language versioning.

I tested randomElement in Swift 3 mode, and it works.


I notice, that it is defined as an extension for Array:

public func randomElement() -> Element?

Hence, this may work as well in Swift 3 mode, as extension, not as language feature.


Should be interested by this discussion:

https://forums.swift.org/t/swift-4-1-or-swift-3-3/7367/8

Thankyour for the reply. If I read correctly It seems from the linked discussion there is some 'compatibility mode' which means that selecting, say, 3.2 in Build Settings actually compiles with the 4.x(?) compiler and allows backwards compatibility to 3.2 - so things like older API for 3.2 will still be available via things like typealias etc. I'm still not clear on the other way around though - selecting 3.2 but being able to use 4.x API; the discussion doesn't seem to say compatibility works that way around although that could be implicit - you're actually building 4.x so you can access that API, but you can also access the API for the version you believe you're building with. If that's the case it's a bit alarming in that there's nothign in Xcode's settings UI that indicates it.


I'm still not clear what's going on with the base SDK under Xcode 10 though. Is it a case of using Xcode 10 means we can only build against the iOS 12 SDK? I'm sceptical because SDK versioning hasn't been enforced with previous Xcode versions as far as I'm aware.

I don't understand mare than you how this exactly works !


But could it be that some features of Swift 4 could have been anticipated through extensions in 3.2 or 3.3 ?


May be you could ask the question in Swift.org forum ?

>still not clear on the other way around though - selecting 3.2 but being able to use 4.x API; the discussion doesn't seem to say compatibility works that way around


Don't conflate supported code with migrated code.


From the Xcode 10 Release Notes:


Xcode 10 is the last release that will support Swift 3. Migrate your projects from Swift 3 code to Swift 4.2 syntax by opening the project and choosing Edit > Convert > To Current Swift Syntax… (43101816)

In recent Xcodes (for a few years, at least), Xcode version and SDK version are tightly coupled.


Xcode 10 comes with iOS SDK 12 and Swift compiler 4.2.

When you compile your project written in Swift 3 with Xcode 10, it is compiled in the Swift 3.4 mode of Swift 4.2 compiler,

and linked against iOS SDK 12.


And the SDK version and your app's target version are different things. You can build your Swift apps targeting iOS 8 (maybe 7, but I cannot test it) or later with iOS SDK 12.

Thanks for the explanation OOPer. I understand the difference between Base SDK and Deployment Target. I didn't know that Xcode version and the SDK version have become coupled though - I recall about 2/3 years ago Apple had to deadline newly submitted apps onto the new SDK version (maybe 9 or 10?) by the January after initial release of that iOS version, meaning that it was possible to be running the newest Xcode and compiling against an older SDK; now I guess it means that building with the new version of Xcode also means you're building with the latest SDK.


To recap what I think I understand then:


1) For the Base SDK issue, Xcode releases are coupled with the latest SDK version. Xcode 10 now shows us just the option of "iOS" under Base SDK, whereas 9 shows various versions, so it was clearly possible to compile against older SDKs until Xcode 10.


2) For the Swift version issue, when selecting 3.2, the compiler is in fact compiling in a 4.2 compatibility mode, so you actually do have access to 4.2 syntax and methods etc.

whereas 9 shows various versions


Sorry, can you tell me if I may be missing something? But I cannot find any menus or settings titled Base SDK showing various versions.

Can you tell me how to show it in Xcode 9.4.1?

Here are screenshots of Xcode 10 (dark mode) and Xcode 9.4.1. The 9 menu does only show 11.4 but I believe if you have multiple SDKs available they showed up in this menu. (in case the images aren't visible I've uploaded them here: https://imgur.com/a/IDsV2F7).

You're probably right in that for the last few major versions this menu has only contained the latest SDK, and I had to download older SDKs and load them via the 'Other...' option (and from them on it would be selectable in this menu). Looks like just a UI change in 10 then, and for previous major version updates I simply didn't notice I was building with the latest SDK.

Thanks. I have found that I changed my Xcode settings about Project editor long time ago and I can find the Base SDK setting in the Build Settings.


I had to download older SDKs and load them via the 'Other...' option

Looks like you were using an old hack to install older SDKs which have not been supported in recent Xcodes.


and for previous major version updates I simply didn't notice I was building with the latest SDK.

It is very lucky for you. If you succeeded to build against older SDKs, your app would be malfunctioning or rejected.

Xcode 10's base SDK?
 
 
Q