[Swift] NSCoding과 Codable 차이점 (상속 관계 유지하기)
·
Swift/개념 & 응용
NSCoding과 Codable Codable이 나오면서 NSCoding은 옛날의 그것으로 생각되었습니다. 그런데 NSCoding만이 할 수 있는 일이 있었습니다. 바로 상속 관계를 유지해서 저장하는 것입니다. Shape 부모 클래스를 상속하는 두 개의 자식 클래스가 있습니다. class Plane { var shapes: [Shape] init(shapes: [Shape]) { self.shapes = shapes } func display() { for shape in shapes { print("\(type(of: shape)): \(shape.description)") } } } let shapes: [Shape] = [ Rect(point: .init(x: 10, y: 10), size: .in..
유정주
'NSCoding' 태그의 글 목록