Xcode 8 - Swift 3 - Break my app - ios

On the previous version of xcode ( Xcode 8 beta 6 ) , my app running fine without errors. I updated xcode this morning, I run my app and now, I have 400 errors !
Pods installed not working and on my code all is on red !
I'm a bit frustrated to have made an update and this has resulted to demolish my application.
How can I resolve my situation ?
Example of code not working now :
if UserDefaults.standard.string(forKey: "token") != nil => Use of unresolved identifier
if( CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse => Type CLAuthorizationStatus has no member authorizedWhenInUse
No luck, I had to quickly add an update that corrects a version of the app store that crash at startup ...

The newest version of Xcode, Xcode 8 beta or Xcode 8 GM seed, runs on an updated and swifter version of Swift. Likely your errors are because your command strings are now too long. If you cannot convert the files, you may need to go in and edit each command line. Refer to the release notes for the newest version of Xcode you have to find these new statements.
Example:
// old code (Swift 2.2)
let content = text.stringByTrimmingCharactersInSet(NSCharacterSet.newlineCharacterSet())
// new code (Swift 3.0)
let content2 = text.trimmingCharacters(in: .newlines)
resource:
https://developer.apple.com/swift/

Related

`UTF16Index()` or `UTF16Index.init(encodedOffset:)` for Xcode 8/9 support

I'm on a development team that's supporting both Xcode 8 and Xcode 9.
I was developing a feature that used String.UTF16Index(range.location) in Xcode 8. When I upgraded to Xcode 9, that resulted in the error 'init' is deprecated.
So in Xcode 9 I changed it to UTF16Index.init(encodedOffset: range.lowerBound). However, now that doesn't work in Xcode 8 with the error Argument labels '(encodedOffset:)' do not match any available overloads.
Even if I could check the Xcode version and write different code, one of the lines would fail at compile time. How can I manage this? Or am I stuck waiting until we fully move to Xcode 9?
From Version Compatibility in the Swift documentation:
NOTE
When the Swift 4 compiler is working with Swift 3 code, it identifies its language version as 3.2. As a result, you can use conditional compilation blocks like #if swift(>=3.2) to write code that’s compatible with multiple versions of the Swift compiler.
In your case that would be
#if swift(>=3.2)
let idx = String.UTF16Index(encodedOffset: range.lowerBound)
#else
let idx = String.UTF16Index(range.location)
#endif
In Xcode 9 (Swift 4 or Swift 3.2 mode) only the first line is compiled,
and in Xcode 8 (Swift 3.1) only the second line is compiled.
Update: The use of encodedOffset is considered harmful and will be deprecated in Swift 5. Starting with Swift 4, the correct way to convert an NSRange to a Range<String.Index> is
let str = "abc"
let nsRange = NSRange(location: 2, length: 1)
let sRange = Range(nsRange, in: str)
As others have said, you can do a Swift version check to call the right API. But if you're calling this from multiple places then it might be easier to define a shim
#if swift(>=3.2)
// already correct
#else
extension String.UTF16Index {
init(encodedOffset: Int) {
self.init(encodedOffset)
}
}
#endif
Now you can just write String.UTF16Index(encodedOffset: range.lowerBound) and in Xcode 8 it will call your shim.

ARSessionConfiguration unresolved in Xcode 9 GM

I have created an ARKit project using a beta version of Xcode 9, which I was able to run on my real device without issues.
Yesterday, I upgraded to Xcode 9 GM, and without touching anything, Xcode shows multiple errors, saying it does not know ARSessionConfiguration i.e.:
Use of undeclared type 'ARSessionConfiguration'
and:
Use of undeclared type 'ARWorldTrackingSessionConfiguration'
...for this code:
let session = ARSession()
var sessionConfig: ARSessionConfiguration = ARWorldTrackingSessionConfiguration()
I have imported ARKit and am using the ARSCNViewDelegate in my ViewController.
When opening the project from the beta version of Xcode, it does not show the errors and I can again run the app on my phone.
Any idea how I can fix this?
ARWorldTrackingSessionConfiguration has been deprecated and renamed to ARWorldTrackingConfiguration: See here
Also, ARSessionConfiguration has been deprecated and renamed to ARConfiguration, which is now an abstract base class.
Use AROrientationTrackingConfiguration when you don't want world tracking, instead of using a generic ARConfiguration. Thus:
let configuration = AROrientationTrackingConfiguration()
You can also check if world tracking is supported on a device:
if ARWorldTrackingConfiguration.isSupported {
configuration = ARWorldTrackingConfiguration()
}
else {
configuration = AROrientationTrackingConfiguration()
}
In Xcode 9 GM, looks like ARWorldTrackingSessionConfiguration has been renamed to ARWorldTrackingConfiguration:
https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration
Reference to this change:
https://github.com/markdaws/arkit-by-example/issues/7
ARSessionConfiguration has been renamed to ARConfiguration:
https://developer.apple.com/documentation/arkit/arconfiguration

NSAttributedStringKey.attachment versus NSAttachmentAttributeName

I'm having problems with NSAttributedStringKey.attachment versus NSAttachmentAttributeName. Here's the relevant code:
var key: Any?
if #available(iOS 11, *) {
key = NSAttributedStringKey.attachment
}
else {
key = NSAttachmentAttributeName
}
One of two things are happening. In the actual place where I'm trying to use this code (a Cococapod of my own design, with a deployment target of iOS 8 and now building with Xcode 9), I get an error:
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'attachment'
Or, if I just make a new example project and set the deployment target at iOS 8, I get:
'NSAttachmentAttributeName' has been renamed to 'NSAttributedStringKey.attachment'
This is not the behavior I'd expect with #available. Thoughts?
This String vs struct difference is between Swift 3 (uses Strings such as NSAttachmentAttributeName) and Swift 4 (uses struct static attributes such as NSAttributedStringKey.attachment), not between iOS <11 and iOS >=11. For instance, you can use NSAttributedStringKey.attachment and similar in any supporting version of iOS (e.g. .attachment is available since iOS 7) within a Swift 4 project. #available doesn't apply because it's a Swift language version difference rather than an OS version difference.
Ensure your pod is set to the correct Swift version and it should then work as expected. You can tell CocoaPods that by adding a .swift-version file at the top of your project:
$ echo 4.0 >.swift-version
This magical version file is mentioned in passing in a CocoaPods blog post from last year: http://blog.cocoapods.org/CocoaPods-1.1.0/

