Ch24. Asset class initialiser error - Return from initializer without initializing all stored properties

/CyclicalAssets/Asset.swift:25:5: Return from initializer without initializing all stored properties

getting this error from Xcode.

if i add owner = nil to the initialiser then it goes away so it would appear that it is required that optional properties must also be set in the initialiser of a class.

is that correct ?

Really hard to say without seeing your exact code. (The code as written in the book worked fine for me.)

I tried several “typos,” but was unable to duplicate the issue. Can you show the code as entered?

if you declared “owner” like this:

var owner: String?

you don’t need to set it in the initialiser

if you declared “owner” like this instead:

let owner: String?

you do need to set it in your initialiser

Nice catch! Will have to remember that correlation…

I had the same issue. The problem was that I hand-typed my code (rather than copy & paste from my e-book) and I made a small typo. I had entered the following:

let owner: Person?

But the book uses the following:

var owner: Person?

Even after going over the code multiple times I didn’t catch this small change. With just three tiny letters, it’s easy to overlook!