swift - Sending array data from one view controller to another -


i trying copy array 1 view controller view controller, somehow not work.. have tried using code:

let othervc = terningspilletviewcontroller()         minespillere = othervc.minespillere2         println("othervc") 

in view controller want send data has code:

var minespillere = ["spiller 1", "spiller 2", "spiller 3"] 

the view controller going received data, has code:

var minespillere2 = [string]() 

the "var minespillere" going show text, when try show it, says "var minespillere" empty. suggestions/ideas?

if want access array of viewcontroller can save in memory , can use nsuserdefaults way:

//save var minespillere = ["spiller 1", "spiller 2", "spiller 3"] var defaults = nsuserdefaults.standarduserdefaults() defaults.setobject(minespillere, forkey: "yourkey") 

now can read anywhere way:

//read if let testarray : anyobject? = nsuserdefaults.standarduserdefaults().objectforkey("yourkey") {     var readarray : [nsstring] = testarray! as! [nsstring]     println(readarray) } 

and if want old way here code:

firstviewcontroller.swift

import uikit  class firstviewcontroller: uiviewcontroller {      var minespillere = ["spiller 1", "spiller 2", "spiller 3"]     override func viewdidload() {         super.viewdidload()     } } 

secondviewcontroller.swift

import uikit  class secondviewcontroller: uiviewcontroller {      var minespillere2 = [string]()     override func viewdidload() {         super.viewdidload()          let othervc = firstviewcontroller()         minespillere2 = othervc.minespillere         println(minespillere2)  //[spiller 1, spiller 2, spiller 3]     }  } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -