Assigning a reference from a class member to variable in Swift

Viewed 1084
class UserDataStore {
}

class ProfileInteractor {

    var userDataStore: UserDataStore?

    init(userDataStore: UserDataStore?) {
        self.userDataStore = userDataStore
    }
}

var profileInteractor = ProfileInteractor(userDataStore: UserDataStore())
var userDataStore = profileInteractor.userDataStore
profileInteractor.userDataStore = nil

print(profileInteractor.userDataStore == nil) // prints: true
print(userDataStore == nil) // prints: false
print(userDataStore === profileInteractor.userDataStore) // prints: false
  • Can anyone please explain, why userDataStore doesn't point to profileInteractor.userDataStore !?
  • What must I do, that userDataStore points to it?
3 Answers
Related