ios - Swift Array Pass by Value...same memory address? -


can please clear me.

i understand (thought) swift passes arrays by value struct.

but when pass array via segue next view controller appears me passing reference, when check memory address of array same.

this how i'm checking

println("\(unsafeaddressof(runs))") // 0x0000000174240c00 

i have thought these memory addresses different ? or confusing myself.

the run / stafftask classes both inherit nsobject saving purposes.

class run: nsobject, nscoding { }  

furthermore, if access item in array

var service = self.stafftasks[indexpath.row] 

and edit value, both service variable value , element in array updated. have same memory address, shown by

println("\(unsafeaddressof(service))  \(unsafeaddressof(self.stafftasks[indexpath.row]))") 

also...

stafftasks subset of larger array called runs

when search service object, larger set, find same memory address

if let index = find(self.runs, self.staff) {     println("local \(unsafeaddressof(self.staff))  main list \(unsafeaddressof(self.runs[index]))") } 

i using nscoding save objects, thought need find service object within larger set, replace object , save them out.

but turns out don't need to, able edit service variable , array of runs updated on automatically ... reference type be.

passing? .. setting var

in prepare segue, setting local var in second vc using standard way, var runsinsecondvc = runs. not using, &pointers or other weirdness.

thanks help.

class basic details

class run: nsobject, nscoding {      var rundate:nsdate!     var staffname:string!     var staffemail:string!     var runtasks:[stafftask]!  }  class stafftask: nsobject, nscoding {      var taskname:string     var tasktime:nsinteger     var clientname:string! } 

these basic of these classes. nothing complicated.

passes arrays value

no. swift arrays value type. not mean pass-by-value. means can mutate array way of reference without affecting other references array has been assigned.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -