Swift 2.2 Warnings and It’s Solutions – Xcode 7.3

Swift 2.2 Warnings and It’s Solutions – Xcode 7.3

 

Xcode 7.3 came with Swift 2.2 Version. I just updated to Xcode 7.3 and found following warnings because of Swift version change.swift

List of warnings with it’s solution:

 

 

Warning Function Var

Warning Function Varapp

    • ‘var’ parameters are deprecated and will be removed in Swift 3

  1. Warning with:

     

    1ide

    2oop

    3post

    func functionTest(var param:String) {spa

        print(param)3d

    }code

    Solution:orm

    1blog

    2

    3

    func functionTest(param:String) {

        print(param)

    }

    If you want to update that variable inside the function then you have to create copy of that variable to do operations on that. 

     

    • Use of string literal for Objective-C selectors is deprecated; use ‘#selector’ instead

     

    Warning Selector

    Warning Selector


    Warning with:

     

    1

    btn.addTarget(self, action: "functionName", forControlEvents: UIControlEvents.TouchUpInside)

    OR

    1

    btn.addTarget(self, action: Selector("functionName"), forControlEvents: UIControlEvents.TouchUpInside)

    Solution:

    1

    btn.addTarget(self, action: #selector(ViewController.functionName), forControlEvents: UIControlEvents.TouchUpInside)

    Apple Documentation : Added information about the #selector syntax for Objective-C selectors to the Selector Expression section.

     

    • ‘++’ is deprecated: it will be removed in Swift 3

     

    Warning ++

    Warning ++


    Warning with:

     

    1

    2

    3

    4

    5

    6

    var i = 0

             

    for str in arrStr {

        print(str)

        i++

    }

    Solution:

    1

    2

    3

    4

    5

    6

    var i = 0

             

    for str in arrStr {

        print(str)

        i += 1

    }

    Apple Documentation : Removed discussion of C-style for loops, the ++ prefix and postfix operators, and the — prefix and postfix operators.

     

    • C-style for statement is deprecated and will be removed in a future version of Swift

     

    Warning For Statement

    Warning For Statement


    Warning with:

     

    1

    2

    3

    for var i=0; i<arrStr.count; i += 1 {

        print(arrStr[i])

    }

    Solution:

    1

    2

    3

    for i in 0 ..< arrStr.count {

        print(arrStr[i])

    }

     

    • __FILE__ is deprecated and will be removed in Swift 3, please use #file
    Warning __FILE__

    Warning __FILE__

    Warning with:

    1

    __FILE__

    Solution:

    1

    #file

More swift tutorials/articles are available here.

Happy Coding 🙂

相關文章
相關標籤/搜索