ios - Pass a string to a second view controller -


i'm trying pass string second view controller. string title of new view controller. pass string can use 2 solutions , both solutions work correctly me not clear difference. can explain me differences?

here first solution:

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) {         if (segue.identifier == "settime") {             let svc = segue.destinationviewcontroller as! timesetting;             //assign new title             svc.topass = "new title"          }     } 

here second solution:

   override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) {         if (segue.identifier == "settime") {             let svc = segue.destinationviewcontroller as? timesetting;             //assign new title             svc!.topass = "new title"          }     } 

the variable topass defined in way in second viewcontroller:

 var topass:string = "title" 

both solutions perform same action. in opinion, first solution preferred because express intent more precisely.

by stating let svc = segue.destinationviewcontroller as! timesetting state destination view controller of type timesetting.

the second form tests see if destination view controller of type timesetting. if is, variable svc have non-nil value.

if define segue of same name presents different type of view controller, both solutions fail; first 1 on as! clause , second 1 when try unwrap svc!, nil.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -