Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swift Test - Answers

Swift Test - Answers

The answers for a fun test on Swift I made for the iCapps Team Meeting on 2/7/2014.

Tom Adriaenssen

July 02, 2014
Tweet

More Decks by Tom Adriaenssen

Other Decks in Programming

Transcript

  1. Swift Test!
    The answers…

    View full-size slide

  2. Which of these statements won't
    compile?
    1. if  (beers  >  0)  consumeBeer()  
    2. if  beers  >  0  {  consumeBeer()  }  
    3. if  (beers  >  0)  {  consumeBeer()  }
    1

    View full-size slide

  3. How would you declare a variable
    named awesome of type Double in
    Swift?
    1. Double  awesome  
    2. var:double  awesome  
    3. var  awesome:Double
    2

    View full-size slide

  4. Which of these is not valid Swift?
    1. class  iCapps  {}  
    2. enum  iCapps  {}  
    3. tuple  iCapps  {}  
    4. struct  iCapps  {}
    3

    View full-size slide

  5. Given:
    !
    what is the result of:
    1. stringValue  ==  nil  
    2. stringValue  ==  “Justin  Gif”  
    3. the  compiler  wont  allow  it
    4
    var  stringValue:String  =  “Justin  Gif”  
    stringValue  =  nil  

    View full-size slide

  6. Given Objective-C:
    !
    How would the Swift equivalent look?
    1. rootController?.view?.label?.text  =  “OHAI”  
    2. rootController.view.label.text  =  “OHAI”  
    3. if  rootController  !=  nil  {  
        if  rootController.view  !=  nil  {  
          if  rootController.view.label  !=  nil  {  
            rootController.view.label.text  =  “OHAI”  
          }  
        }  
      }
    5
    rootController.view.label.text  =  @“OHAI”  

    View full-size slide

  7. How do you declare class methods on
    a Swift class?
    1. class  
    2. static  
    3. both
    6

    View full-size slide

  8. What is the mutating keyword for?
    1. Indicates  a  class  can  mutate  its  properties  
    2. Indicates  a  method  on  a  struct  changes  the  struct’s  
    values  
    3. Indicates  that  a  variable  will  change  during  its  
    lifetime
    7

    View full-size slide

  9. Which of these is not a built in swift
    type?
    1. Boolean  
    2. Int  
    3. String
    8

    View full-size slide

  10. What is the equivalent of Objective-C’s
    dealloc in Swift?
    1. dealloc  
    2. dispose  
    3. deinit
    9

    View full-size slide

  11. What is the expected result?
    1. a  =  [  33,  44  ]    
      b  =  [  33,  55  ]    
    2. a  =  [  33,  55  ]    
      b  =  [  33,  55  ]  
    3. compiler  will  not  allow  it
    10
    let  a  =  [  33,  44  ]  
    let  b  =  a  
    b[1]  =  55  

    View full-size slide

  12. What is the expected result?
    1. a  =  [  33,  44  ]    
      b  =  [  33,  44,  55  ]    
    2. a  =  [  33,  44,  55  ]    
      b  =  [  33,  44,  55  ]  
    3. compiler  will  not  allow  it
    11
    let  a  =  [  33,  44  ]  
    let  b  =  a  
    b.append(55)  

    View full-size slide

  13. How do you declare an IBOutlet
    property?
    1. @IBOutlet  var  button:UIButton  
    2. var  button:UIButton(IBOutlet)  
    3. var  button:UIButton
    12

    View full-size slide

  14. let  firstString:String?  =  “abc”  
    let  secondString:String!  =  “abc”  
    Which of these lines will compile?
    1. print  firstString?  
      print  secondString!  
    2. print  firstString!  
      print  secondString  
    3. print  firstString?  
      print  secondString  
    4. print  firstString  
      print  secondString
    13

    View full-size slide