Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dale] - Step5 리턴타입 class -> protocol 변경 #92

Open
wants to merge 3 commits into
base: dale
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions DrawingApp/DrawingApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

/* Begin PBXBuildFile section */
6C0479CD27E06EEA00C5E1BF /* Clamping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0479CC27E06EEA00C5E1BF /* Clamping.swift */; };
6C0479D527E17B8100C5E1BF /* PhotoRectangle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0479D427E17B8100C5E1BF /* PhotoRectangle.swift */; };
6C0479D727E1A26B00C5E1BF /* Shape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0479D627E1A26B00C5E1BF /* Shape.swift */; };
6C0479D927E1B85D00C5E1BF /* ShapeViewAble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0479D827E1B85D00C5E1BF /* ShapeViewAble.swift */; };
6C0A105127D60B4600AC3272 /* PropertyChangeBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0A105027D60B4600AC3272 /* PropertyChangeBoard.swift */; };
6C0A105427D6F4F100AC3272 /* RectangleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0A105327D6F4F100AC3272 /* RectangleView.swift */; };
6C0A105627D73FAE00AC3272 /* RectangleViewBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0A105527D73FAE00AC3272 /* RectangleViewBoard.swift */; };
6C0A105627D73FAE00AC3272 /* ShapeViewBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0A105527D73FAE00AC3272 /* ShapeViewBoard.swift */; };
6C0A108A27DA202C00AC3272 /* RandomGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0A108927DA202C00AC3272 /* RandomGenerator.swift */; };
6C0A108C27DA372100AC3272 /* RectangleViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0A108B27DA372100AC3272 /* RectangleViewFactory.swift */; };
6C0A108C27DA372100AC3272 /* ShapeViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0A108B27DA372100AC3272 /* ShapeViewFactory.swift */; };
6C2F1DE027CCB4F80025803A /* Id.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2F1DDF27CCB4F80025803A /* Id.swift */; };
6C2F1DE427CCB7510025803A /* Position.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2F1DE327CCB7510025803A /* Position.swift */; };
6C2F1DE627CCBCA10025803A /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2F1DE527CCBCA10025803A /* Color.swift */; };
Expand All @@ -29,7 +32,7 @@
6CD0B2E927CC610F009F5E9E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CD0B2E827CC610F009F5E9E /* Assets.xcassets */; };
6CD0B2EC27CC610F009F5E9E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6CD0B2EA27CC610F009F5E9E /* LaunchScreen.storyboard */; };
6CD0B2F427CC6383009F5E9E /* Rectangle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD0B2F327CC6383009F5E9E /* Rectangle.swift */; };
6CD0B2F627CC6824009F5E9E /* RectangleFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD0B2F527CC6824009F5E9E /* RectangleFactory.swift */; };
6CD0B2F627CC6824009F5E9E /* ShapeFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD0B2F527CC6824009F5E9E /* ShapeFactory.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -44,11 +47,14 @@

/* Begin PBXFileReference section */
6C0479CC27E06EEA00C5E1BF /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = "<group>"; };
6C0479D427E17B8100C5E1BF /* PhotoRectangle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoRectangle.swift; sourceTree = "<group>"; };
6C0479D627E1A26B00C5E1BF /* Shape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shape.swift; sourceTree = "<group>"; };
6C0479D827E1B85D00C5E1BF /* ShapeViewAble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeViewAble.swift; sourceTree = "<group>"; };
6C0A105027D60B4600AC3272 /* PropertyChangeBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyChangeBoard.swift; sourceTree = "<group>"; };
6C0A105327D6F4F100AC3272 /* RectangleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RectangleView.swift; sourceTree = "<group>"; };
6C0A105527D73FAE00AC3272 /* RectangleViewBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RectangleViewBoard.swift; sourceTree = "<group>"; };
6C0A105527D73FAE00AC3272 /* ShapeViewBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeViewBoard.swift; sourceTree = "<group>"; };
6C0A108927DA202C00AC3272 /* RandomGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomGenerator.swift; sourceTree = "<group>"; };
6C0A108B27DA372100AC3272 /* RectangleViewFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RectangleViewFactory.swift; sourceTree = "<group>"; };
6C0A108B27DA372100AC3272 /* ShapeViewFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeViewFactory.swift; sourceTree = "<group>"; };
6C2F1DDF27CCB4F80025803A /* Id.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Id.swift; sourceTree = "<group>"; };
6C2F1DE327CCB7510025803A /* Position.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Position.swift; sourceTree = "<group>"; };
6C2F1DE527CCBCA10025803A /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
Expand All @@ -68,7 +74,7 @@
6CD0B2EB27CC610F009F5E9E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
6CD0B2ED27CC610F009F5E9E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6CD0B2F327CC6383009F5E9E /* Rectangle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rectangle.swift; sourceTree = "<group>"; };
6CD0B2F527CC6824009F5E9E /* RectangleFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RectangleFactory.swift; sourceTree = "<group>"; };
6CD0B2F527CC6824009F5E9E /* ShapeFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeFactory.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -94,12 +100,14 @@
isa = PBXGroup;
children = (
6CD0B2F327CC6383009F5E9E /* Rectangle.swift */,
6C0479D427E17B8100C5E1BF /* PhotoRectangle.swift */,
6C0479D627E1A26B00C5E1BF /* Shape.swift */,
6C373A0427D0938B00F29699 /* Plane.swift */,
6C0A108927DA202C00AC3272 /* RandomGenerator.swift */,
6C2F1DE527CCBCA10025803A /* Color.swift */,
6C0479CC27E06EEA00C5E1BF /* Clamping.swift */,
6C2F1DE327CCB7510025803A /* Position.swift */,
6CD0B2F527CC6824009F5E9E /* RectangleFactory.swift */,
6CD0B2F527CC6824009F5E9E /* ShapeFactory.swift */,
6C2F1DE927CCC15A0025803A /* Alpha.swift */,
6C2F1DE727CCBEE40025803A /* Size.swift */,
6C2F1DDF27CCB4F80025803A /* Id.swift */,
Expand All @@ -110,11 +118,12 @@
6C0A105227D6F11600AC3272 /* View */ = {
isa = PBXGroup;
children = (
6C0A105527D73FAE00AC3272 /* RectangleViewBoard.swift */,
6C0A105527D73FAE00AC3272 /* ShapeViewBoard.swift */,
6C5F3A0327DF38C7001BD523 /* PhotoRectangleView.swift */,
6C0A105027D60B4600AC3272 /* PropertyChangeBoard.swift */,
6C0A105327D6F4F100AC3272 /* RectangleView.swift */,
6C0A108B27DA372100AC3272 /* RectangleViewFactory.swift */,
6C0A105027D60B4600AC3272 /* PropertyChangeBoard.swift */,
6C0479D827E1B85D00C5E1BF /* ShapeViewAble.swift */,
6C0A108B27DA372100AC3272 /* ShapeViewFactory.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -280,11 +289,14 @@
buildActionMask = 2147483647;
files = (
6C2F1DE427CCB7510025803A /* Position.swift in Sources */,
6CD0B2F627CC6824009F5E9E /* RectangleFactory.swift in Sources */,
6CD0B2F627CC6824009F5E9E /* ShapeFactory.swift in Sources */,
6C0A108A27DA202C00AC3272 /* RandomGenerator.swift in Sources */,
6CD0B2E427CC610E009F5E9E /* ViewController.swift in Sources */,
6C2F1DE027CCB4F80025803A /* Id.swift in Sources */,
6C0479D727E1A26B00C5E1BF /* Shape.swift in Sources */,
6C0479D927E1B85D00C5E1BF /* ShapeViewAble.swift in Sources */,
6C2F1DE827CCBEE40025803A /* Size.swift in Sources */,
6C0479D527E17B8100C5E1BF /* PhotoRectangle.swift in Sources */,
6CD0B2E027CC610E009F5E9E /* AppDelegate.swift in Sources */,
6C2F1DEA27CCC15A0025803A /* Alpha.swift in Sources */,
6C0479CD27E06EEA00C5E1BF /* Clamping.swift in Sources */,
Expand All @@ -294,9 +306,9 @@
6C0A105427D6F4F100AC3272 /* RectangleView.swift in Sources */,
6CD0B2F427CC6383009F5E9E /* Rectangle.swift in Sources */,
6C0A105127D60B4600AC3272 /* PropertyChangeBoard.swift in Sources */,
6C0A108C27DA372100AC3272 /* RectangleViewFactory.swift in Sources */,
6C0A108C27DA372100AC3272 /* ShapeViewFactory.swift in Sources */,
6C373A0527D0938B00F29699 /* Plane.swift in Sources */,
6C0A105627D73FAE00AC3272 /* RectangleViewBoard.swift in Sources */,
6C0A105627D73FAE00AC3272 /* ShapeViewBoard.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
23 changes: 23 additions & 0 deletions DrawingApp/DrawingApp/Model/PhotoRectangle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// PhotoRectangle.swift
// DrawingApp
//
// Created by dale on 2022/03/16.
//

import Foundation

class PhotoRectangle: Shape{
var backgroundImage: Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

항상 속성은 private var를 우선적으로 고려하세요


init(size: Size, position: Position, imageData: Data, alpha: Alpha) {
self.backgroundImage = imageData
super.init(size: size, position: position, alpha: alpha)
}
}

extension PhotoRectangle : CustomStringConvertible{
var description: String {
return "(\(self.id)), \(position), \(self.size), \(self.backgroundImage) , \(self.alpha)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data 타입은 이렇게 description을 하는게 큰 의미는 없습니다. 존재하는지 혹은 크기가 바뀌는지 정도만 봐도 다행이죠

}
}
49 changes: 24 additions & 25 deletions DrawingApp/DrawingApp/Model/Plane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,59 @@
import Foundation

class Plane {
private var rectangles : [Rectangle] = []
private var selectedRectangle : Rectangle?
private var shapes : [Shape] = []
private var selectedShape : Shape?

enum NotificationName {
static let addRectangle : Notification.Name = Notification.Name("addRectangle")
static let searchRectangle : Notification.Name = Notification.Name("searchRectangle")
static let addShape : Notification.Name = Notification.Name("addShape")
static let searchShape : Notification.Name = Notification.Name("searchShape")
static let updateAlpha : Notification.Name = Notification.Name("updateAlpha")
static let changeColor : Notification.Name = Notification.Name("changeColor")
}

enum NotificationKeyValue {
static let rectangle = "rectangle"
static let shape = "shape"
static let index = "index"
static let alpha = "alpha"
static let color = "color"
}

subscript(index: Int) -> Rectangle? {
if index < rectangleCount {
let targetRectangle = rectangles[index]
return targetRectangle
subscript(index: Int) -> Shape? {
if index < shapeCount {
let targetShape = shapes[index]
return targetShape
}
return nil
}

var rectangleCount : Int {
return rectangles.count
var shapeCount : Int {
return shapes.count
}

func addRectangle(rectangle: Rectangle) {
self.rectangles.append(rectangle)
NotificationCenter.default.post(name: Plane.NotificationName.addRectangle, object: self, userInfo: [Plane.NotificationKeyValue.rectangle:rectangle])
func addShape(shape: Shape) {
self.shapes.append(shape)
NotificationCenter.default.post(name: Plane.NotificationName.addShape, object: self, userInfo: [Plane.NotificationKeyValue.shape:shape])
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 Plane에서는 addShape()할 때 생성의 책임이 여기 없네요
Plane이 모델을 생성하는 역할이 없는데, 외부에서 생성하는 게 적절할까요
아니면 여기서 생성하고 추가까지 하는게 적절할까요? 어떻게 생각하세요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plane에서 생성하는게 맞는것 같습니다. 처음 설계시 사각형을 만드는 팩토리메소드가 인스턴스메소드라 팩토리에 대한 인스턴스는 VC가 가지고 있어야 한다고 생각을 했는데, 현재 팩토리메소드가 타입메소드 형태로 바뀌어 Plane에서 생성할 수 있습니다.

}

func searchRectangle(at position : Position) {
self.selectedRectangle = nil
for rectangle in rectangles.reversed() {
if (rectangle.position.x...(rectangle.position.x + rectangle.size.width)).contains(position.x) && (rectangle.position.y...(rectangle.position.y + rectangle.size.height)).contains(position.y) {
self.selectedRectangle = rectangle
func searchShape(at position : Position) {
self.selectedShape = nil
for shape in shapes.reversed() {
if (shape.position.x...(shape.position.x + shape.size.width)).contains(position.x) && (shape.position.y...(shape.position.y + shape.size.height)).contains(position.y) {
self.selectedShape = shape
Comment on lines +48 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 부분도 shape의 속성을 가져와서 비교하는 게 아니라 shape.contains(x,y) 처럼 일을 시키면 좋을 것 같습니다.
카드 속성을 가져와서 비교하지 말고 카드 자체를 비교했던 것처럼요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정해보겠습니다!

break
}
}
guard let targetRectangle = selectedRectangle else {return}
NotificationCenter.default.post(name: Plane.NotificationName.searchRectangle, object: self, userInfo: [Plane.NotificationKeyValue.rectangle:targetRectangle])
NotificationCenter.default.post(name: Plane.NotificationName.searchShape, object: self, userInfo: [Plane.NotificationKeyValue.shape:self.selectedShape])
}

func updateAlphaValue(with alpha: Alpha) {
self.selectedRectangle?.alpha = alpha
self.selectedShape?.setAlpha(to: alpha)
NotificationCenter.default.post(name: Plane.NotificationName.updateAlpha, object: self, userInfo: [Plane.NotificationKeyValue.alpha:alpha])
}

func changeRandomColor(to randomColor : Color?) {
guard let randomColor = randomColor else {return}
self.selectedRectangle?.backgroundColor = randomColor
func changeRandomColor(to randomColor : Color) {
guard let rectangle = self.selectedShape as? Rectangle else {return}
rectangle.setBackgroundColor(to: randomColor)
NotificationCenter.default.post(name: Plane.NotificationName.changeColor, object: self, userInfo: [Plane.NotificationKeyValue.color:randomColor])
}
}
33 changes: 7 additions & 26 deletions DrawingApp/DrawingApp/Model/Rectangle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,21 @@

import Foundation

class Rectangle {
let id : Id = Id()
var size : Size
var position : Position
var backgroundColor : Color?
var backgroundImage: Data?
var alpha : Alpha
class Rectangle: Shape {
var backgroundColor : Color

init(size: Size, position : Position, color : Color?, alpha : Alpha) {
self.size = size
self.position = position
init(size: Size, position : Position, color : Color, alpha : Alpha) {
self.backgroundColor = color
self.alpha = alpha
super.init(size: size, position: position, alpha: alpha)
}

init(size: Size, position: Position, imageData: Data, alpha: Alpha) {
self.size = size
self.position = position
self.backgroundImage = imageData
self.alpha = alpha
func setBackgroundColor(to color: Color) {
self.backgroundColor = color
}

}

extension Rectangle : CustomStringConvertible, Equatable, Hashable {
static func == (lhs: Rectangle, rhs: Rectangle) -> Bool {
return ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
}

extension Rectangle : CustomStringConvertible{
var description: String {
return "(\(self.id)), \(position), \(self.size), \(String(describing: self.backgroundColor)) , \(self.alpha)"
}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
35 changes: 35 additions & 0 deletions DrawingApp/DrawingApp/Model/Shape.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ViewObject.swift
// DrawingApp
//
// Created by dale on 2022/03/16.
//

import Foundation

class Shape{
private(set) var id : Id = Id()
private(set) var size : Size
private(set) var position : Position
private(set) var alpha : Alpha

init(size: Size, position : Position, alpha : Alpha) {
self.size = size
self.position = position
self.alpha = alpha
}

func setAlpha(to alpha: Alpha) {
self.alpha = alpha
}
}

extension Shape: Equatable, Hashable {
Comment on lines +10 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어.. Shape가 프로토콜인 줄 알았는데 상위 클래스였네요. 상위 클래스가 있어도 되는데 프로토콜로 추상화할 부분도 시도해보세요.

static func == (lhs: Shape, rhs: Shape) -> Bool {
return ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shape 객체가 같다는 어떤 의미가 있을까요?
a. id만 같으면 같은 객체인가? 완전히 동일한 객체를 의미하는 것인가?
b. id는 다르지만 모든 속성이 동일하고 같은 위치에 있으면 같다고 할 수 있는가?
a와 b 경우에 대한 것을 구분할 수 있으면 좋습니다.

https://lucas.codesquad.kr/masters-2022/course/모바일-iOS-클래스/포커게임-앱/카드덱-구현하고-테스트하기

에 참고자료로 올라온 내용 중에 Identity와 Equality를 다시 확인해보세요.
ObjectIdentifier가 같다는 것은 어떤 것을 의미할까요?

그래서 질문은 == 연산으로 무엇을 비교하려고 하는 것인가, 그 의도가 중요한 것 같습니다. class 경우는 === 연산도 있는데 어떤 역할을 하려는 것인가 궁금합니다.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음 설계 당시에는 b와 같이 모든 속성이 동일하면 같다 라고 판단을 하였는데, 아주 적은 확률이라도 겹칠경우가 있어 두 도형의 참조값을 비교하는게 확실한 방법같아서 === 와 Objectidentifier사이에서 고민하게 되었습니다.
=== 연산의 경우 lhs rhs 로 옵셔널 값을 받아, nil 인경우도 비교를 하지만 Shape의 경우 nil을 가질수 없다고 판단하여 Objectidentifier를 사용하게 되었습니다.

}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

import Foundation

struct RectangleFactory {
struct ShapeFactory {

static func makeRandomRectangle(in screenSize : (Double,Double)) -> Rectangle? {
static func makeRandomShape(in screenSize : (Double,Double)) -> Shape? {
let randomPosition = RandomGenerator.generatePosition(screenSize: screenSize)
let randomColor = RandomGenerator.generateColor()
let randomAlpha = RandomGenerator.generateAlpha()

return Rectangle(size: Size(width: 150, height: 120), position: randomPosition, color: randomColor, alpha: randomAlpha)
}

static func makePhotoRectangle(in screenSize : (Double, Double), imageData: Data) -> Rectangle? {
static func makePhotoShape(in screenSize : (Double, Double), imageData: Data) -> Shape? {
Comment on lines +12 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

팩토리에서 생성하는 타입을 Shape 말고 프로토콜로도 추상화해보면 좋겠습니다.
아마도 서로 다른 역할이 있을 겁니다

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 추가로 추상화 진행해보겠습니다

let randomPosition = RandomGenerator.generatePosition(screenSize: screenSize)
let randomAlpha = RandomGenerator.generateAlpha()

return Rectangle(size: Size(width: 150, height: 120), position: randomPosition, imageData: imageData, alpha: randomAlpha)
return PhotoRectangle(size: Size(width: 150, height: 120), position: randomPosition, imageData: imageData, alpha: randomAlpha)
}


Expand Down
14 changes: 12 additions & 2 deletions DrawingApp/DrawingApp/View/PhotoRectangleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@

import UIKit

class PhotoRectangleView: RectangleView {
class PhotoRectangleView: UIView, ShapeViewAble {
private var photoImageView : UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleToFill
imageView.layer.borderColor = UIColor.blue.cgColor
return imageView
}()

init(from rectangleFrame: CGRect, imageData: Data, alpha: Alpha) {
super.init(frame: rectangleFrame, color: nil, alpha: alpha)
super.init(frame: rectangleFrame)
layoutImageView()
setImage(imageData: imageData)
setAlpha(alpha: alpha)
}

required init?(coder: NSCoder) {
Expand All @@ -33,6 +35,14 @@ class PhotoRectangleView: RectangleView {
photoImageView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
}

func borderVisible(_ enable : Bool) {
self.layer.borderWidth = enable ? 2 : 0
}

func setAlpha(alpha: Alpha) {
self.alpha = alpha.transparency
}

func setImage(imageData : Data) {
self.photoImageView.image = UIImage(data: imageData)
}
Expand Down
Loading