Difficulties converting to Swift 3

后端 未结 3 1808
無奈伤痛
無奈伤痛 2021-01-30 01:30

After converting from Swift 2 to Swift 3 (even after converting edit-> convert -> to current swift syntax) I am getting lots of errors. Especially:

I am show

相关标签:
3条回答
  • 2021-01-30 02:21

    I was converting a project and Xcode was not helping me with any fixes so I resorted to a couple of regex search-and-replaces:-

    CGPointMake\((.*),[ ]*([^\)]+)\)
    CGPoint(x:$1, y:$2)
    
    CGSizeMake\((.*),[ ]*([^\)]+)\)
    CGSize(width:$1, height:$2)
    

    Note they are not aware of nested parentheses , but probably good enough for 90% of cases.

    0 讨论(0)
  • 2021-01-30 02:22

    And always remember to use the helpful "Fix all in Scope" function which can be found at Editor -> Fix all in Scope

    0 讨论(0)
  • 2021-01-30 02:27

    Most of them are easy fixes, simply by tapping the red button, and having Xcode fix it for you! Others include:

    CGRect

    Swift 2:

    let frame = CGRectMake(0, 0, 20, 20)
    

    Swift 3:

    let frame = CGRect(x: 0, y: 0, width: 20, height: 20)
    

    CGPoint

    Swift 2:

    let point = CGPointMake(0, 0)
    

    Swift 3:

    let point = CGPoint(x: 0, y: 0)
    

    CGSize

    Swift 2:

    let size = CGSizeMake(20, 20)
    

    Swift 3:

    let size = CGSize(width: 20, height: 20)
    

    CGRectGetMidX

    Swift 2:

    CGRectGetMidX(view)
    

    Swift 3:

    view.midX
    

    CGRectGetMidY

    Swift 2:

    CGRectGetMidY(view)
    

    Swift 3:

    view.midY
    

    UIColor

    Swift 2:

    let color = UIColor.redColor()
    

    Swift 3:

    let color = UIColor.red
    

    "NS"

    Swift 2:

    NSTimer
    NSData
    NSError
    

    Swift 3:

    Timer
    Data
    Error
    

    UserDefaults

    Swift 2:

    NSUserDefaults.standardUserDefaults().//something
    

    Swift 3:

    UserDefaults.standard.//something
    
    0 讨论(0)
提交回复
热议问题