diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index 5f3b18f9..207fc1cf 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -7,24 +7,32 @@ objects = { /* Begin PBXBuildFile section */ - 736D9D3027CFB3CA00C040D8 /* FactoryArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D2F27CFB3CA00C040D8 /* FactoryArray.swift */; }; + 73312E5027D618C10073D746 /* ID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738A8A8227D5AC1400086985 /* ID.swift */; }; + 7348F21B27D7407F00613449 /* Plane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7348F21A27D7407F00613449 /* Plane.swift */; }; + 735A316027DEE60900E3E4C0 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 735A315F27DEE60900E3E4C0 /* Log.swift */; }; + 735A316327DF802500E3E4C0 /* ControlView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 735A316227DF802500E3E4C0 /* ControlView.xib */; }; + 735A316727DF80ED00E3E4C0 /* ControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 735A316627DF80ED00E3E4C0 /* ControlView.swift */; }; + 735A316927DF84A600E3E4C0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 735A316827DF84A600E3E4C0 /* ViewController.swift */; }; 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */; }; - 736D9D4127CFBF9400C040D8 /* FactoryArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D2F27CFB3CA00C040D8 /* FactoryArray.swift */; }; 736D9D4227CFBF9600C040D8 /* Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750BC27CE1D1A00086C1D /* Factory.swift */; }; 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B227CE00FE00086C1D /* Point.swift */; }; - 736D9D4427CFBF9E00C040D8 /* BackgroundColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B427CE015800086C1D /* BackgroundColor.swift */; }; + 736D9D4427CFBF9E00C040D8 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B427CE015800086C1D /* Color.swift */; }; 736D9D4527CFBF9E00C040D8 /* Alpha.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B627CE01CF00086C1D /* Alpha.swift */; }; 736D9D4627CFBF9E00C040D8 /* Rectangle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B827CE033900086C1D /* Rectangle.swift */; }; 736D9D4727CFBF9E00C040D8 /* Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B027CE007300086C1D /* Size.swift */; }; + 738A8A8327D5AC1400086985 /* ID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738A8A8227D5AC1400086985 /* ID.swift */; }; + 738ADB1227DEDCC300BE418C /* Convert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73966C8727DA10FE006883FF /* Convert.swift */; }; + 73966C8827DA10FE006883FF /* Convert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73966C8727DA10FE006883FF /* Convert.swift */; }; + 739B87AD27E3178100346AD9 /* PlaneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739B87AC27E3178100346AD9 /* PlaneDelegate.swift */; }; + 739B87AF27E31F3C00346AD9 /* ControlViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739B87AE27E31F3C00346AD9 /* ControlViewDelegate.swift */; }; 73C7509C27CDB7D300086C1D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C7509B27CDB7D300086C1D /* AppDelegate.swift */; }; 73C7509E27CDB7D300086C1D /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C7509D27CDB7D300086C1D /* SceneDelegate.swift */; }; - 73C750A027CDB7D300086C1D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C7509F27CDB7D300086C1D /* ViewController.swift */; }; 73C750A327CDB7D300086C1D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 73C750A127CDB7D300086C1D /* Main.storyboard */; }; 73C750A527CDB7D400086C1D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 73C750A427CDB7D400086C1D /* Assets.xcassets */; }; 73C750A827CDB7D400086C1D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 73C750A627CDB7D400086C1D /* LaunchScreen.storyboard */; }; 73C750B127CE007300086C1D /* Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B027CE007300086C1D /* Size.swift */; }; 73C750B327CE00FE00086C1D /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B227CE00FE00086C1D /* Point.swift */; }; - 73C750B527CE015800086C1D /* BackgroundColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B427CE015800086C1D /* BackgroundColor.swift */; }; + 73C750B527CE015800086C1D /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B427CE015800086C1D /* Color.swift */; }; 73C750B727CE01CF00086C1D /* Alpha.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B627CE01CF00086C1D /* Alpha.swift */; }; 73C750B927CE033900086C1D /* Rectangle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B827CE033900086C1D /* Rectangle.swift */; }; 73C750BD27CE1D1A00086C1D /* Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750BC27CE1D1A00086C1D /* Factory.swift */; }; @@ -41,20 +49,27 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 736D9D2F27CFB3CA00C040D8 /* FactoryArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryArray.swift; sourceTree = ""; }; + 7348F21A27D7407F00613449 /* Plane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Plane.swift; sourceTree = ""; }; + 735A315F27DEE60900E3E4C0 /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = ""; }; + 735A316227DF802500E3E4C0 /* ControlView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ControlView.xib; sourceTree = ""; }; + 735A316627DF80ED00E3E4C0 /* ControlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = ""; }; + 735A316827DF84A600E3E4C0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 736D9D3827CFBF6C00C040D8 /* DrawingAppTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DrawingAppTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DrawingAppTests.swift; sourceTree = ""; }; + 738A8A8227D5AC1400086985 /* ID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ID.swift; sourceTree = ""; }; + 73966C8727DA10FE006883FF /* Convert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convert.swift; sourceTree = ""; }; + 739B87AC27E3178100346AD9 /* PlaneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaneDelegate.swift; sourceTree = ""; }; + 739B87AE27E31F3C00346AD9 /* ControlViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlViewDelegate.swift; sourceTree = ""; }; 73C7509827CDB7D300086C1D /* DrawingApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DrawingApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 73C7509B27CDB7D300086C1D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 73C7509D27CDB7D300086C1D /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - 73C7509F27CDB7D300086C1D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 73C750A227CDB7D300086C1D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 73C750A427CDB7D400086C1D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 73C750A727CDB7D400086C1D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 73C750A927CDB7D400086C1D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 73C750B027CE007300086C1D /* Size.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Size.swift; sourceTree = ""; }; 73C750B227CE00FE00086C1D /* Point.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Point.swift; sourceTree = ""; }; - 73C750B427CE015800086C1D /* BackgroundColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundColor.swift; sourceTree = ""; }; + 73C750B427CE015800086C1D /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; 73C750B627CE01CF00086C1D /* Alpha.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alpha.swift; sourceTree = ""; }; 73C750B827CE033900086C1D /* Rectangle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rectangle.swift; sourceTree = ""; }; 73C750BC27CE1D1A00086C1D /* Factory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Factory.swift; sourceTree = ""; }; @@ -78,13 +93,21 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 736D9D3127CFB3D600C040D8 /* Factory */ = { + 73312E5127D61A170073D746 /* Base */ = { isa = PBXGroup; children = ( - 736D9D2F27CFB3CA00C040D8 /* FactoryArray.swift */, - 73C750BC27CE1D1A00086C1D /* Factory.swift */, + 73C750A627CDB7D400086C1D /* LaunchScreen.storyboard */, + ); + path = Base; + sourceTree = ""; + }; + 735A316127DF7FFC00E3E4C0 /* View */ = { + isa = PBXGroup; + children = ( + 735A316227DF802500E3E4C0 /* ControlView.xib */, + 735A316627DF80ED00E3E4C0 /* ControlView.swift */, ); - path = Factory; + path = View; sourceTree = ""; }; 736D9D3927CFBF6C00C040D8 /* DrawingAppTests */ = { @@ -95,6 +118,49 @@ path = DrawingAppTests; sourceTree = ""; }; + 738ADB1427DEE16200BE418C /* Resources */ = { + isa = PBXGroup; + children = ( + 73C750A127CDB7D300086C1D /* Main.storyboard */, + 73C750A427CDB7D400086C1D /* Assets.xcassets */, + 73C7509D27CDB7D300086C1D /* SceneDelegate.swift */, + 73C7509B27CDB7D300086C1D /* AppDelegate.swift */, + 73312E5127D61A170073D746 /* Base */, + ); + path = Resources; + sourceTree = ""; + }; + 738ADB1527DEE1A900BE418C /* VC */ = { + isa = PBXGroup; + children = ( + 735A316827DF84A600E3E4C0 /* ViewController.swift */, + ); + path = VC; + sourceTree = ""; + }; + 738ADB1627DEE1B700BE418C /* Sources */ = { + isa = PBXGroup; + children = ( + 73966C8727DA10FE006883FF /* Convert.swift */, + 73C750BC27CE1D1A00086C1D /* Factory.swift */, + 735A315F27DEE60900E3E4C0 /* Log.swift */, + 739B87AB27E3174E00346AD9 /* Delegate */, + 73C750AF27CE003D00086C1D /* Model */, + 735A316127DF7FFC00E3E4C0 /* View */, + 738ADB1527DEE1A900BE418C /* VC */, + ); + path = Sources; + sourceTree = ""; + }; + 739B87AB27E3174E00346AD9 /* Delegate */ = { + isa = PBXGroup; + children = ( + 739B87AC27E3178100346AD9 /* PlaneDelegate.swift */, + 739B87AE27E31F3C00346AD9 /* ControlViewDelegate.swift */, + ); + path = Delegate; + sourceTree = ""; + }; 73C7508F27CDB7D300086C1D = { isa = PBXGroup; children = ( @@ -116,15 +182,9 @@ 73C7509A27CDB7D300086C1D /* DrawingApp */ = { isa = PBXGroup; children = ( - 73C750AF27CE003D00086C1D /* Model */, - 736D9D3127CFB3D600C040D8 /* Factory */, - 73C7509B27CDB7D300086C1D /* AppDelegate.swift */, - 73C7509D27CDB7D300086C1D /* SceneDelegate.swift */, - 73C7509F27CDB7D300086C1D /* ViewController.swift */, - 73C750A127CDB7D300086C1D /* Main.storyboard */, - 73C750A427CDB7D400086C1D /* Assets.xcassets */, - 73C750A627CDB7D400086C1D /* LaunchScreen.storyboard */, 73C750A927CDB7D400086C1D /* Info.plist */, + 738ADB1427DEE16200BE418C /* Resources */, + 738ADB1627DEE1B700BE418C /* Sources */, ); path = DrawingApp; sourceTree = ""; @@ -132,11 +192,13 @@ 73C750AF27CE003D00086C1D /* Model */ = { isa = PBXGroup; children = ( + 7348F21A27D7407F00613449 /* Plane.swift */, 73C750B827CE033900086C1D /* Rectangle.swift */, + 73C750B427CE015800086C1D /* Color.swift */, 73C750B027CE007300086C1D /* Size.swift */, 73C750B227CE00FE00086C1D /* Point.swift */, - 73C750B427CE015800086C1D /* BackgroundColor.swift */, 73C750B627CE01CF00086C1D /* Alpha.swift */, + 738A8A8227D5AC1400086985 /* ID.swift */, ); path = Model; sourceTree = ""; @@ -230,6 +292,7 @@ buildActionMask = 2147483647; files = ( 73C750A827CDB7D400086C1D /* LaunchScreen.storyboard in Resources */, + 735A316327DF802500E3E4C0 /* ControlView.xib in Resources */, 73C750A527CDB7D400086C1D /* Assets.xcassets in Resources */, 73C750A327CDB7D300086C1D /* Main.storyboard in Resources */, ); @@ -242,11 +305,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 73312E5027D618C10073D746 /* ID.swift in Sources */, + 738ADB1227DEDCC300BE418C /* Convert.swift in Sources */, 736D9D4727CFBF9E00C040D8 /* Size.swift in Sources */, 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */, - 736D9D4127CFBF9400C040D8 /* FactoryArray.swift in Sources */, 736D9D4527CFBF9E00C040D8 /* Alpha.swift in Sources */, - 736D9D4427CFBF9E00C040D8 /* BackgroundColor.swift in Sources */, + 736D9D4427CFBF9E00C040D8 /* Color.swift in Sources */, 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */, 736D9D4227CFBF9600C040D8 /* Factory.swift in Sources */, 736D9D4627CFBF9E00C040D8 /* Rectangle.swift in Sources */, @@ -257,16 +321,22 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 735A316927DF84A600E3E4C0 /* ViewController.swift in Sources */, 73C750B127CE007300086C1D /* Size.swift in Sources */, - 73C750B527CE015800086C1D /* BackgroundColor.swift in Sources */, + 735A316027DEE60900E3E4C0 /* Log.swift in Sources */, + 738A8A8327D5AC1400086985 /* ID.swift in Sources */, + 739B87AF27E31F3C00346AD9 /* ControlViewDelegate.swift in Sources */, + 73C750B527CE015800086C1D /* Color.swift in Sources */, 73C750B727CE01CF00086C1D /* Alpha.swift in Sources */, 73C750B327CE00FE00086C1D /* Point.swift in Sources */, - 73C750A027CDB7D300086C1D /* ViewController.swift in Sources */, + 735A316727DF80ED00E3E4C0 /* ControlView.swift in Sources */, + 739B87AD27E3178100346AD9 /* PlaneDelegate.swift in Sources */, 73C750BD27CE1D1A00086C1D /* Factory.swift in Sources */, - 736D9D3027CFB3CA00C040D8 /* FactoryArray.swift in Sources */, + 73966C8827DA10FE006883FF /* Convert.swift in Sources */, 73C7509C27CDB7D300086C1D /* AppDelegate.swift in Sources */, 73C7509E27CDB7D300086C1D /* SceneDelegate.swift in Sources */, 73C750B927CE033900086C1D /* Rectangle.swift in Sources */, + 7348F21B27D7407F00613449 /* Plane.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/DrawingApp/DrawingApp/Base.lproj/Main.storyboard b/DrawingApp/DrawingApp/Base.lproj/Main.storyboard deleted file mode 100644 index cfbdfb90..00000000 --- a/DrawingApp/DrawingApp/Base.lproj/Main.storyboard +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DrawingApp/DrawingApp/Factory/Factory.swift b/DrawingApp/DrawingApp/Factory/Factory.swift deleted file mode 100644 index 7a630888..00000000 --- a/DrawingApp/DrawingApp/Factory/Factory.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// RectangleFactory.swift -// DrawingApp -// -// Created by Jihee hwang on 2022/03/01. -// - -import Foundation - -class Factory { - - func createId() -> String { - let id = "abcdefghijklmnopqrstuvwxyz0123456789" - let length = 9 - var newId = id.createRandomString(length: length) - newId.insert("-", at: id.index(id.startIndex, offsetBy: 3)) - newId.insert("-", at: id.index(id.startIndex, offsetBy: 6)) - - return newId - } - - func createSize() -> Size { - let size = Size(width: 150, height: 120) - return size - } - - func createPoint() -> Point { - let point = Point(x: 0, y: 0) - return point - } - - func createColor() -> BackgroundColor { - let color = BackgroundColor(r: Int.random(in: 0...255), g: Int.random(in: 0...255), b: Int.random(in: 0...255)) - return color - } - - func createAlpha() -> Alpha { - let alpha = Alpha.allCases.shuffled()[0] - return alpha - } - - func createRectangle() -> Rectangle { - let ractangle = Rectangle(id: createId(), size: createSize(), point: createPoint(), backGroundColor: createColor(), alpha: createAlpha()) - return ractangle - } - -} - -extension String { - func createRandomString(length: Int) -> String { - let string = (0.. String { - self.createRectangle() - var rectangleArray = String() - for number in 1...4 { - let tempRactangle = "Rect\(number) \(self.description)\n" - rectangleArray += tempRactangle - } - return rectangleArray - } -} diff --git a/DrawingApp/DrawingApp/Model/Alpha.swift b/DrawingApp/DrawingApp/Model/Alpha.swift deleted file mode 100644 index 5db9660b..00000000 --- a/DrawingApp/DrawingApp/Model/Alpha.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// Alpha.swift -// DrawingApp -// -// Created by Jihee hwang on 2022/03/01. -// - -import Foundation - -enum Alpha: Int, CaseIterable { - case one = 1, two, three, four, five, six, seven, eight, nine, ten -} - -extension Alpha: CustomStringConvertible { - var description: String { - return "\(self.rawValue)" - } -} diff --git a/DrawingApp/DrawingApp/Model/BackgroundColor.swift b/DrawingApp/DrawingApp/Model/BackgroundColor.swift deleted file mode 100644 index 326cc473..00000000 --- a/DrawingApp/DrawingApp/Model/BackgroundColor.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// BackgroundColor.swift -// DrawingApp -// -// Created by Jihee hwang on 2022/03/01. -// - -import Foundation - -class BackgroundColor { - - private let r: Int - private let g: Int - private let b: Int - - init(r: Int, g: Int, b: Int) { - self.r = r - self.g = g - self.b = b - } - -} - -extension BackgroundColor: CustomStringConvertible { - var description: String { - return "R: \(r), G: \(g), b: \(b)" - } -} diff --git a/DrawingApp/DrawingApp/Model/Rectangle.swift b/DrawingApp/DrawingApp/Model/Rectangle.swift deleted file mode 100644 index 58aa87b4..00000000 --- a/DrawingApp/DrawingApp/Model/Rectangle.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// Rectangle.swift -// DrawingApp -// -// Created by Jihee hwang on 2022/03/01. -// - -import Foundation - -class Rectangle: Factory { - - private let id: String - private let size: Size - private let point: Point - private let backGroundColor: BackgroundColor - private let alpha: Alpha - - func RequestCreateRectangle() -> Rectangle { - let ractangle = self.createRectangle() - return ractangle - } - - init(id: String, size: Size, point: Point, backGroundColor: BackgroundColor, alpha: Alpha) { - self.id = id - self.size = size - self.point = point - self.backGroundColor = backGroundColor - self.alpha = alpha - } -} - diff --git a/DrawingApp/DrawingApp/AppDelegate.swift b/DrawingApp/DrawingApp/Resources/AppDelegate.swift similarity index 100% rename from DrawingApp/DrawingApp/AppDelegate.swift rename to DrawingApp/DrawingApp/Resources/AppDelegate.swift diff --git a/DrawingApp/DrawingApp/Assets.xcassets/AccentColor.colorset/Contents.json b/DrawingApp/DrawingApp/Resources/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Assets.xcassets/AccentColor.colorset/Contents.json rename to DrawingApp/DrawingApp/Resources/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/DrawingApp/DrawingApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/DrawingApp/DrawingApp/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Assets.xcassets/AppIcon.appiconset/Contents.json rename to DrawingApp/DrawingApp/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/DrawingApp/DrawingApp/Assets.xcassets/Contents.json b/DrawingApp/DrawingApp/Resources/Assets.xcassets/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Assets.xcassets/Contents.json rename to DrawingApp/DrawingApp/Resources/Assets.xcassets/Contents.json diff --git a/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard b/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard new file mode 100644 index 00000000..c27e3217 --- /dev/null +++ b/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DrawingApp/DrawingApp/Base.lproj/LaunchScreen.storyboard b/DrawingApp/DrawingApp/Resources/Base/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from DrawingApp/DrawingApp/Base.lproj/LaunchScreen.storyboard rename to DrawingApp/DrawingApp/Resources/Base/Base.lproj/LaunchScreen.storyboard diff --git a/DrawingApp/DrawingApp/SceneDelegate.swift b/DrawingApp/DrawingApp/Resources/SceneDelegate.swift similarity index 100% rename from DrawingApp/DrawingApp/SceneDelegate.swift rename to DrawingApp/DrawingApp/Resources/SceneDelegate.swift diff --git a/DrawingApp/DrawingApp/Sources/Convert.swift b/DrawingApp/DrawingApp/Sources/Convert.swift new file mode 100644 index 00000000..35ba26ee --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Convert.swift @@ -0,0 +1,40 @@ + +// DrawingApp +// +// Created by Jihee hwang on 2022/03/10. +// + +import Foundation +import UIKit + +struct Convert { + + static func toUIColor(color: Color, alpha: Alpha) -> UIColor { + return UIColor(red: color.r / 255, green: color.g / 255, blue: color.b / 255, alpha: alpha.value) + } + + static func toCGSize(size: Size) -> CGSize { + return CGSize(width: size.width, height: size.height) + } + + static func toCGPoint(point: Point) -> CGPoint { + return CGPoint(x: point.x, y: point.y) + } + +} + +extension UIColor { + + func toHex() -> String? { + guard let components = cgColor.components, components.count >= 3 else { + return nil // components가 [CGFloat]? 여서 옵셔널 바인딩, 최소 3개 이상 + } + + let r = Float(components[0]) + let g = Float(components[1]) + let b = Float(components[2]) + + return String(format: "%02lX%02lX%02lX", lroundf(r * 255), lroundf(g * 255), lroundf(b * 255)) // + } + +} diff --git a/DrawingApp/DrawingApp/Sources/Delegate/ControlViewDelegate.swift b/DrawingApp/DrawingApp/Sources/Delegate/ControlViewDelegate.swift new file mode 100644 index 00000000..9f001159 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Delegate/ControlViewDelegate.swift @@ -0,0 +1,14 @@ +// +// PanelDelegate.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/17. +// + +import Foundation + +protocol ControlViewDelegate { + func didpressColorChangeButton() + func didMoveSlider() + func didpressCreateRectangleButton() +} diff --git a/DrawingApp/DrawingApp/Sources/Delegate/PlaneDelegate.swift b/DrawingApp/DrawingApp/Sources/Delegate/PlaneDelegate.swift new file mode 100644 index 00000000..f7454979 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Delegate/PlaneDelegate.swift @@ -0,0 +1,13 @@ +// +// PlaneDelegate.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/17. +// + +import Foundation + +protocol PlaneDelegate { + func didCreatRectangel(rectangle: Rectangle) + func didSelect() +} diff --git a/DrawingApp/DrawingApp/Sources/Factory.swift b/DrawingApp/DrawingApp/Sources/Factory.swift new file mode 100644 index 00000000..05f1accd --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Factory.swift @@ -0,0 +1,26 @@ +// +// RectangleFactory.swift. +// DrawingApp +// +// Created by Jihee hwang on 2022/03/01. +// + +import Foundation +import UIKit + +class Factory { + + static func createRectangle() -> Rectangle { + + let size = Size(width: 150, height: 120) + let point = Point(x: round(Double.random(in: 0...700)), + y: round(Double.random(in: 0...700))) + let color = Color(r: round(Double.random(in: 0...255)), + g: round(Double.random(in: 0...255)), + b: round(Double.random(in: 0...255))) + let alpha = Alpha(value: Double(Int.random(in: 1...10))) + + return Rectangle(id: ID.createId(), size: size, point: point, color: color, alpha: alpha) + } + +} diff --git a/DrawingApp/DrawingApp/Sources/Log.swift b/DrawingApp/DrawingApp/Sources/Log.swift new file mode 100644 index 00000000..1789fe93 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Log.swift @@ -0,0 +1,15 @@ +// +// Log.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/14. +// + +import Foundation +import OSLog + +extension OSLog { + static func log(message: String) { + os_log("\(message)") + } +} diff --git a/DrawingApp/DrawingApp/Sources/Model/Alpha.swift b/DrawingApp/DrawingApp/Sources/Model/Alpha.swift new file mode 100644 index 00000000..3dfb3e74 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Model/Alpha.swift @@ -0,0 +1,29 @@ +// +// Alpha.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/01. +// + +import Foundation + +struct Alpha { + + static let min = 1.0 + static let max = 10.0 + + private(set) var value: Double + + init(value: Double) { + self.value = value / 10 + + if value < Alpha.min { self.value = Alpha.min } + if value > Alpha.max { self.value = Alpha.max } + } +} + +extension Alpha: CustomStringConvertible { + var description: String { + return "Alpha: \(value)" + } +} diff --git a/DrawingApp/DrawingApp/Sources/Model/Color.swift b/DrawingApp/DrawingApp/Sources/Model/Color.swift new file mode 100644 index 00000000..4c4f1f10 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Model/Color.swift @@ -0,0 +1,34 @@ +// +// BackgroundColor.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/01. +// + +import Foundation + +class Color { + static let min = 0.0 + static let max = 255.0 + + private(set) var r: Double + private(set) var g: Double + private(set) var b: Double + + init(r: Double, g: Double, b: Double) { + self.r = r + self.g = g + self.b = b + + if r <= Color.min { self.r = Color.min }; if r >= Color.max { self.r = Color.max } + if g <= Color.min { self.g = Color.min }; if g >= Color.max { self.g = Color.max } + if b <= Color.min { self.b = Color.min }; if b >= Color.max { self.b = Color.max } + } + +} + +extension Color: CustomStringConvertible { + var description: String { + return "R: \(r), G: \(g), b: \(b)" + } +} diff --git a/DrawingApp/DrawingApp/Sources/Model/ID.swift b/DrawingApp/DrawingApp/Sources/Model/ID.swift new file mode 100644 index 00000000..87aa754e --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Model/ID.swift @@ -0,0 +1,40 @@ +// +// ID.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/07. +// + +import Foundation + +class ID { + static func createId() -> String { + let id = "abcdefghijklmnopqrstuvwxyz0123456789" + let length = 9 + var count = 0 + var newId = "" + + for i in 0.. Bool { + return lhs.description == rhs.description + } +} diff --git a/DrawingApp/DrawingApp/Sources/Model/Plane.swift b/DrawingApp/DrawingApp/Sources/Model/Plane.swift new file mode 100644 index 00000000..6121d351 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Model/Plane.swift @@ -0,0 +1,46 @@ +// +// Plane.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/08. +// + +import Foundation + +class Plane { + + private var rectangles: [Rectangle] = [] + private var selctRectangle: Rectangle? + var delegate: PlaneDelegate? + + subscript(index: Int) -> Rectangle { + return rectangles[index] + } + + func createRectangle() { + let add = Factory.createRectangle() + rectangles.append(add) + + delegate?.didCreatRectangel(rectangle: add) + } + + func countingRectangle() -> Int { + if rectangles.isEmpty { + print("생성된 사각형이 없습니다.") + return 0 + } else { + return rectangles.count + } + } + + func isExist(point: Point) -> Rectangle? { + for rectangle in rectangles { + if rectangle.point.x == point.x || rectangle.point.y == point.y { + selctRectangle = rectangle + return selctRectangle + } + } + return nil + } + +} diff --git a/DrawingApp/DrawingApp/Model/Point.swift b/DrawingApp/DrawingApp/Sources/Model/Point.swift similarity index 83% rename from DrawingApp/DrawingApp/Model/Point.swift rename to DrawingApp/DrawingApp/Sources/Model/Point.swift index d119769d..681f00de 100644 --- a/DrawingApp/DrawingApp/Model/Point.swift +++ b/DrawingApp/DrawingApp/Sources/Model/Point.swift @@ -9,8 +9,8 @@ import Foundation class Point { - private let x: Double - private let y: Double + private(set) var x: Double + private(set) var y: Double init(x: Double, y: Double) { self.x = x diff --git a/DrawingApp/DrawingApp/Sources/Model/Rectangle.swift b/DrawingApp/DrawingApp/Sources/Model/Rectangle.swift new file mode 100644 index 00000000..c117a26e --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Model/Rectangle.swift @@ -0,0 +1,41 @@ +// +// Rectangle.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/01. +// + +import Foundation + +class Rectangle { + + private let id: String + private(set) var size: Size + private(set) var point: Point + private(set) var color: Color + private(set) var alpha: Alpha + + init(id: String, size: Size, point: Point, color: Color, alpha: Alpha) { + self.id = id + self.size = size + self.point = point + self.color = color + self.alpha = alpha + } +} + +extension Rectangle: CustomStringConvertible { + var description: String { + return "(\(id)), \(size), \(point), \(color), \(alpha)" + } +} + +extension Rectangle: Equatable, Hashable { + static func == (lhs: Rectangle, rhs: Rectangle) -> Bool { + return lhs.id == rhs.id + } + + func hash(into hasher: inout Hasher) { + hasher.combine(id) + } +} diff --git a/DrawingApp/DrawingApp/Model/Size.swift b/DrawingApp/DrawingApp/Sources/Model/Size.swift similarity index 83% rename from DrawingApp/DrawingApp/Model/Size.swift rename to DrawingApp/DrawingApp/Sources/Model/Size.swift index 23908847..9115616e 100644 --- a/DrawingApp/DrawingApp/Model/Size.swift +++ b/DrawingApp/DrawingApp/Sources/Model/Size.swift @@ -9,8 +9,8 @@ import Foundation class Size { - private let width: Double - private let height: Double + private(set) var width: Double + private(set) var height: Double init(width: Double, height: Double) { self.width = width diff --git a/DrawingApp/DrawingApp/Sources/PlaneDelegate.swift b/DrawingApp/DrawingApp/Sources/PlaneDelegate.swift new file mode 100644 index 00000000..5dda9f3a --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/PlaneDelegate.swift @@ -0,0 +1,13 @@ +// +// PlaneDelegate.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/15. +// + +import Foundation + +protocol PlaneDelegate { + func didCreateRectengle() + func didSelect() +} diff --git a/DrawingApp/DrawingApp/Sources/VC/ViewController.swift b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift new file mode 100644 index 00000000..7d2f9d88 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift @@ -0,0 +1,67 @@ +// +// ViewController.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/01. +// + +import UIKit +import OSLog + +class ViewController: UIViewController { + + @IBOutlet weak var canvas: UIView! + @IBOutlet weak var controlView: ControlView! + + private var plane = Plane() + + private var rectengles = [Rectangle: UIView]() // 이 안에 Rectangle 값이랑, 그에 맞는 view를 넣어 + + override func viewDidLoad() { + super.viewDidLoad() + + self.view.addSubview(canvas) + + plane.delegate = self + controlView.delegate = self + + } + +} + +extension ViewController: ControlViewDelegate { + + func didpressColorChangeButton() { + print("") + } + + func didMoveSlider() { + print("") + + } + + func didpressCreateRectangleButton() { + plane.createRectangle() + } + +} + +extension ViewController: PlaneDelegate { + + func didCreatRectangel(rectangle: Rectangle) { + let view = UIView.init(frame: CGRect(x: rectangle.point.x, y: rectangle.point.y, width: rectangle.size.width, height: rectangle.size.height)) + + view.backgroundColor = Convert.toUIColor(color: rectangle.color, alpha: rectangle.alpha) + + rectengles[rectangle] = view + self.canvas.addSubview(view) + + print(rectangle.point) + } + + func didSelect() { + print("") + } + + +} diff --git a/DrawingApp/DrawingApp/Sources/View/ControlView.swift b/DrawingApp/DrawingApp/Sources/View/ControlView.swift new file mode 100644 index 00000000..ab190fba --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/View/ControlView.swift @@ -0,0 +1,45 @@ +// +// RightView.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/14. +// + +import UIKit + +class ControlView: UIView { + + var delegate: ControlViewDelegate? + + required init?(coder: NSCoder) { + super.init(coder: coder) + self.loadXib() + } + + override init(frame: CGRect) { + super.init(frame: frame) + self.loadXib() + } + + private func loadXib() { + let identifier = String(describing: type(of: self)) + let nibs = Bundle.main.loadNibNamed(identifier, owner: self, options: nil) + guard let inputView = nibs?.first as? UIView else { + return + } + inputView.frame = self.bounds + self.addSubview(inputView) + } + + @IBAction func backgroundColor(_ sender: UIButton) { + delegate?.didpressColorChangeButton() + } + + @IBAction func changAlpha(_ sender: Any) { + delegate?.didMoveSlider() + } + + @IBAction func createRectangle(_ sender: UIButton) { + delegate?.didpressCreateRectangleButton() + } +} diff --git a/DrawingApp/DrawingApp/Sources/View/ControlView.xib b/DrawingApp/DrawingApp/Sources/View/ControlView.xib new file mode 100644 index 00000000..3bf13274 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/View/ControlView.xib @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DrawingApp/DrawingApp/ViewController.swift b/DrawingApp/DrawingApp/ViewController.swift deleted file mode 100644 index f341c35e..00000000 --- a/DrawingApp/DrawingApp/ViewController.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// ViewController.swift -// DrawingApp -// -// Created by Jihee hwang on 2022/03/01. -// - -import UIKit -import OSLog - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - } - - @IBAction func createRectangle(_ sender: UIButton) { - let logger = Logger() - let factory = FactoryArray() - - logger.info("\(factory.createRectanleArray())") - } - -} - diff --git a/DrawingApp/DrawingAppTests/DrawingAppTests.swift b/DrawingApp/DrawingAppTests/DrawingAppTests.swift index 03582fab..844195f2 100644 --- a/DrawingApp/DrawingAppTests/DrawingAppTests.swift +++ b/DrawingApp/DrawingAppTests/DrawingAppTests.swift @@ -10,18 +10,25 @@ import XCTest class DrawingAppTests: XCTestCase { - func testId() { - let factory = Factory() - let id = factory.createId().count - - XCTAssertEqual(11, 11) + func testCreateID() { + let count = ID.createId().count + XCTAssertEqual(count, 11) } - func testFactoryArray() { - let factoryArray = FactoryArray() - let array = factoryArray.createRectanleArray().count + func testCountingRectangle() { + let plane = Plane() + plane.addRectangle() + let count = plane.countingRectangle() - XCTAssertEqual(4, 4) + XCTAssertEqual(count, 1) } + func testExist() { + let plane = Plane() + let rectangle = plane.addRectangle() + let point = rectangle.point + let exist = plane.isExist(point: point) + + XCTAssertEqual(rectangle, exist) + } } diff --git a/README.md b/README.md index e6b8cb78..9df6dfb4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # swift-drawingapp -3번째 미션 - iOS 터치 드로잉 앱 +#### 3번째 미션 - iOS 터치 드로잉 앱 + +--- + +
+ +## Step 1. 아이패드 앱 프로젝트 + + +### ✅ 작업 목록 + +- [x] 속성 별 객체 생성 +- [x] 형식에 맞춰 랜덤 생성 +- [x] 출력을 위한 `CustomStringConvertible` 프로토콜 추가 +- [x] 팩토리 구현 +- [x] 로그함수로 출력 + +
+ +### ⚒ 작업 진행 순서 + +1. 속성별 객체 생성 +2. Rectangle 객체 생성 후, Factory 객체 생성 +3. Factory 객체에서 Rectangle 생성 +4. UIButton 생성 후, `os_log` 사용으로 결과물 출력 (버튼과 `Logger` 연결) +5. UnitTest 추가 및 실행 + +
+ +#### • 결과물 +스크린샷 2022-03-03 오후 4 31 49