iOS: Null pointer reference when encoding non-null enum type?
淡淡烟草味
淡淡烟草味 2017-05-31 10:36:30
0
1
703

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)

淡淡烟草味
淡淡烟草味

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!