How to get a NSuser default value in another viewcontroller in swift

864 Views Asked by At

My requirement is when user entered in to login screen userid will generate that id is stored in nsuserdefault and I want to append this userid with url in another viewcontroller can any one tell me?

2

There are 2 best solutions below

5
On BEST ANSWER

When you generate your user id, you can store it in NSUserDefaults like that :

NSUserDefaults().setObject(userId, forKey: "userId")

Whenever you want to get this userId :

let userId = NSUserDefaults().stringForKey("userId")
0
On

Well first get value of string from defaults

 var myOutput: AnyObject? = NSUserDefaults.standardUserDefaults().objectForKey("key")

Then append in your desired url

 url = url + myOutput

and you are golden