The structure is roughly like this. Class A contains an array of class B, and class B contains a variable of enumeration type C.
A is initialized as shown in the figure when it is first initialized10 B elements come out, except that the B array in class A has not been modified. However, when encoding s in B, (enumeration C is Status), the value of s can be printed out
, But an error was reported after encode (s) (I put breakpoints on both print and encode, and the latter crashed as soon as I left it)
func encode(with aCoder: NSCoder) {
print(status)
aCoder.encode(status, forKey: "status")
}
The following is some console information:
Normal
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue encodeWithCoder:]: unrecognized selector sent to instance 0x608000444fb0'
At the same time, there is Thread 1: signal SIGABRT at the top of AppDelegate. After searching on Google, it seems that it is because the object was released early, but the value can still be printed before encode.
The value can be typed, but the value is not the expected value. In a loop before encoding, the value of each B enumeration type of the A class B array is replaced one by one (not directly replacing the object B)
已经找到原因了,原因就是枚举类型直接编译会产生各种问题,曲线救国存读枚举的值就行了