BangOperator
BangOperator

Reputation: 4437

Foundation API availability issue with swift

We have used this code lots of times in our objective c app that supports iOS 7 devices.

NSArray* paths = NSSearchPathForDirectoriesInDomains(searchPath, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths firstObject];

And in our objective c app, the documentations show that this API was available since iOS 2.0

enter image description here

We are porting our project to Swift from scratch and there the same API is available since iOS 8.

enter image description here

I created a new swift test project that would support iOS 7 and used this API and it worked. Now I am confused, why in Swift project, the Api is available since iOS 8.0 but still running on iOS 7.0. May be the documentations are wrong. But this is the way we have been checking the availability. If this is not trustworthy it would take lots of time to verify API availability via other sources.

Upvotes: 1

Views: 80

Answers (1)

JAL
JAL

Reputation: 42449

Swift was introduced with iOS 8, so by default the availability of any Swift classes in the Cocoa Touch Framework will be iOS 8 or later.

To see the true availability of a function or class, check the online documentation. As seen here, the true availability of NSSearchPathForDirectoriesInDomains is from iOS 2 and still continues to be available.

Related: What is the availability of NSNotFound?

Upvotes: 0

Related Questions