Convert swift2 syntax to swift3

Discussion in 'iOS Programming' started by Ceonn, Aug 2, 2016.

Tags:
  1. Ceonn macrumors newbie

    Joined:
    Jul 27, 2016
    #1
    Can someone please help me with a some conversion from swift2 to swift3? Here are the three lines written in swift2 and would like this functioning in swift3:


    Code:
    return CGSizeMake(view.frame.width, 80)
    layout.headerReferenceSize = CGSizeMake(view.frame.width, 50)
    return CGSizeMake(view.frame.width, size.height + 16)
    Thanks in advance!
     
  2. Mascots macrumors 65816

    Mascots

    Joined:
    Sep 5, 2009
    #2
    With Swift 3, you can initialize a CGSize and CGRect directly through the constructor:

    Code:
    let size = CGSize(width: 150, height: 150)
    Code:
    let rect = CGRect(x: 10, y: 10, width: 150, height: 150)
     
  3. Ceonn thread starter macrumors newbie

    Joined:
    Jul 27, 2016
    #3
    Thanks Mascots. I have seen this on a few threads on different forums and all, but to be more on point I am having issues implementing that into the code I listed above... It would be great if you have the possibility to maybe show me how it's done with my code.

    Appreciate the help!
     
  4. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #4
    Code:
    return CGSize(width: view!.frame.width, height: CGFloat(80.0))
    layout.headerReferenceSize = CGSize(width: view!.frame.width, height: CGFloat(50.0))
    return CGSize(width: view!.frame.width, height: size.height + CGFloat(16.0))
    
     

Share This Page