xcode6 - Store data in Swift -


i have general question on programming related swift. example when want store int value in app because use variable along whole application. have 3 options this:

//first //in appdelegate var myint = 3 //and later can use when let delegate = uiapplication.sharedapplication().delegate appdelegate delegate.myint = 5  //second //i can store value in userdefaults nsuserdefaults.standarduserdefaults().setinteger(myint, forkey: "myint") nsuserdefaults.standarduserdefaults().synchronize() //and later them var anotherint = nsuserdefaults.standarduserdefaults().integerforkey("myint")  //third //i can define structure data storage struct mydata {     static var myint = 3 } //and later value mydata.myint = 5 

so question is, 1 should use? or shouldn't 1 store global values @ all? love hear :]

option 1 work fine if don't want variable persist between app launches.

option 2 work fine if do want variable persist between app launches.

option 3 work not persistent.

i option 1 or 2 more commonly used, depending on if need variable persistent.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -