how to store json object in a variable and use globally in other functions in swift -
var drivers : nsarray?
func loaddriversrest() { restapimanager.sharedinstance.getdriverlist{ json in var drivers = json println(drivers.description) }
func getdriverfromid(id: int?) -> string {
if id == nil { return "no driver assigned" } else{ drivers.["name"] as! string } return "test" }
i don't know want do, there lot of options. can use nsuserdefaults(). did in case user's domains:
private let domain_prefix = "domains_" private let domain_delimiter = "|" private let defaults: nsuserdefaults init() { defaults = nsuserdefaults.standarduserdefaults() } func getdomains(user: string) -> [string] { if let domains = defaults.valueforkey("\(domain_prefix)\(user)") as? string { return domains.componentsseparatedbystring(domain_delimiter) } return [string]() } func savedomains(domains : [string], user: string) { defaults.setvalue(domain_delimiter.join(domains), forkey: "\(domain_prefix)\(user)") defaults.synchronize() }
you can save drivers in save way.
Comments
Post a Comment