Yet not migrated to swift 3.0 + from 2.3 !? Here is how I did

as the latest swift 4.0 and Xcode 9 is out in market, it's time to upgrade the code base.

When you will open any Xcode project developed with swift 2.3 in latest Xcode versions i.e Xcode 8.0 + OR Xcode 9.0 +, The Migration tool will ask you to convert it to latest swift version. Allow it to do it's work and wait for a while.

Once it show all the required changes, just allow it by pressing SAVE.

Secondly, you will have to update your pods, checkout for the latest compatible pod versions for the existing pods from https://cocoapods.org and update your pod file to the latest version.

Open up the terminal and change directory to your working directory and run the following commands
  1. cd YOUR PROJECT LOCATION
  2. pod repo update
  3. pod install
Now, it comes to solve the pending errors, Checkout if you observe any of the errors from the list then FIX IT

1. Ambiguous reference to member dataTask(with:completionHandler:)

Solution:

CTRL + F in your project workspace

let request = NSMutableURLRequest(url: url!)

Replace all with

var request = URLRequest(url: url!)

2. Value of type `Any` has no member `value`

Solution:

CTRL + F in your project workspace

let jsonResult = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments)

Replace all with

let jsonResult = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as AnyObject

3. Ambiguous reference to member 'componets(separatedBy:)' error

Solution:

Checkout for something like

let arrayXyz: NSArray = fullXyzString.components(separatedBy: " ")

It should be replaced to

let arrayXyz: [String] = fullXyzString.components(separatedBy: " ")

because NSArray can contain AnyObject means every object in the array could be of a different type. Therefore the compiler can't know in advance whether any two objects in the array can be joined. so start showing you error

4. ? must be followed by a call, member lookup, or subscript

Solution:

Checkout for something like

?)! and replace it to if let var = someOptional

5. Value of type `Any` has no member `Object`

Solution:

Check for

             let result = jsonResult!.object(forKey: "data")

Replace it to

               let result = (jsonResult! as AnyObject).object(forKey: "data")

6. Random() is unavailable, use arc4random instead

Solution: Simply find and replace and typecast to UInt32(reminderValue)

Hope it helps :)











要查看或添加评论,请登录

Bhavin Kansagara的更多文章

社区洞察

其他会员也浏览了