From dbca7c02a83c236600f864c3594c8125ce7a2ee0 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Mon, 7 Mar 2022 11:22:03 +0900 Subject: [PATCH 01/15] Fix : CreateId in Factory --- DrawingApp/DrawingApp/Factory/Factory.swift | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/DrawingApp/DrawingApp/Factory/Factory.swift b/DrawingApp/DrawingApp/Factory/Factory.swift index 7a630888..1b77823c 100644 --- a/DrawingApp/DrawingApp/Factory/Factory.swift +++ b/DrawingApp/DrawingApp/Factory/Factory.swift @@ -12,9 +12,17 @@ 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)) + var count = 0 + var newId = "" + + for i in 0.. String { - let string = (0.. Date: Mon, 7 Mar 2022 15:30:48 +0900 Subject: [PATCH 02/15] [ Complete ] All feedback --- .../DrawingApp.xcodeproj/project.pbxproj | 10 ++-- DrawingApp/DrawingApp/Factory/Factory.swift | 58 +++++-------------- .../DrawingApp/Factory/FactoryArray.swift | 21 ------- DrawingApp/DrawingApp/Model/Alpha.swift | 4 +- .../DrawingApp/Model/BackgroundColor.swift | 3 +- DrawingApp/DrawingApp/Model/ID.swift | 34 +++++++++++ DrawingApp/DrawingApp/Model/Rectangle.swift | 12 ++-- DrawingApp/DrawingApp/ViewController.swift | 6 +- 8 files changed, 64 insertions(+), 84 deletions(-) delete mode 100644 DrawingApp/DrawingApp/Factory/FactoryArray.swift create mode 100644 DrawingApp/DrawingApp/Model/ID.swift diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index 5f3b18f9..e31c1805 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -7,15 +7,14 @@ objects = { /* Begin PBXBuildFile section */ - 736D9D3027CFB3CA00C040D8 /* FactoryArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D2F27CFB3CA00C040D8 /* FactoryArray.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 */; }; 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 */; }; 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 */; }; @@ -41,9 +40,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 736D9D2F27CFB3CA00C040D8 /* FactoryArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryArray.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 = ""; }; 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 = ""; }; @@ -81,7 +80,6 @@ 736D9D3127CFB3D600C040D8 /* Factory */ = { isa = PBXGroup; children = ( - 736D9D2F27CFB3CA00C040D8 /* FactoryArray.swift */, 73C750BC27CE1D1A00086C1D /* Factory.swift */, ); path = Factory; @@ -137,6 +135,7 @@ 73C750B227CE00FE00086C1D /* Point.swift */, 73C750B427CE015800086C1D /* BackgroundColor.swift */, 73C750B627CE01CF00086C1D /* Alpha.swift */, + 738A8A8227D5AC1400086985 /* ID.swift */, ); path = Model; sourceTree = ""; @@ -244,7 +243,6 @@ files = ( 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 */, 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */, @@ -258,12 +256,12 @@ buildActionMask = 2147483647; files = ( 73C750B127CE007300086C1D /* Size.swift in Sources */, + 738A8A8327D5AC1400086985 /* ID.swift in Sources */, 73C750B527CE015800086C1D /* BackgroundColor.swift in Sources */, 73C750B727CE01CF00086C1D /* Alpha.swift in Sources */, 73C750B327CE00FE00086C1D /* Point.swift in Sources */, 73C750A027CDB7D300086C1D /* ViewController.swift in Sources */, 73C750BD27CE1D1A00086C1D /* Factory.swift in Sources */, - 736D9D3027CFB3CA00C040D8 /* FactoryArray.swift in Sources */, 73C7509C27CDB7D300086C1D /* AppDelegate.swift in Sources */, 73C7509E27CDB7D300086C1D /* SceneDelegate.swift in Sources */, 73C750B927CE033900086C1D /* Rectangle.swift in Sources */, diff --git a/DrawingApp/DrawingApp/Factory/Factory.swift b/DrawingApp/DrawingApp/Factory/Factory.swift index 1b77823c..1ac89131 100644 --- a/DrawingApp/DrawingApp/Factory/Factory.swift +++ b/DrawingApp/DrawingApp/Factory/Factory.swift @@ -6,56 +6,24 @@ // import Foundation +import UIKit class Factory { - - func createId() -> String { - let id = "abcdefghijklmnopqrstuvwxyz0123456789" - let length = 9 - var count = 0 - var newId = "" - for i in 0.. Rectangle { - return newId - } - - func createSize() -> Size { + let DeviceWidth = UIScreen.main.bounds.size.width + let DeviceHeight = UIScreen.main.bounds.size.height + 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 + let point = Point(x: Double(Int.random(in: 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 index 5db9660b..853cda9d 100644 --- a/DrawingApp/DrawingApp/Model/Alpha.swift +++ b/DrawingApp/DrawingApp/Model/Alpha.swift @@ -7,12 +7,12 @@ import Foundation -enum Alpha: Int, CaseIterable { +enum Alpha: Double, CaseIterable { case one = 1, two, three, four, five, six, seven, eight, nine, ten } extension Alpha: CustomStringConvertible { var description: String { - return "\(self.rawValue)" + return "Alpha: \(self.rawValue / 10 )" } } diff --git a/DrawingApp/DrawingApp/Model/BackgroundColor.swift b/DrawingApp/DrawingApp/Model/BackgroundColor.swift index 326cc473..99b47436 100644 --- a/DrawingApp/DrawingApp/Model/BackgroundColor.swift +++ b/DrawingApp/DrawingApp/Model/BackgroundColor.swift @@ -9,7 +9,7 @@ import Foundation class BackgroundColor { - private let r: Int + private var r: Int private let g: Int private let b: Int @@ -18,7 +18,6 @@ class BackgroundColor { self.g = g self.b = b } - } extension BackgroundColor: CustomStringConvertible { diff --git a/DrawingApp/DrawingApp/Model/ID.swift b/DrawingApp/DrawingApp/Model/ID.swift new file mode 100644 index 00000000..38b80a53 --- /dev/null +++ b/DrawingApp/DrawingApp/Model/ID.swift @@ -0,0 +1,34 @@ +// +// 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.. Rectangle { - let ractangle = self.createRectangle() - return ractangle - } - init(id: String, size: Size, point: Point, backGroundColor: BackgroundColor, alpha: Alpha) { self.id = id self.size = size @@ -29,3 +24,8 @@ class Rectangle: Factory { } } +extension Rectangle: CustomStringConvertible { + var description: String { + return "(\(id)), \(point), \(point), \(backGroundColor), \(alpha)" + } +} diff --git a/DrawingApp/DrawingApp/ViewController.swift b/DrawingApp/DrawingApp/ViewController.swift index f341c35e..52751a33 100644 --- a/DrawingApp/DrawingApp/ViewController.swift +++ b/DrawingApp/DrawingApp/ViewController.swift @@ -16,9 +16,11 @@ class ViewController: UIViewController { @IBAction func createRectangle(_ sender: UIButton) { let logger = Logger() - let factory = FactoryArray() + let factory = Factory() - logger.info("\(factory.createRectanleArray())") + for makeCount in 1...4 { + logger.info("Rect\(makeCount) \(factory.createRectangle())") + } } } From 32f776f1c4f39a8013a65d21a56bf27bae4ae3ae Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Mon, 7 Mar 2022 16:45:12 +0900 Subject: [PATCH 03/15] Edit : ReadMe --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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 From ed32ac5e512ea197635e559b13784568990fa126 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Mon, 7 Mar 2022 19:44:25 +0900 Subject: [PATCH 04/15] [ Fix ] UnitTest Change the test code by changing the code --- DrawingApp/DrawingApp.xcodeproj/project.pbxproj | 2 ++ DrawingApp/DrawingAppTests/DrawingAppTests.swift | 16 +++------------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index e31c1805..9d3a0630 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 73312E5027D618C10073D746 /* ID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738A8A8227D5AC1400086985 /* ID.swift */; }; 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */; }; 736D9D4227CFBF9600C040D8 /* Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750BC27CE1D1A00086C1D /* Factory.swift */; }; 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B227CE00FE00086C1D /* Point.swift */; }; @@ -241,6 +242,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 73312E5027D618C10073D746 /* ID.swift in Sources */, 736D9D4727CFBF9E00C040D8 /* Size.swift in Sources */, 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */, 736D9D4527CFBF9E00C040D8 /* Alpha.swift in Sources */, diff --git a/DrawingApp/DrawingAppTests/DrawingAppTests.swift b/DrawingApp/DrawingAppTests/DrawingAppTests.swift index 03582fab..9c42948f 100644 --- a/DrawingApp/DrawingAppTests/DrawingAppTests.swift +++ b/DrawingApp/DrawingAppTests/DrawingAppTests.swift @@ -10,18 +10,8 @@ import XCTest class DrawingAppTests: XCTestCase { - func testId() { - let factory = Factory() - let id = factory.createId().count - - XCTAssertEqual(11, 11) + func createID() { + let count = ID.createId().count + XCTAssertEqual(count, 11) } - - func testFactoryArray() { - let factoryArray = FactoryArray() - let array = factoryArray.createRectanleArray().count - - XCTAssertEqual(4, 4) - } - } From 632ccccd82e1789d6a042ad344d92082be7d7f12 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Tue, 8 Mar 2022 22:48:15 +0900 Subject: [PATCH 05/15] [ Create ] Object Plane --- .../AccentColor.colorset/Contents.json | 0 .../AppIcon.appiconset/Contents.json | 0 .../{ => Base}/Assets.xcassets/Contents.json | 0 .../Base.lproj/LaunchScreen.storyboard | 0 .../{ => Base}/Base.lproj/Main.storyboard | 0 DrawingApp/DrawingApp/Model/Plane.swift | 41 +++++++++++++++++++ 6 files changed, 41 insertions(+) rename DrawingApp/DrawingApp/{ => Base}/Assets.xcassets/AccentColor.colorset/Contents.json (100%) rename DrawingApp/DrawingApp/{ => Base}/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename DrawingApp/DrawingApp/{ => Base}/Assets.xcassets/Contents.json (100%) rename DrawingApp/DrawingApp/{ => Base}/Base.lproj/LaunchScreen.storyboard (100%) rename DrawingApp/DrawingApp/{ => Base}/Base.lproj/Main.storyboard (100%) create mode 100644 DrawingApp/DrawingApp/Model/Plane.swift diff --git a/DrawingApp/DrawingApp/Assets.xcassets/AccentColor.colorset/Contents.json b/DrawingApp/DrawingApp/Base/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Assets.xcassets/AccentColor.colorset/Contents.json rename to DrawingApp/DrawingApp/Base/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/DrawingApp/DrawingApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/DrawingApp/DrawingApp/Base/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Assets.xcassets/AppIcon.appiconset/Contents.json rename to DrawingApp/DrawingApp/Base/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/DrawingApp/DrawingApp/Assets.xcassets/Contents.json b/DrawingApp/DrawingApp/Base/Assets.xcassets/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Assets.xcassets/Contents.json rename to DrawingApp/DrawingApp/Base/Assets.xcassets/Contents.json diff --git a/DrawingApp/DrawingApp/Base.lproj/LaunchScreen.storyboard b/DrawingApp/DrawingApp/Base/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from DrawingApp/DrawingApp/Base.lproj/LaunchScreen.storyboard rename to DrawingApp/DrawingApp/Base/Base.lproj/LaunchScreen.storyboard diff --git a/DrawingApp/DrawingApp/Base.lproj/Main.storyboard b/DrawingApp/DrawingApp/Base/Base.lproj/Main.storyboard similarity index 100% rename from DrawingApp/DrawingApp/Base.lproj/Main.storyboard rename to DrawingApp/DrawingApp/Base/Base.lproj/Main.storyboard diff --git a/DrawingApp/DrawingApp/Model/Plane.swift b/DrawingApp/DrawingApp/Model/Plane.swift new file mode 100644 index 00000000..8ceda783 --- /dev/null +++ b/DrawingApp/DrawingApp/Model/Plane.swift @@ -0,0 +1,41 @@ +// +// Plane.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/08. +// + +import Foundation +import UIKit + +class Plane { + + private var rectangles: [Rectangle] = [] + + subscript(index: Int) -> Rectangle { + return rectangles[index] + } + + func addRectangle() { + rectangles.append(Factory.createRectangle()) + } + + func countingRectangle() -> Int { + if rectangles.isEmpty { + print("생성된 사각형이 없습니다.") + return 0 + } else { + return rectangles.count + } + } + + func isExist(point: Point) -> Bool { + for rectangle in rectangles { + if rectangle.point.x== point.x || rectangle.point.y == point.y { + return true + } + + } + } + +} From da73c5fb2b0a04745adee8559f762f6e96c87af5 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Wed, 9 Mar 2022 22:59:03 +0900 Subject: [PATCH 06/15] [ Create ] Plane Unit Test --- .../DrawingApp.xcodeproj/project.pbxproj | 18 +++++++++++++++--- DrawingApp/DrawingApp/Factory/Factory.swift | 4 ++-- DrawingApp/DrawingApp/Model/ID.swift | 6 ++++++ DrawingApp/DrawingApp/Model/Plane.swift | 16 ++++++++++------ DrawingApp/DrawingApp/Model/Point.swift | 4 ++-- DrawingApp/DrawingApp/Model/Rectangle.swift | 8 +++++++- DrawingApp/DrawingApp/ViewController.swift | 3 +-- .../DrawingAppTests/DrawingAppTests.swift | 19 ++++++++++++++++++- 8 files changed, 61 insertions(+), 17 deletions(-) diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index 9d3a0630..c98e7e33 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 73312E5027D618C10073D746 /* ID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738A8A8227D5AC1400086985 /* ID.swift */; }; + 7348F21B27D7407F00613449 /* Plane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7348F21A27D7407F00613449 /* Plane.swift */; }; 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */; }; 736D9D4227CFBF9600C040D8 /* Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750BC27CE1D1A00086C1D /* Factory.swift */; }; 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B227CE00FE00086C1D /* Point.swift */; }; @@ -41,6 +42,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7348F21A27D7407F00613449 /* Plane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Plane.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 = ""; }; @@ -78,6 +80,16 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 73312E5127D61A170073D746 /* Base */ = { + isa = PBXGroup; + children = ( + 73C750A127CDB7D300086C1D /* Main.storyboard */, + 73C750A627CDB7D400086C1D /* LaunchScreen.storyboard */, + 73C750A427CDB7D400086C1D /* Assets.xcassets */, + ); + path = Base; + sourceTree = ""; + }; 736D9D3127CFB3D600C040D8 /* Factory */ = { isa = PBXGroup; children = ( @@ -115,14 +127,12 @@ 73C7509A27CDB7D300086C1D /* DrawingApp */ = { isa = PBXGroup; children = ( + 73312E5127D61A170073D746 /* Base */, 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 */, ); path = DrawingApp; @@ -131,6 +141,7 @@ 73C750AF27CE003D00086C1D /* Model */ = { isa = PBXGroup; children = ( + 7348F21A27D7407F00613449 /* Plane.swift */, 73C750B827CE033900086C1D /* Rectangle.swift */, 73C750B027CE007300086C1D /* Size.swift */, 73C750B227CE00FE00086C1D /* Point.swift */, @@ -267,6 +278,7 @@ 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/Factory/Factory.swift b/DrawingApp/DrawingApp/Factory/Factory.swift index 1ac89131..d5071714 100644 --- a/DrawingApp/DrawingApp/Factory/Factory.swift +++ b/DrawingApp/DrawingApp/Factory/Factory.swift @@ -1,5 +1,5 @@ // -// RectangleFactory.swift +// RectangleFactory.swift. // DrawingApp // // Created by Jihee hwang on 2022/03/01. @@ -10,7 +10,7 @@ import UIKit class Factory { - func createRectangle() -> Rectangle { + static func createRectangle() -> Rectangle { let DeviceWidth = UIScreen.main.bounds.size.width let DeviceHeight = UIScreen.main.bounds.size.height diff --git a/DrawingApp/DrawingApp/Model/ID.swift b/DrawingApp/DrawingApp/Model/ID.swift index 38b80a53..87aa754e 100644 --- a/DrawingApp/DrawingApp/Model/ID.swift +++ b/DrawingApp/DrawingApp/Model/ID.swift @@ -32,3 +32,9 @@ extension ID: CustomStringConvertible { return ID.createId() } } + +extension ID: Equatable { + static func == (lhs: ID, rhs: ID) -> Bool { + return lhs.description == rhs.description + } +} diff --git a/DrawingApp/DrawingApp/Model/Plane.swift b/DrawingApp/DrawingApp/Model/Plane.swift index 8ceda783..57562589 100644 --- a/DrawingApp/DrawingApp/Model/Plane.swift +++ b/DrawingApp/DrawingApp/Model/Plane.swift @@ -11,13 +11,16 @@ import UIKit class Plane { private var rectangles: [Rectangle] = [] + private var selctRectangle: Rectangle? subscript(index: Int) -> Rectangle { return rectangles[index] } - func addRectangle() { - rectangles.append(Factory.createRectangle()) + func addRectangle() -> Rectangle { + let add = Factory.createRectangle() + rectangles.append(add) + return add } func countingRectangle() -> Int { @@ -29,13 +32,14 @@ class Plane { } } - func isExist(point: Point) -> Bool { + func isExist(point: Point) -> Rectangle? { for rectangle in rectangles { - if rectangle.point.x== point.x || rectangle.point.y == point.y { - return true + 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/Model/Point.swift index d119769d..004f9fa0 100644 --- a/DrawingApp/DrawingApp/Model/Point.swift +++ b/DrawingApp/DrawingApp/Model/Point.swift @@ -9,8 +9,8 @@ import Foundation class Point { - private let x: Double - private let y: Double + let x: Double + let y: Double init(x: Double, y: Double) { self.x = x diff --git a/DrawingApp/DrawingApp/Model/Rectangle.swift b/DrawingApp/DrawingApp/Model/Rectangle.swift index e01cf381..5764949a 100644 --- a/DrawingApp/DrawingApp/Model/Rectangle.swift +++ b/DrawingApp/DrawingApp/Model/Rectangle.swift @@ -11,7 +11,7 @@ class Rectangle { private let id: String private let size: Size - private let point: Point + let point: Point private let backGroundColor: BackgroundColor private let alpha: Alpha @@ -29,3 +29,9 @@ extension Rectangle: CustomStringConvertible { return "(\(id)), \(point), \(point), \(backGroundColor), \(alpha)" } } + +extension Rectangle: Equatable { + static func == (lhs: Rectangle, rhs: Rectangle) -> Bool { + return lhs.id == rhs.id + } +} diff --git a/DrawingApp/DrawingApp/ViewController.swift b/DrawingApp/DrawingApp/ViewController.swift index 52751a33..73654416 100644 --- a/DrawingApp/DrawingApp/ViewController.swift +++ b/DrawingApp/DrawingApp/ViewController.swift @@ -16,10 +16,9 @@ class ViewController: UIViewController { @IBAction func createRectangle(_ sender: UIButton) { let logger = Logger() - let factory = Factory() for makeCount in 1...4 { - logger.info("Rect\(makeCount) \(factory.createRectangle())") + logger.info("Rect\(makeCount) \(Factory.createRectangle())") } } diff --git a/DrawingApp/DrawingAppTests/DrawingAppTests.swift b/DrawingApp/DrawingAppTests/DrawingAppTests.swift index 9c42948f..844195f2 100644 --- a/DrawingApp/DrawingAppTests/DrawingAppTests.swift +++ b/DrawingApp/DrawingAppTests/DrawingAppTests.swift @@ -10,8 +10,25 @@ import XCTest class DrawingAppTests: XCTestCase { - func createID() { + func testCreateID() { let count = ID.createId().count XCTAssertEqual(count, 11) } + + func testCountingRectangle() { + let plane = Plane() + plane.addRectangle() + let count = plane.countingRectangle() + + 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) + } } From 5e2544a7e04989b2ddb387a84d0b199396e4b5c4 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Thu, 10 Mar 2022 20:17:52 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[=20Fix=20]=20Color=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B2=94=EC=9C=84=20=EC=A0=9C=ED=95=9C=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(Alpha=EB=8F=84=20=EC=A0=9C=ED=95=9C=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingApp.xcodeproj/project.pbxproj | 16 ++++--- DrawingApp/DrawingApp/Factory/Factory.swift | 21 +++++---- DrawingApp/DrawingApp/Model/Alpha.swift | 26 +++++++++-- .../DrawingApp/Model/BackgroundColor.swift | 27 ------------ DrawingApp/DrawingApp/Model/Color.swift | 44 +++++++++++++++++++ DrawingApp/DrawingApp/Model/Plane.swift | 1 - DrawingApp/DrawingApp/Model/Point.swift | 4 +- DrawingApp/DrawingApp/Model/Rectangle.swift | 14 +++--- DrawingApp/DrawingApp/Model/Size.swift | 4 +- DrawingApp/DrawingApp/Model/Util.swift | 15 +++++++ DrawingApp/DrawingApp/ViewController.swift | 11 +++-- 11 files changed, 123 insertions(+), 60 deletions(-) delete mode 100644 DrawingApp/DrawingApp/Model/BackgroundColor.swift create mode 100644 DrawingApp/DrawingApp/Model/Color.swift create mode 100644 DrawingApp/DrawingApp/Model/Util.swift diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index c98e7e33..7a96291b 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -12,11 +12,12 @@ 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.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 */; }; + 73966C8827DA10FE006883FF /* Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73966C8727DA10FE006883FF /* Util.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 */; }; @@ -25,7 +26,7 @@ 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 */; }; @@ -46,6 +47,7 @@ 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 /* Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Util.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 = ""; }; @@ -56,7 +58,7 @@ 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 = ""; }; @@ -141,11 +143,12 @@ 73C750AF27CE003D00086C1D /* Model */ = { isa = PBXGroup; children = ( + 73966C8727DA10FE006883FF /* Util.swift */, 7348F21A27D7407F00613449 /* Plane.swift */, 73C750B827CE033900086C1D /* Rectangle.swift */, 73C750B027CE007300086C1D /* Size.swift */, 73C750B227CE00FE00086C1D /* Point.swift */, - 73C750B427CE015800086C1D /* BackgroundColor.swift */, + 73C750B427CE015800086C1D /* Color.swift */, 73C750B627CE01CF00086C1D /* Alpha.swift */, 738A8A8227D5AC1400086985 /* ID.swift */, ); @@ -257,7 +260,7 @@ 736D9D4727CFBF9E00C040D8 /* Size.swift in Sources */, 736D9D4327CFBF9E00C040D8 /* Point.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 */, @@ -270,11 +273,12 @@ files = ( 73C750B127CE007300086C1D /* Size.swift in Sources */, 738A8A8327D5AC1400086985 /* ID.swift in Sources */, - 73C750B527CE015800086C1D /* BackgroundColor.swift in Sources */, + 73C750B527CE015800086C1D /* Color.swift in Sources */, 73C750B727CE01CF00086C1D /* Alpha.swift in Sources */, 73C750B327CE00FE00086C1D /* Point.swift in Sources */, 73C750A027CDB7D300086C1D /* ViewController.swift in Sources */, 73C750BD27CE1D1A00086C1D /* Factory.swift in Sources */, + 73966C8827DA10FE006883FF /* Util.swift in Sources */, 73C7509C27CDB7D300086C1D /* AppDelegate.swift in Sources */, 73C7509E27CDB7D300086C1D /* SceneDelegate.swift in Sources */, 73C750B927CE033900086C1D /* Rectangle.swift in Sources */, diff --git a/DrawingApp/DrawingApp/Factory/Factory.swift b/DrawingApp/DrawingApp/Factory/Factory.swift index d5071714..f0651201 100644 --- a/DrawingApp/DrawingApp/Factory/Factory.swift +++ b/DrawingApp/DrawingApp/Factory/Factory.swift @@ -12,18 +12,21 @@ class Factory { static func createRectangle() -> Rectangle { - let DeviceWidth = UIScreen.main.bounds.size.width - let DeviceHeight = UIScreen.main.bounds.size.height + let marginX = 130.0 + let marginY = 160.0 + + let DeviceWidth = UIScreen.main.bounds.size.width - marginX + let DeviceHeight = UIScreen.main.bounds.size.height - marginY let size = Size(width: 150, height: 120) - let point = Point(x: Double(Int.random(in: 0.. Double { + if number < Alpha.min { + return Alpha.min + } else if number > Alpha.max { + return Alpha.max + } else { + return number + } + } + + init(alpha: Double) { + self.value = alpha / 10 + } } extension Alpha: CustomStringConvertible { var description: String { - return "Alpha: \(self.rawValue / 10 )" + return "Alpha: \(value)" } } diff --git a/DrawingApp/DrawingApp/Model/BackgroundColor.swift b/DrawingApp/DrawingApp/Model/BackgroundColor.swift deleted file mode 100644 index 99b47436..00000000 --- a/DrawingApp/DrawingApp/Model/BackgroundColor.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// BackgroundColor.swift -// DrawingApp -// -// Created by Jihee hwang on 2022/03/01. -// - -import Foundation - -class BackgroundColor { - - private var 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/Color.swift b/DrawingApp/DrawingApp/Model/Color.swift new file mode 100644 index 00000000..a18010a0 --- /dev/null +++ b/DrawingApp/DrawingApp/Model/Color.swift @@ -0,0 +1,44 @@ +// +// BackgroundColor.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/01. +// + +import Foundation + +class Color { + static let min = 0 + static let max = 255 + + var r: Int { checkRange(number: checkR) } + var g: Int { checkRange(number: checkG) } + var b: Int { checkRange(number: checkB) } + + private let checkR: Int + private let checkG: Int + private let checkB: Int + + func checkRange(number: Int) -> Int { + if number < Color.min { + return Color.min + } else if number > Color.max { + return Color.max + } else { + return number + } + } + + init(r: Int, g: Int, b: Int) { + self.checkR = r + self.checkG = g + self.checkB = b + } + +} + +extension Color: CustomStringConvertible { + var description: String { + return "R: \(r), G: \(g), b: \(b)" + } +} diff --git a/DrawingApp/DrawingApp/Model/Plane.swift b/DrawingApp/DrawingApp/Model/Plane.swift index 57562589..f55f0d0b 100644 --- a/DrawingApp/DrawingApp/Model/Plane.swift +++ b/DrawingApp/DrawingApp/Model/Plane.swift @@ -6,7 +6,6 @@ // import Foundation -import UIKit class Plane { diff --git a/DrawingApp/DrawingApp/Model/Point.swift b/DrawingApp/DrawingApp/Model/Point.swift index 004f9fa0..681f00de 100644 --- a/DrawingApp/DrawingApp/Model/Point.swift +++ b/DrawingApp/DrawingApp/Model/Point.swift @@ -9,8 +9,8 @@ import Foundation class Point { - let x: Double - 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/Model/Rectangle.swift b/DrawingApp/DrawingApp/Model/Rectangle.swift index 5764949a..19f2e713 100644 --- a/DrawingApp/DrawingApp/Model/Rectangle.swift +++ b/DrawingApp/DrawingApp/Model/Rectangle.swift @@ -10,23 +10,23 @@ import Foundation class Rectangle { private let id: String - private let size: Size - let point: Point - private let backGroundColor: BackgroundColor - private let alpha: Alpha + 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, backGroundColor: BackgroundColor, alpha: Alpha) { + init(id: String, size: Size, point: Point, color: Color, alpha: Alpha) { self.id = id self.size = size self.point = point - self.backGroundColor = backGroundColor + self.color = color self.alpha = alpha } } extension Rectangle: CustomStringConvertible { var description: String { - return "(\(id)), \(point), \(point), \(backGroundColor), \(alpha)" + return "(\(id)), \(point), \(point), \(color), \(alpha)" } } diff --git a/DrawingApp/DrawingApp/Model/Size.swift b/DrawingApp/DrawingApp/Model/Size.swift index 23908847..9115616e 100644 --- a/DrawingApp/DrawingApp/Model/Size.swift +++ b/DrawingApp/DrawingApp/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/Model/Util.swift b/DrawingApp/DrawingApp/Model/Util.swift new file mode 100644 index 00000000..5aef3d56 --- /dev/null +++ b/DrawingApp/DrawingApp/Model/Util.swift @@ -0,0 +1,15 @@ + +// DrawingApp +// +// Created by Jihee hwang on 2022/03/10. +// + +import Foundation +import UIKit + +struct Util { + static func convertUIColor() -> UIColor { + let red = Color + } + +} diff --git a/DrawingApp/DrawingApp/ViewController.swift b/DrawingApp/DrawingApp/ViewController.swift index 73654416..b3261264 100644 --- a/DrawingApp/DrawingApp/ViewController.swift +++ b/DrawingApp/DrawingApp/ViewController.swift @@ -16,10 +16,15 @@ class ViewController: UIViewController { @IBAction func createRectangle(_ sender: UIButton) { let logger = Logger() + let newRectangle = Factory.createRectangle() + logger.info("\(newRectangle)") - for makeCount in 1...4 { - logger.info("Rect\(makeCount) \(Factory.createRectangle())") - } + let test = UIView.init(frame: CGRect(x: newRectangle.point.x, y: newRectangle.point.y, width: newRectangle.size.width, height: newRectangle.size.height)) + test.backgroundColor = UIColor.red +// test.backgroundColor = UIColor(red: 0, green: CGFloat(newRectangle.color.g), blue: CGFloat(newRectangle.color.b), alpha: newRectangle.alpha.self) + self.view.addSubview(test) + + } } From c91617fa5d12b4aec6bee04b0577617d44a28d66 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Thu, 10 Mar 2022 22:17:55 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[=20Create=20]=20Convert=20RGB=20to=20UIC?= =?UTF-8?q?olor=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B7=B0=EC=97=90=20=EB=9E=9C=EB=8D=A4=20=EC=82=AC=EA=B0=81?= =?UTF-8?q?=ED=98=95=20=EB=9D=84=EC=9A=B0=EA=B8=B0=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawingApp/DrawingApp/Factory/Factory.swift | 12 +++---- DrawingApp/DrawingApp/Model/Alpha.swift | 21 ++++-------- DrawingApp/DrawingApp/Model/Color.swift | 36 ++++++++------------- DrawingApp/DrawingApp/Model/Rectangle.swift | 2 +- DrawingApp/DrawingApp/Model/Util.swift | 13 ++++++-- DrawingApp/DrawingApp/ViewController.swift | 6 ++-- 6 files changed, 39 insertions(+), 51 deletions(-) diff --git a/DrawingApp/DrawingApp/Factory/Factory.swift b/DrawingApp/DrawingApp/Factory/Factory.swift index f0651201..88444ef3 100644 --- a/DrawingApp/DrawingApp/Factory/Factory.swift +++ b/DrawingApp/DrawingApp/Factory/Factory.swift @@ -19,12 +19,12 @@ class Factory { let DeviceHeight = UIScreen.main.bounds.size.height - marginY let size = Size(width: 150, height: 120) - let point = Point(x: Double.random(in: 0.. Double { - if number < Alpha.min { - return Alpha.min - } else if number > Alpha.max { - return Alpha.max - } else { - return number - } - } - - init(alpha: Double) { - self.value = alpha / 10 + init(value: Double) { + self.value = value / 10 + + if value < Alpha.min { self.value = Alpha.min } + if value > Alpha.max { self.value = Alpha.max } } } diff --git a/DrawingApp/DrawingApp/Model/Color.swift b/DrawingApp/DrawingApp/Model/Color.swift index a18010a0..4c4f1f10 100644 --- a/DrawingApp/DrawingApp/Model/Color.swift +++ b/DrawingApp/DrawingApp/Model/Color.swift @@ -8,31 +8,21 @@ import Foundation class Color { - static let min = 0 - static let max = 255 + static let min = 0.0 + static let max = 255.0 - var r: Int { checkRange(number: checkR) } - var g: Int { checkRange(number: checkG) } - var b: Int { checkRange(number: checkB) } + private(set) var r: Double + private(set) var g: Double + private(set) var b: Double - private let checkR: Int - private let checkG: Int - private let checkB: Int - - func checkRange(number: Int) -> Int { - if number < Color.min { - return Color.min - } else if number > Color.max { - return Color.max - } else { - return number - } - } - - init(r: Int, g: Int, b: Int) { - self.checkR = r - self.checkG = g - self.checkB = b + 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 } } } diff --git a/DrawingApp/DrawingApp/Model/Rectangle.swift b/DrawingApp/DrawingApp/Model/Rectangle.swift index 19f2e713..b8473d30 100644 --- a/DrawingApp/DrawingApp/Model/Rectangle.swift +++ b/DrawingApp/DrawingApp/Model/Rectangle.swift @@ -26,7 +26,7 @@ class Rectangle { extension Rectangle: CustomStringConvertible { var description: String { - return "(\(id)), \(point), \(point), \(color), \(alpha)" + return "(\(id)), \(size), \(point), \(color), \(alpha)" } } diff --git a/DrawingApp/DrawingApp/Model/Util.swift b/DrawingApp/DrawingApp/Model/Util.swift index 5aef3d56..8226820f 100644 --- a/DrawingApp/DrawingApp/Model/Util.swift +++ b/DrawingApp/DrawingApp/Model/Util.swift @@ -8,8 +8,15 @@ import Foundation import UIKit struct Util { - static func convertUIColor() -> UIColor { - let red = Color - } + private(set) var color: Color + private(set) var alpha: Alpha + func getUIColor() -> UIColor { + let red = color.r / 255 + let green = color.g / 255 + let blue = color.b / 255 + let alpha = alpha.value + + return UIColor(red: red, green: green, blue: blue, alpha: alpha) + } } diff --git a/DrawingApp/DrawingApp/ViewController.swift b/DrawingApp/DrawingApp/ViewController.swift index b3261264..52ceb696 100644 --- a/DrawingApp/DrawingApp/ViewController.swift +++ b/DrawingApp/DrawingApp/ViewController.swift @@ -20,11 +20,11 @@ class ViewController: UIViewController { logger.info("\(newRectangle)") let test = UIView.init(frame: CGRect(x: newRectangle.point.x, y: newRectangle.point.y, width: newRectangle.size.width, height: newRectangle.size.height)) - test.backgroundColor = UIColor.red -// test.backgroundColor = UIColor(red: 0, green: CGFloat(newRectangle.color.g), blue: CGFloat(newRectangle.color.b), alpha: newRectangle.alpha.self) + + let util = Util(color: newRectangle.color, alpha: newRectangle.alpha) + test.backgroundColor = util.getUIColor() self.view.addSubview(test) - } } From 0f5a5d0428d7d4be3e05548f939462f13995c743 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Mon, 14 Mar 2022 11:54:39 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[=20Fix=20]=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=ED=99=94=20=EB=B0=8F=20Convert=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Util 객체를 Convert 로 변경 후, 메서드 추가 --- .../DrawingApp.xcodeproj/project.pbxproj | 56 ++++++++++++------- DrawingApp/DrawingApp/Model/Util.swift | 22 -------- .../{ => Resources}/AppDelegate.swift | 0 .../AccentColor.colorset/Contents.json | 0 .../AppIcon.appiconset/Contents.json | 0 .../Assets.xcassets/Contents.json | 0 .../Base.lproj/Main.storyboard | 0 .../Base/Base.lproj/LaunchScreen.storyboard | 0 .../{ => Resources}/SceneDelegate.swift | 0 DrawingApp/DrawingApp/Sources/Convert.swift | 24 ++++++++ .../{Factory => Sources}/Factory.swift | 0 .../{ => Sources}/Model/Alpha.swift | 0 .../{ => Sources}/Model/Color.swift | 0 .../DrawingApp/{ => Sources}/Model/ID.swift | 0 .../{ => Sources}/Model/Plane.swift | 0 .../{ => Sources}/Model/Point.swift | 0 .../{ => Sources}/Model/Rectangle.swift | 0 .../DrawingApp/{ => Sources}/Model/Size.swift | 0 .../{ => Sources/VC}/ViewController.swift | 3 +- 19 files changed, 62 insertions(+), 43 deletions(-) delete mode 100644 DrawingApp/DrawingApp/Model/Util.swift rename DrawingApp/DrawingApp/{ => Resources}/AppDelegate.swift (100%) rename DrawingApp/DrawingApp/{Base => Resources}/Assets.xcassets/AccentColor.colorset/Contents.json (100%) rename DrawingApp/DrawingApp/{Base => Resources}/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename DrawingApp/DrawingApp/{Base => Resources}/Assets.xcassets/Contents.json (100%) rename DrawingApp/DrawingApp/{Base => Resources}/Base.lproj/Main.storyboard (100%) rename DrawingApp/DrawingApp/{ => Resources}/Base/Base.lproj/LaunchScreen.storyboard (100%) rename DrawingApp/DrawingApp/{ => Resources}/SceneDelegate.swift (100%) create mode 100644 DrawingApp/DrawingApp/Sources/Convert.swift rename DrawingApp/DrawingApp/{Factory => Sources}/Factory.swift (100%) rename DrawingApp/DrawingApp/{ => Sources}/Model/Alpha.swift (100%) rename DrawingApp/DrawingApp/{ => Sources}/Model/Color.swift (100%) rename DrawingApp/DrawingApp/{ => Sources}/Model/ID.swift (100%) rename DrawingApp/DrawingApp/{ => Sources}/Model/Plane.swift (100%) rename DrawingApp/DrawingApp/{ => Sources}/Model/Point.swift (100%) rename DrawingApp/DrawingApp/{ => Sources}/Model/Rectangle.swift (100%) rename DrawingApp/DrawingApp/{ => Sources}/Model/Size.swift (100%) rename DrawingApp/DrawingApp/{ => Sources/VC}/ViewController.swift (83%) diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index 7a96291b..ada69f9c 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -17,7 +17,8 @@ 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 */; }; - 73966C8827DA10FE006883FF /* Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73966C8727DA10FE006883FF /* Util.swift */; }; + 738ADB1227DEDCC300BE418C /* Convert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73966C8727DA10FE006883FF /* Convert.swift */; }; + 73966C8827DA10FE006883FF /* Convert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73966C8727DA10FE006883FF /* Convert.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 */; }; @@ -47,7 +48,7 @@ 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 /* Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Util.swift; sourceTree = ""; }; + 73966C8727DA10FE006883FF /* Convert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convert.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 = ""; }; @@ -85,27 +86,48 @@ 73312E5127D61A170073D746 /* Base */ = { isa = PBXGroup; children = ( - 73C750A127CDB7D300086C1D /* Main.storyboard */, 73C750A627CDB7D400086C1D /* LaunchScreen.storyboard */, - 73C750A427CDB7D400086C1D /* Assets.xcassets */, ); path = Base; sourceTree = ""; }; - 736D9D3127CFB3D600C040D8 /* Factory */ = { + 736D9D3927CFBF6C00C040D8 /* DrawingAppTests */ = { isa = PBXGroup; children = ( - 73C750BC27CE1D1A00086C1D /* Factory.swift */, + 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */, ); - path = Factory; + path = DrawingAppTests; sourceTree = ""; }; - 736D9D3927CFBF6C00C040D8 /* DrawingAppTests */ = { + 738ADB1427DEE16200BE418C /* Resources */ = { isa = PBXGroup; children = ( - 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */, + 73C750A127CDB7D300086C1D /* Main.storyboard */, + 73C750A427CDB7D400086C1D /* Assets.xcassets */, + 73C7509D27CDB7D300086C1D /* SceneDelegate.swift */, + 73C7509B27CDB7D300086C1D /* AppDelegate.swift */, + 73312E5127D61A170073D746 /* Base */, ); - path = DrawingAppTests; + path = Resources; + sourceTree = ""; + }; + 738ADB1527DEE1A900BE418C /* VC */ = { + isa = PBXGroup; + children = ( + 73C7509F27CDB7D300086C1D /* ViewController.swift */, + ); + path = VC; + sourceTree = ""; + }; + 738ADB1627DEE1B700BE418C /* Sources */ = { + isa = PBXGroup; + children = ( + 73966C8727DA10FE006883FF /* Convert.swift */, + 73C750BC27CE1D1A00086C1D /* Factory.swift */, + 73C750AF27CE003D00086C1D /* Model */, + 738ADB1527DEE1A900BE418C /* VC */, + ); + path = Sources; sourceTree = ""; }; 73C7508F27CDB7D300086C1D = { @@ -129,13 +151,9 @@ 73C7509A27CDB7D300086C1D /* DrawingApp */ = { isa = PBXGroup; children = ( - 73312E5127D61A170073D746 /* Base */, - 73C750AF27CE003D00086C1D /* Model */, - 736D9D3127CFB3D600C040D8 /* Factory */, - 73C7509B27CDB7D300086C1D /* AppDelegate.swift */, - 73C7509D27CDB7D300086C1D /* SceneDelegate.swift */, - 73C7509F27CDB7D300086C1D /* ViewController.swift */, 73C750A927CDB7D400086C1D /* Info.plist */, + 738ADB1427DEE16200BE418C /* Resources */, + 738ADB1627DEE1B700BE418C /* Sources */, ); path = DrawingApp; sourceTree = ""; @@ -143,12 +161,11 @@ 73C750AF27CE003D00086C1D /* Model */ = { isa = PBXGroup; children = ( - 73966C8727DA10FE006883FF /* Util.swift */, 7348F21A27D7407F00613449 /* Plane.swift */, 73C750B827CE033900086C1D /* Rectangle.swift */, + 73C750B427CE015800086C1D /* Color.swift */, 73C750B027CE007300086C1D /* Size.swift */, 73C750B227CE00FE00086C1D /* Point.swift */, - 73C750B427CE015800086C1D /* Color.swift */, 73C750B627CE01CF00086C1D /* Alpha.swift */, 738A8A8227D5AC1400086985 /* ID.swift */, ); @@ -257,6 +274,7 @@ buildActionMask = 2147483647; files = ( 73312E5027D618C10073D746 /* ID.swift in Sources */, + 738ADB1227DEDCC300BE418C /* Convert.swift in Sources */, 736D9D4727CFBF9E00C040D8 /* Size.swift in Sources */, 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */, 736D9D4527CFBF9E00C040D8 /* Alpha.swift in Sources */, @@ -278,7 +296,7 @@ 73C750B327CE00FE00086C1D /* Point.swift in Sources */, 73C750A027CDB7D300086C1D /* ViewController.swift in Sources */, 73C750BD27CE1D1A00086C1D /* Factory.swift in Sources */, - 73966C8827DA10FE006883FF /* Util.swift in Sources */, + 73966C8827DA10FE006883FF /* Convert.swift in Sources */, 73C7509C27CDB7D300086C1D /* AppDelegate.swift in Sources */, 73C7509E27CDB7D300086C1D /* SceneDelegate.swift in Sources */, 73C750B927CE033900086C1D /* Rectangle.swift in Sources */, diff --git a/DrawingApp/DrawingApp/Model/Util.swift b/DrawingApp/DrawingApp/Model/Util.swift deleted file mode 100644 index 8226820f..00000000 --- a/DrawingApp/DrawingApp/Model/Util.swift +++ /dev/null @@ -1,22 +0,0 @@ - -// DrawingApp -// -// Created by Jihee hwang on 2022/03/10. -// - -import Foundation -import UIKit - -struct Util { - private(set) var color: Color - private(set) var alpha: Alpha - - func getUIColor() -> UIColor { - let red = color.r / 255 - let green = color.g / 255 - let blue = color.b / 255 - let alpha = alpha.value - - return UIColor(red: red, green: green, blue: blue, 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/Base/Assets.xcassets/AccentColor.colorset/Contents.json b/DrawingApp/DrawingApp/Resources/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Base/Assets.xcassets/AccentColor.colorset/Contents.json rename to DrawingApp/DrawingApp/Resources/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/DrawingApp/DrawingApp/Base/Assets.xcassets/AppIcon.appiconset/Contents.json b/DrawingApp/DrawingApp/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Base/Assets.xcassets/AppIcon.appiconset/Contents.json rename to DrawingApp/DrawingApp/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/DrawingApp/DrawingApp/Base/Assets.xcassets/Contents.json b/DrawingApp/DrawingApp/Resources/Assets.xcassets/Contents.json similarity index 100% rename from DrawingApp/DrawingApp/Base/Assets.xcassets/Contents.json rename to DrawingApp/DrawingApp/Resources/Assets.xcassets/Contents.json diff --git a/DrawingApp/DrawingApp/Base/Base.lproj/Main.storyboard b/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard similarity index 100% rename from DrawingApp/DrawingApp/Base/Base.lproj/Main.storyboard rename to DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard diff --git a/DrawingApp/DrawingApp/Base/Base.lproj/LaunchScreen.storyboard b/DrawingApp/DrawingApp/Resources/Base/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from DrawingApp/DrawingApp/Base/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..5380de4f --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Convert.swift @@ -0,0 +1,24 @@ + +// DrawingApp +// +// Created by Jihee hwang on 2022/03/10. +// + +import Foundation +import UIKit + +struct Convert { + + static func getUIColor(color: Color, alpha: Alpha) -> UIColor { + return UIColor(red: color.r / 255, green: color.g / 255, blue: color.b / 255, alpha: alpha.value) + } + + static func getCGSize(size: Size) -> CGSize { + return CGSize(width: size.width, height: size.height) + } + + static func getCGPoint(point: Point) -> CGPoint { + return CGPoint(x: point.x, y: point.y) + } + +} diff --git a/DrawingApp/DrawingApp/Factory/Factory.swift b/DrawingApp/DrawingApp/Sources/Factory.swift similarity index 100% rename from DrawingApp/DrawingApp/Factory/Factory.swift rename to DrawingApp/DrawingApp/Sources/Factory.swift diff --git a/DrawingApp/DrawingApp/Model/Alpha.swift b/DrawingApp/DrawingApp/Sources/Model/Alpha.swift similarity index 100% rename from DrawingApp/DrawingApp/Model/Alpha.swift rename to DrawingApp/DrawingApp/Sources/Model/Alpha.swift diff --git a/DrawingApp/DrawingApp/Model/Color.swift b/DrawingApp/DrawingApp/Sources/Model/Color.swift similarity index 100% rename from DrawingApp/DrawingApp/Model/Color.swift rename to DrawingApp/DrawingApp/Sources/Model/Color.swift diff --git a/DrawingApp/DrawingApp/Model/ID.swift b/DrawingApp/DrawingApp/Sources/Model/ID.swift similarity index 100% rename from DrawingApp/DrawingApp/Model/ID.swift rename to DrawingApp/DrawingApp/Sources/Model/ID.swift diff --git a/DrawingApp/DrawingApp/Model/Plane.swift b/DrawingApp/DrawingApp/Sources/Model/Plane.swift similarity index 100% rename from DrawingApp/DrawingApp/Model/Plane.swift rename to DrawingApp/DrawingApp/Sources/Model/Plane.swift diff --git a/DrawingApp/DrawingApp/Model/Point.swift b/DrawingApp/DrawingApp/Sources/Model/Point.swift similarity index 100% rename from DrawingApp/DrawingApp/Model/Point.swift rename to DrawingApp/DrawingApp/Sources/Model/Point.swift diff --git a/DrawingApp/DrawingApp/Model/Rectangle.swift b/DrawingApp/DrawingApp/Sources/Model/Rectangle.swift similarity index 100% rename from DrawingApp/DrawingApp/Model/Rectangle.swift rename to DrawingApp/DrawingApp/Sources/Model/Rectangle.swift diff --git a/DrawingApp/DrawingApp/Model/Size.swift b/DrawingApp/DrawingApp/Sources/Model/Size.swift similarity index 100% rename from DrawingApp/DrawingApp/Model/Size.swift rename to DrawingApp/DrawingApp/Sources/Model/Size.swift diff --git a/DrawingApp/DrawingApp/ViewController.swift b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift similarity index 83% rename from DrawingApp/DrawingApp/ViewController.swift rename to DrawingApp/DrawingApp/Sources/VC/ViewController.swift index 52ceb696..eadf91e4 100644 --- a/DrawingApp/DrawingApp/ViewController.swift +++ b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift @@ -21,8 +21,7 @@ class ViewController: UIViewController { let test = UIView.init(frame: CGRect(x: newRectangle.point.x, y: newRectangle.point.y, width: newRectangle.size.width, height: newRectangle.size.height)) - let util = Util(color: newRectangle.color, alpha: newRectangle.alpha) - test.backgroundColor = util.getUIColor() + test.backgroundColor = Convert.getUIColor(color: newRectangle.color, alpha: newRectangle.alpha) self.view.addSubview(test) } From 9996384fb21883856d5b2a17a12b6c604a72485f Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Mon, 14 Mar 2022 12:06:25 +0900 Subject: [PATCH 10/15] [ Fix ] Create Object Log --- DrawingApp/DrawingApp.xcodeproj/project.pbxproj | 4 ++++ DrawingApp/DrawingApp/Sources/Log.swift | 15 +++++++++++++++ .../DrawingApp/Sources/VC/ViewController.swift | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 DrawingApp/DrawingApp/Sources/Log.swift diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index ada69f9c..4a6d7eb2 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 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 */; }; 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */; }; 736D9D4227CFBF9600C040D8 /* Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750BC27CE1D1A00086C1D /* Factory.swift */; }; 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B227CE00FE00086C1D /* Point.swift */; }; @@ -45,6 +46,7 @@ /* Begin PBXFileReference section */ 7348F21A27D7407F00613449 /* Plane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Plane.swift; sourceTree = ""; }; + 735A315F27DEE60900E3E4C0 /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.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 = ""; }; @@ -124,6 +126,7 @@ children = ( 73966C8727DA10FE006883FF /* Convert.swift */, 73C750BC27CE1D1A00086C1D /* Factory.swift */, + 735A315F27DEE60900E3E4C0 /* Log.swift */, 73C750AF27CE003D00086C1D /* Model */, 738ADB1527DEE1A900BE418C /* VC */, ); @@ -290,6 +293,7 @@ buildActionMask = 2147483647; files = ( 73C750B127CE007300086C1D /* Size.swift in Sources */, + 735A316027DEE60900E3E4C0 /* Log.swift in Sources */, 738A8A8327D5AC1400086985 /* ID.swift in Sources */, 73C750B527CE015800086C1D /* Color.swift in Sources */, 73C750B727CE01CF00086C1D /* Alpha.swift in Sources */, 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/VC/ViewController.swift b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift index eadf91e4..7aca06d2 100644 --- a/DrawingApp/DrawingApp/Sources/VC/ViewController.swift +++ b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift @@ -15,9 +15,9 @@ class ViewController: UIViewController { } @IBAction func createRectangle(_ sender: UIButton) { - let logger = Logger() let newRectangle = Factory.createRectangle() - logger.info("\(newRectangle)") + + OSLog.log(message: newRectangle.description) let test = UIView.init(frame: CGRect(x: newRectangle.point.x, y: newRectangle.point.y, width: newRectangle.size.width, height: newRectangle.size.height)) From 5333510b910992043813efeeb8565f824af4c9a5 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Mon, 14 Mar 2022 17:32:56 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[=20Add=20]=20Hex=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawingApp/DrawingApp/Sources/Convert.swift | 22 ++++++++++++++++--- .../Sources/VC/ViewController.swift | 8 ++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/DrawingApp/DrawingApp/Sources/Convert.swift b/DrawingApp/DrawingApp/Sources/Convert.swift index 5380de4f..01ee7aa1 100644 --- a/DrawingApp/DrawingApp/Sources/Convert.swift +++ b/DrawingApp/DrawingApp/Sources/Convert.swift @@ -9,16 +9,32 @@ import UIKit struct Convert { - static func getUIColor(color: Color, alpha: Alpha) -> UIColor { + 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 getCGSize(size: Size) -> CGSize { + static func toCGSize(size: Size) -> CGSize { return CGSize(width: size.width, height: size.height) } - static func getCGPoint(point: Point) -> CGPoint { + 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 + } + + 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/VC/ViewController.swift b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift index 7aca06d2..6ffb5050 100644 --- a/DrawingApp/DrawingApp/Sources/VC/ViewController.swift +++ b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift @@ -21,7 +21,13 @@ class ViewController: UIViewController { let test = UIView.init(frame: CGRect(x: newRectangle.point.x, y: newRectangle.point.y, width: newRectangle.size.width, height: newRectangle.size.height)) - test.backgroundColor = Convert.getUIColor(color: newRectangle.color, alpha: newRectangle.alpha) + let check = Convert.toUIColor(color: newRectangle.color, alpha: newRectangle.alpha) + + test.backgroundColor = check + print(check.toHex() ?? "") + + + self.view.addSubview(test) } From c9a3a9171bb2e8409f09337de67c1f4989244379 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Thu, 17 Mar 2022 16:13:38 +0900 Subject: [PATCH 12/15] [ Create ] Delegate and Custom View --- .../DrawingApp.xcodeproj/project.pbxproj | 28 +++++++++++-- .../Resources/Base.lproj/Main.storyboard | 8 ++++ DrawingApp/DrawingApp/Sources/Convert.swift | 4 +- DrawingApp/DrawingApp/Sources/Factory.swift | 12 ++---- .../DrawingApp/Sources/Model/Plane.swift | 4 +- .../DrawingApp/Sources/Model/Rectangle.swift | 6 ++- .../DrawingApp/Sources/PlaneDelegate.swift | 13 +++++++ .../Sources/VC/ViewController.swift | 27 ++++++------- .../Sources/View/RectengleView.swift | 39 +++++++++++++++++++ .../Sources/View/Right V\020iew.xib" | 18 +++++++++ .../DrawingApp/Sources/View/RightView.swift | 36 +++++++++++++++++ 11 files changed, 162 insertions(+), 33 deletions(-) create mode 100644 DrawingApp/DrawingApp/Sources/PlaneDelegate.swift create mode 100644 DrawingApp/DrawingApp/Sources/View/RectengleView.swift create mode 100644 "DrawingApp/DrawingApp/Sources/View/Right V\020iew.xib" create mode 100644 DrawingApp/DrawingApp/Sources/View/RightView.swift diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index 4a6d7eb2..776439dd 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -9,7 +9,11 @@ /* Begin PBXBuildFile section */ 73312E5027D618C10073D746 /* ID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738A8A8227D5AC1400086985 /* ID.swift */; }; 7348F21B27D7407F00613449 /* Plane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7348F21A27D7407F00613449 /* Plane.swift */; }; + 73583EE327E03E5800BE36DA /* RectengleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73583EE227E03E5800BE36DA /* RectengleView.swift */; }; 735A316027DEE60900E3E4C0 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 735A315F27DEE60900E3E4C0 /* Log.swift */; }; + 735A316327DF802500E3E4C0 /* Right View.xib in Resources */ = {isa = PBXBuildFile; fileRef = 735A316227DF802500E3E4C0 /* Right View.xib */; }; + 735A316727DF80ED00E3E4C0 /* RightView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 735A316627DF80ED00E3E4C0 /* RightView.swift */; }; + 735A316927DF84A600E3E4C0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 735A316827DF84A600E3E4C0 /* ViewController.swift */; }; 736D9D3B27CFBF6C00C040D8 /* DrawingAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736D9D3A27CFBF6C00C040D8 /* DrawingAppTests.swift */; }; 736D9D4227CFBF9600C040D8 /* Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750BC27CE1D1A00086C1D /* Factory.swift */; }; 736D9D4327CFBF9E00C040D8 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750B227CE00FE00086C1D /* Point.swift */; }; @@ -22,7 +26,6 @@ 73966C8827DA10FE006883FF /* Convert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73966C8727DA10FE006883FF /* Convert.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 */; }; @@ -46,7 +49,11 @@ /* Begin PBXFileReference section */ 7348F21A27D7407F00613449 /* Plane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Plane.swift; sourceTree = ""; }; + 73583EE227E03E5800BE36DA /* RectengleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RectengleView.swift; sourceTree = ""; }; 735A315F27DEE60900E3E4C0 /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = ""; }; + 735A316227DF802500E3E4C0 /* Right View.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = "Right V\U0010iew.xib"; sourceTree = ""; }; + 735A316627DF80ED00E3E4C0 /* RightView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RightView.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 = ""; }; @@ -54,7 +61,6 @@ 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 = ""; }; @@ -93,6 +99,16 @@ path = Base; sourceTree = ""; }; + 735A316127DF7FFC00E3E4C0 /* View */ = { + isa = PBXGroup; + children = ( + 735A316227DF802500E3E4C0 /* Right View.xib */, + 735A316627DF80ED00E3E4C0 /* RightView.swift */, + 73583EE227E03E5800BE36DA /* RectengleView.swift */, + ); + path = View; + sourceTree = ""; + }; 736D9D3927CFBF6C00C040D8 /* DrawingAppTests */ = { isa = PBXGroup; children = ( @@ -116,7 +132,7 @@ 738ADB1527DEE1A900BE418C /* VC */ = { isa = PBXGroup; children = ( - 73C7509F27CDB7D300086C1D /* ViewController.swift */, + 735A316827DF84A600E3E4C0 /* ViewController.swift */, ); path = VC; sourceTree = ""; @@ -128,6 +144,7 @@ 73C750BC27CE1D1A00086C1D /* Factory.swift */, 735A315F27DEE60900E3E4C0 /* Log.swift */, 73C750AF27CE003D00086C1D /* Model */, + 735A316127DF7FFC00E3E4C0 /* View */, 738ADB1527DEE1A900BE418C /* VC */, ); path = Sources; @@ -264,6 +281,7 @@ buildActionMask = 2147483647; files = ( 73C750A827CDB7D400086C1D /* LaunchScreen.storyboard in Resources */, + 735A316327DF802500E3E4C0 /* Right View.xib in Resources */, 73C750A527CDB7D400086C1D /* Assets.xcassets in Resources */, 73C750A327CDB7D300086C1D /* Main.storyboard in Resources */, ); @@ -292,13 +310,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 735A316927DF84A600E3E4C0 /* ViewController.swift in Sources */, 73C750B127CE007300086C1D /* Size.swift in Sources */, 735A316027DEE60900E3E4C0 /* Log.swift in Sources */, 738A8A8327D5AC1400086985 /* ID.swift in Sources */, 73C750B527CE015800086C1D /* Color.swift in Sources */, 73C750B727CE01CF00086C1D /* Alpha.swift in Sources */, 73C750B327CE00FE00086C1D /* Point.swift in Sources */, - 73C750A027CDB7D300086C1D /* ViewController.swift in Sources */, + 73583EE327E03E5800BE36DA /* RectengleView.swift in Sources */, + 735A316727DF80ED00E3E4C0 /* RightView.swift in Sources */, 73C750BD27CE1D1A00086C1D /* Factory.swift in Sources */, 73966C8827DA10FE006883FF /* Convert.swift in Sources */, 73C7509C27CDB7D300086C1D /* AppDelegate.swift in Sources */, diff --git a/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard b/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard index cfbdfb90..6e03f2d8 100644 --- a/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard +++ b/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard @@ -16,6 +16,11 @@ + + + + + + + + + + + + + - + + diff --git a/DrawingApp/DrawingApp/Sources/Delegate/PanelDelegate.swift b/DrawingApp/DrawingApp/Sources/Delegate/PanelDelegate.swift new file mode 100644 index 00000000..9e178687 --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/Delegate/PanelDelegate.swift @@ -0,0 +1,14 @@ +// +// PanelDelegate.swift +// DrawingApp +// +// Created by Jihee hwang on 2022/03/17. +// + +import Foundation + +protocol PanelDelegate { + 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 index fc9df1f3..509ad7c6 100644 --- a/DrawingApp/DrawingApp/Sources/Factory.swift +++ b/DrawingApp/DrawingApp/Sources/Factory.swift @@ -10,11 +10,11 @@ import UIKit class Factory { - static func createRectangle(marginX: Double, marginY: Double) -> Rectangle { + static func createRectangle() -> Rectangle { let size = Size(width: 150, height: 120) - let point = Point(x: round(Double.random(in: 0.. Rectangle { return rectangles[index] } - func createRectangle(marginX: Double, marginY: Double) -> Rectangle { - let add = Factory.createRectangle(marginX: marginX, marginY: marginY) + func createRectangle() { + let add = Factory.createRectangle() rectangles.append(add) - return add + + delegate?.didCreatRectangel(rectangle: add) } func countingRectangle() -> Int { diff --git a/DrawingApp/DrawingApp/Sources/VC/ViewController.swift b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift index fbd0b663..6a4455b8 100644 --- a/DrawingApp/DrawingApp/Sources/VC/ViewController.swift +++ b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift @@ -9,24 +9,58 @@ import UIKit import OSLog class ViewController: UIViewController { + + @IBOutlet weak var canvas: UIView! + @IBOutlet weak var panel: Panel! - private var model = Plane() - private var rectengles = [Rectangle: RectengleView]() // 이 안에 Rectangle 값이랑, 그에 맞는 view를 넣어 + private var plane = Plane() - @IBOutlet weak var canvas: UIView! + private var rectengles = [Rectangle: UIView]() // 이 안에 Rectangle 값이랑, 그에 맞는 view를 넣어 override func viewDidLoad() { super.viewDidLoad() + self.view.addSubview(canvas) + + plane.delegate = self + panel.delegate = self + } + +} + +extension ViewController: PanelDelegate { + func didpressColorChangeButton() { + print("") + } + + func didMoveSlider() { + print("") + + } + + func didpressCreateRectangleButton() { + plane.createRectangle() + } + +} - @IBAction func createRectangle(_ sender: UIButton) { - let rectangle = model.createRectangle(marginX: canvas.bounds.width, marginY: canvas.bounds.height) +extension ViewController: PlaneDelegate { - let view = RectengleView.init(frame: CGRect(x: rectangle.point.x, y: rectangle.point.y, width: rectangle.size.width, height: rectangle.size.height)) + 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/RightView.swift b/DrawingApp/DrawingApp/Sources/View/Panel.swift similarity index 59% rename from DrawingApp/DrawingApp/Sources/View/RightView.swift rename to DrawingApp/DrawingApp/Sources/View/Panel.swift index 42967413..9a762872 100644 --- a/DrawingApp/DrawingApp/Sources/View/RightView.swift +++ b/DrawingApp/DrawingApp/Sources/View/Panel.swift @@ -7,20 +7,18 @@ import UIKit +class Panel: UIView { -//@IBDesignable -class RightView: UIView { - - @IBOutlet weak var rightViewBackground: UIView! + var delegate: PanelDelegate? required init?(coder: NSCoder) { super.init(coder: coder) - loadXib() + self.loadXib() } override init(frame: CGRect) { super.init(frame: frame) - loadXib() + self.loadXib() } private func loadXib() { @@ -33,4 +31,15 @@ class RightView: UIView { 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/Panel.xib b/DrawingApp/DrawingApp/Sources/View/Panel.xib new file mode 100644 index 00000000..782f2bfa --- /dev/null +++ b/DrawingApp/DrawingApp/Sources/View/Panel.xib @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DrawingApp/DrawingApp/Sources/View/RectengleView.swift b/DrawingApp/DrawingApp/Sources/View/RectengleView.swift deleted file mode 100644 index 8b58044c..00000000 --- a/DrawingApp/DrawingApp/Sources/View/RectengleView.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// RectengleView.swift -// DrawingApp -// -// Created by Jihee hwang on 2022/03/15. -// - -import UIKit - -class RectengleView: UIView { - - override init(frame: CGRect) { - super.init(frame: frame) - } - - required init?(coder: NSCoder) { - super.init(coder: coder) - } - - convenience init(frame: CGRect, color: Color, alpha: Alpha) { - self.init(frame: frame) - setColor(color: color, alpha: alpha) - } - - func setColor(color: Color, alpha: Alpha) { - self.backgroundColor = UIColor(red: color.r, green: color.g, blue: color.b, alpha: alpha.value) - } - - func selectRectangle(isSelect: Bool) { // 선택된 사각형 테두리 - if isSelect == true { - self.layer.borderColor = UIColor.black.cgColor - self.layer.borderWidth = 5 - } else { - self.layer.borderColor = UIColor.clear.cgColor - self.layer.borderWidth = 0 - } - } - -} diff --git "a/DrawingApp/DrawingApp/Sources/View/Right V\020iew.xib" "b/DrawingApp/DrawingApp/Sources/View/Right V\020iew.xib" deleted file mode 100644 index 8b759e78..00000000 --- "a/DrawingApp/DrawingApp/Sources/View/Right V\020iew.xib" +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - From 0e85494d547ffda07fca1a7e661e710bf4f34c7d Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Fri, 18 Mar 2022 11:35:08 +0900 Subject: [PATCH 14/15] [ Update ] Panel View --- DrawingApp/DrawingApp/Sources/Factory.swift | 2 +- DrawingApp/DrawingApp/Sources/View/Panel.xib | 140 +++++++++---------- 2 files changed, 69 insertions(+), 73 deletions(-) diff --git a/DrawingApp/DrawingApp/Sources/Factory.swift b/DrawingApp/DrawingApp/Sources/Factory.swift index 509ad7c6..05f1accd 100644 --- a/DrawingApp/DrawingApp/Sources/Factory.swift +++ b/DrawingApp/DrawingApp/Sources/Factory.swift @@ -14,7 +14,7 @@ class Factory { let size = Size(width: 150, height: 120) let point = Point(x: round(Double.random(in: 0...700)), - y: round(Double.random(in: 0...720))) + 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))) diff --git a/DrawingApp/DrawingApp/Sources/View/Panel.xib b/DrawingApp/DrawingApp/Sources/View/Panel.xib index 782f2bfa..da1df8d1 100644 --- a/DrawingApp/DrawingApp/Sources/View/Panel.xib +++ b/DrawingApp/DrawingApp/Sources/View/Panel.xib @@ -12,83 +12,79 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + + + + + + + + + + + From ed406e4933639122d45f6630a859045b1e9c7bc8 Mon Sep 17 00:00:00 2001 From: Jihee hwang Date: Fri, 18 Mar 2022 12:01:50 +0900 Subject: [PATCH 15/15] [ Change ] Panel to ControlView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Panel 과 Plane의 혼동으로 이름 변경 --- .../DrawingApp.xcodeproj/project.pbxproj | 24 +++++++++---------- .../Resources/Base.lproj/Main.storyboard | 4 ++-- ...legate.swift => ControlViewDelegate.swift} | 2 +- .../Sources/VC/ViewController.swift | 6 ++--- .../View/{Panel.swift => ControlView.swift} | 4 ++-- .../View/{Panel.xib => ControlView.xib} | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) rename DrawingApp/DrawingApp/Sources/Delegate/{PanelDelegate.swift => ControlViewDelegate.swift} (87%) rename DrawingApp/DrawingApp/Sources/View/{Panel.swift => ControlView.swift} (93%) rename DrawingApp/DrawingApp/Sources/View/{Panel.xib => ControlView.xib} (98%) diff --git a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj index 027e1dd7..207fc1cf 100644 --- a/DrawingApp/DrawingApp.xcodeproj/project.pbxproj +++ b/DrawingApp/DrawingApp.xcodeproj/project.pbxproj @@ -10,8 +10,8 @@ 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 /* Panel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 735A316227DF802500E3E4C0 /* Panel.xib */; }; - 735A316727DF80ED00E3E4C0 /* Panel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 735A316627DF80ED00E3E4C0 /* Panel.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 */; }; 736D9D4227CFBF9600C040D8 /* Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C750BC27CE1D1A00086C1D /* Factory.swift */; }; @@ -24,7 +24,7 @@ 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 /* PanelDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739B87AE27E31F3C00346AD9 /* PanelDelegate.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 */; }; 73C750A327CDB7D300086C1D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 73C750A127CDB7D300086C1D /* Main.storyboard */; }; @@ -51,15 +51,15 @@ /* Begin PBXFileReference section */ 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 /* Panel.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Panel.xib; sourceTree = ""; }; - 735A316627DF80ED00E3E4C0 /* Panel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panel.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 /* PanelDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanelDelegate.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 = ""; }; @@ -104,8 +104,8 @@ 735A316127DF7FFC00E3E4C0 /* View */ = { isa = PBXGroup; children = ( - 735A316227DF802500E3E4C0 /* Panel.xib */, - 735A316627DF80ED00E3E4C0 /* Panel.swift */, + 735A316227DF802500E3E4C0 /* ControlView.xib */, + 735A316627DF80ED00E3E4C0 /* ControlView.swift */, ); path = View; sourceTree = ""; @@ -156,7 +156,7 @@ isa = PBXGroup; children = ( 739B87AC27E3178100346AD9 /* PlaneDelegate.swift */, - 739B87AE27E31F3C00346AD9 /* PanelDelegate.swift */, + 739B87AE27E31F3C00346AD9 /* ControlViewDelegate.swift */, ); path = Delegate; sourceTree = ""; @@ -292,7 +292,7 @@ buildActionMask = 2147483647; files = ( 73C750A827CDB7D400086C1D /* LaunchScreen.storyboard in Resources */, - 735A316327DF802500E3E4C0 /* Panel.xib in Resources */, + 735A316327DF802500E3E4C0 /* ControlView.xib in Resources */, 73C750A527CDB7D400086C1D /* Assets.xcassets in Resources */, 73C750A327CDB7D300086C1D /* Main.storyboard in Resources */, ); @@ -325,11 +325,11 @@ 73C750B127CE007300086C1D /* Size.swift in Sources */, 735A316027DEE60900E3E4C0 /* Log.swift in Sources */, 738A8A8327D5AC1400086985 /* ID.swift in Sources */, - 739B87AF27E31F3C00346AD9 /* PanelDelegate.swift in Sources */, + 739B87AF27E31F3C00346AD9 /* ControlViewDelegate.swift in Sources */, 73C750B527CE015800086C1D /* Color.swift in Sources */, 73C750B727CE01CF00086C1D /* Alpha.swift in Sources */, 73C750B327CE00FE00086C1D /* Point.swift in Sources */, - 735A316727DF80ED00E3E4C0 /* Panel.swift in Sources */, + 735A316727DF80ED00E3E4C0 /* ControlView.swift in Sources */, 739B87AD27E3178100346AD9 /* PlaneDelegate.swift in Sources */, 73C750BD27CE1D1A00086C1D /* Factory.swift in Sources */, 73966C8827DA10FE006883FF /* Convert.swift in Sources */, diff --git a/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard b/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard index 513eaacf..c27e3217 100644 --- a/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard +++ b/DrawingApp/DrawingApp/Resources/Base.lproj/Main.storyboard @@ -16,7 +16,7 @@ - + @@ -45,7 +45,7 @@ - + diff --git a/DrawingApp/DrawingApp/Sources/Delegate/PanelDelegate.swift b/DrawingApp/DrawingApp/Sources/Delegate/ControlViewDelegate.swift similarity index 87% rename from DrawingApp/DrawingApp/Sources/Delegate/PanelDelegate.swift rename to DrawingApp/DrawingApp/Sources/Delegate/ControlViewDelegate.swift index 9e178687..9f001159 100644 --- a/DrawingApp/DrawingApp/Sources/Delegate/PanelDelegate.swift +++ b/DrawingApp/DrawingApp/Sources/Delegate/ControlViewDelegate.swift @@ -7,7 +7,7 @@ import Foundation -protocol PanelDelegate { +protocol ControlViewDelegate { func didpressColorChangeButton() func didMoveSlider() func didpressCreateRectangleButton() diff --git a/DrawingApp/DrawingApp/Sources/VC/ViewController.swift b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift index 6a4455b8..7d2f9d88 100644 --- a/DrawingApp/DrawingApp/Sources/VC/ViewController.swift +++ b/DrawingApp/DrawingApp/Sources/VC/ViewController.swift @@ -11,7 +11,7 @@ import OSLog class ViewController: UIViewController { @IBOutlet weak var canvas: UIView! - @IBOutlet weak var panel: Panel! + @IBOutlet weak var controlView: ControlView! private var plane = Plane() @@ -23,13 +23,13 @@ class ViewController: UIViewController { self.view.addSubview(canvas) plane.delegate = self - panel.delegate = self + controlView.delegate = self } } -extension ViewController: PanelDelegate { +extension ViewController: ControlViewDelegate { func didpressColorChangeButton() { print("") diff --git a/DrawingApp/DrawingApp/Sources/View/Panel.swift b/DrawingApp/DrawingApp/Sources/View/ControlView.swift similarity index 93% rename from DrawingApp/DrawingApp/Sources/View/Panel.swift rename to DrawingApp/DrawingApp/Sources/View/ControlView.swift index 9a762872..ab190fba 100644 --- a/DrawingApp/DrawingApp/Sources/View/Panel.swift +++ b/DrawingApp/DrawingApp/Sources/View/ControlView.swift @@ -7,9 +7,9 @@ import UIKit -class Panel: UIView { +class ControlView: UIView { - var delegate: PanelDelegate? + var delegate: ControlViewDelegate? required init?(coder: NSCoder) { super.init(coder: coder) diff --git a/DrawingApp/DrawingApp/Sources/View/Panel.xib b/DrawingApp/DrawingApp/Sources/View/ControlView.xib similarity index 98% rename from DrawingApp/DrawingApp/Sources/View/Panel.xib rename to DrawingApp/DrawingApp/Sources/View/ControlView.xib index da1df8d1..3bf13274 100644 --- a/DrawingApp/DrawingApp/Sources/View/Panel.xib +++ b/DrawingApp/DrawingApp/Sources/View/ControlView.xib @@ -6,7 +6,7 @@ - +