December 2018
Intermediate to advanced
414 pages
10h 19m
English
Now that we've seen the powerful weak and unowned modifiers and have regained control over our memory management, we are thrilled to use it everywhere. That is, until we see a crash in the form of the following:
Fatal error: Attempted to read an unowned reference but object 0x10132c0f0 was already deallocated.
This is the same issue as the, which the dangling pointer one that we saw earlier in this chapter.
Let's reuse the example, as follows:
func getCard() -> Card { let batman = Person(name: "Batman") let card = Card(batman) batman.cards.append(card) return card}let card = getCard()print("\(card.owner.name)")
In this code, we explicitly return a card, but the owner of this card is not in the memory anymore, as it was ...
Read now
Unlock full access