fatal error: unexpectedly found nil while unwrapping an Optional value
It means your variable is set to nil, but your code is expecting it to not be nil.
什么叫"your code is expecting it to not be nil"呢?來看個(gè)例子:
var name : String?
name = nil
name!.uppercaseString//fatal error: unexpectedly found nil while unwrapping an Optional value
Initializer requirement 'XXXX' can only be satisfied by a required initializer in the definition of non-final class 'XXXX'
意思就是你聲明的'XXXX'這個(gè)構(gòu)造器要么加上required關(guān)鍵字,要么把你的類改成final class。
為什么呢?
出現(xiàn)這種情況,一般是在自定義的'XXXX'構(gòu)造器由于某種原因必須在子類中重寫,在子類中重寫的構(gòu)造器必須加required關(guān)鍵字。當(dāng)然如果是final class也就不用操這個(gè)心了,因?yàn)閴焊粫?huì)有子類。
關(guān)于swift構(gòu)造器可以參考Swift initializer