Swift struct is nil when referenced from a function -


i set struct this:

struct person {     var name: string     var age: int      init(name:string, age:int) {         self.name = name         self.age = age     } } 

if in viewdidload, happens expected.

override func viewdidload() {     super.viewdidload()     let person = person(name: "sally", age: 20)     self.titlelabel.text = person.name } 

however, if put same code in function, , call function elsewhere

func setup() {     let person = person(name: "wally", age: 12)     self.titlelabel.text = person.name } 

the app crashes on line label set, message:

"fatal error: unexpectedly found nil while unwrapping optional value"

what missing here?


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -