Originally created by @ghost on GitHub (Dec 8, 2016).
So i have a button in the first view controller that when pressed, creates an entity friend like so:
Static.datastack.beginAsynchronous{ (transaction) in
let json: [String: AnyObject] = [ "id" : ID as AnyObject]
let friend = try! transaction.importUniqueObject(Into(Friend.self), source: json)
transaction.commit({ (saveResult) in
if saveResult.boolValue == true {
let secondvc = secondvc()
secondvc.friend = friend //this is the part that fails
self.navigationController?.show(secondvc, sender: nil)
}
})
}
class secondvc() {
var friend: Friend!
}
In the second view controller, if I try to access the value friend, its nil. I 'am absolutely positive that it is indeed saving since I can access the value in the first view controller (if i were to print it in the commit completion handler, it would give a value, but in the second vc, its nil). I have found a workaround to this which is just to fetch the friend in the second view controller. However, I 'am very curious as to what the problem is and how to go about fixing it. This framework is so powerful that I want to know how to fully manipulate it. Thank you !
Originally created by @ghost on GitHub (Dec 8, 2016).
So i have a button in the first view controller that when pressed, creates an entity friend like so:
Static.datastack.beginAsynchronous{ (transaction) in
let json: [String: AnyObject] = [ "id" : ID as AnyObject]
let friend = try! transaction.importUniqueObject(Into(Friend.self), source: json)
transaction.commit({ (saveResult) in
if saveResult.boolValue == true {
let secondvc = secondvc()
secondvc.friend = friend //this is the part that fails
self.navigationController?.show(secondvc, sender: nil)
}
})
}
class secondvc() {
var friend: Friend!
}
In the second view controller, if I try to access the value friend, its nil. I 'am absolutely positive that it is indeed saving since I can access the value in the first view controller (if i were to print it in the commit completion handler, it would give a value, but in the second vc, its nil). I have found a workaround to this which is just to fetch the friend in the second view controller. However, I 'am very curious as to what the problem is and how to go about fixing it. This framework is so powerful that I want to know how to fully manipulate it. Thank you !
And i forgot, a fault does print out when passing friend to the second view controller when I try to print(self.friend) in the second vc
@ghost commented on GitHub (Dec 8, 2016):
And i forgot, a fault does print out when passing friend to the second view controller when I try to print(self.friend) in the second vc
@JohnEstropia commented on GitHub (Dec 8, 2016):
Hi, you are passing a transaction-only instance which would be invalid after commit().
try
```swift
secondvc.friend = Static.datastack.fetchExisting(friend)
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @ghost on GitHub (Dec 8, 2016).
So i have a button in the first view controller that when pressed, creates an entity friend like so:
class secondvc() {
var friend: Friend!
}
In the second view controller, if I try to access the value friend, its nil. I 'am absolutely positive that it is indeed saving since I can access the value in the first view controller (if i were to print it in the commit completion handler, it would give a value, but in the second vc, its nil). I have found a workaround to this which is just to fetch the friend in the second view controller. However, I 'am very curious as to what the problem is and how to go about fixing it. This framework is so powerful that I want to know how to fully manipulate it. Thank you !
@ghost commented on GitHub (Dec 8, 2016):
And i forgot, a fault does print out when passing friend to the second view controller when I try to print(self.friend) in the second vc
@JohnEstropia commented on GitHub (Dec 8, 2016):
Hi, you are passing a transaction-only instance which would be invalid after commit().
try
@ghost commented on GitHub (Dec 8, 2016):
worked like a charm, thank you very much !
@JohnEstropia commented on GitHub (Dec 8, 2016):
Glad it worked :)