1

I've created a class which should have a variable containing a pointer to a Swift object.

class dataCollector: NSObject {
  var dataDict : [String:Int] = ["value1":10]
  ...(class will update values inside dataDict regularly)...
}

class dataDisplay: NSObject {
  var name : String = "Name"
  var object : dataCollector? = nil
}

I'm using this to instantiate the dataDisplay object

var collector1 = dataCollector()
...
var display1 = dataDisplay()
...
display1.object = collector1

I'm wondering of object in display1 contains a copy of collector1 or a pointer to collector1.

I set a binding to display1.object.value1 which isn't updated in the UI although it is updated in the dataCollector object (I've checked this via some print() output)

If object is indeed no pointer how can I add a pointer variable to the class?

Thanks!

1
  • Why are these all subclassing NSObject? Commented May 19, 2017 at 19:08

1 Answer 1

1

collector1 and display1.object are both referencess to the same dataCollector object. This is the case for all reference (class) types. Value types on the other hand (enums, tuples, structs) are all copied on assignment.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.