Cannot build source in XCODE 8 iOS 10

I have developed iOS application using Swift 2.3. and I have put the application to the app store in review process, apparently they have rejected it due to crash in iOS 10 .
Then in order to fix it I have downloaded the Xcode 8 and tried to build the app without converting code in to swift 3 using legacy setting
But I couldn't build the app. There was few compile errors in pods that I have used. (Alamofire framework)
error :- and there will more
private func trustIsValid(trust: SecTrust) -> Bool {
var isValid = false
var result = SecTrustResultType(kSecTrustResultInvalid)
let status = SecTrustEvaluate(trust, &result)
if status == errSecSuccess {
let unspecified = SecTrustResultType(kSecTrustResultUnspecified)
let proceed = SecTrustResultType(kSecTrustResultProceed)
isValid = result == unspecified || result == proceed
}
return isValid
}
So I did a small digging apparently Alamofire has released a new version for Xcode 8 so i have put that version, apparently I can't integrate that version in to my source code since it's in Swift 2.3.
Can someone help me to get over with this issue, problem was I can't release the app to App store since there is a crash in iOS 10 and I can't check it since I don't have iOS 10.

suddenly UIUserNotificationActionResponseTypedTextKey is unavailable

I don't understand this. Suddenly, I couldn't use the in iOS 9.0 introduced UIUserNotificationActionResponseTypedTextKey identifier for accessing text input messages in notifications. Xcode 7.1 says: "UIUserNotificationActionResponseTypedTextKey is unavailable".
But I can see this value in UIUserNotificationeSettings.h.
In Watchos2.0 I have this value.
Any Ideas?
I'm seeing the same exact thing in the release version of Xcode 7.2. Instead of using the key UIUserNotificationActionResponseTypedTextKey, I've gotten it working using the string version "UIUserNotificationActionResponseTypedTextKey".
So for me this is doing the trick:
if let response = responseInfo["UIUserNotificationActionResponseTypedTextKey"] as? String {
// Your code here
}

Resources