Last active
September 4, 2021 07:48
Revisions
-
codelynx revised this gist
Sep 4, 2021 . 1 changed file with 4 additions and 12 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,14 +6,6 @@ import Foundation import CoreGraphics protocol Shape { } @@ -35,10 +27,10 @@ class Rectangle: Shape { } } class RoundedRectangle: Rectangle { var cornerRadius: CGFloat init(origin: CGPoint, size: CGSize, cornerRadius: CGFloat) { self.cornerRadius = cornerRadius super.init(origin: origin, size: size) } } -
codelynx created this gist
Sep 3, 2021 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ /* This sample code shows the problem of archive and unarchive abstruct objects. Please see `TODO` keyword and make this Contents class to save and load shape objects. */ import Foundation import CoreGraphics struct RGBA: Codable, CustomStringConvertible { var r: Float16 var g: Float16 var b: Float16 var a: Float16 var description: String { "(\(self.r), \(self.r), \(self.r), \(self.r))" } } protocol Shape { } class Circle: Shape { var center: CGPoint var radius: CGFloat init(center: CGPoint, radius: CGFloat) { self.center = center self.radius = radius } } class Rectangle: Shape { var origin: CGPoint var size: CGSize init(origin: CGPoint, size: CGSize) { self.origin = origin self.size = size } } class ColoredRectangle: Rectangle { var color: RGBA init(origin: CGPoint, size: CGSize, color: RGBA) { self.color = color super.init(origin: origin, size: size) } } class Contens { var shapes: [Shape] init(shapes: [Shape]) { self.shapes = shapes } init?(binary: Data) { // TODO: archive shapes to binary fatalError() } func binary() -> Data { // TODO: unarchive all shpes from binary fatalError() } }