Store global strings in iOS in Swift for app-wide use -
i designing app has login screen. when user enters username , password, call web service done returns token on successful login. need send token every http call inside different screens across app.
i want achieve similar functionality this: where store global constants in ios application?
as there won't .h
, .m
files in swift, how store these global strings (note these not constants, these global variables) need able access in view controller
this wanted: sharing strings , variables throughout ios app
i able share strings such apikeys, tokens using nsuserdefaults
saving:
nsuserdefaults.standarduserdefaults().setobject("apistringhere", forkey: "apikey") nsuserdefaults.standarduserdefaults().synchronize()
getting:
nsuserdefaults.standarduserdefaults().objectforkey("apikey")
Comments
Post a Comment