Is there a better way to save a custom class to NSUserDefaults than encoding and decoding everything with NSCoder?

前端 未结 2 1303
南笙
南笙 2021-01-03 15:42

My current class has around 50 lines just encoding and decoding variables in order for my class to be NSUserDefaults compatible. Is there a better way to handle this?

<
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 16:03

    Look at protocol codeable in Swift 4.

    The decoder and encoder will be auto-generated for you.

    Check out: (starting about half way through) https://developer.apple.com/videos/play/wwdc2017/212/

提交回复
热议问题