├── Behavioral Pattern
├── Chain of Responsibility
│ ├── Chain of Responsibility.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Chain of Responsibility
│ │ ├── Client
│ │ └── Client.swift
│ │ ├── Concrete Handler
│ │ ├── IPadServiceHandler.swift
│ │ ├── IPhoneServiceHandler.swift
│ │ ├── MainAppleServiceHandler.swift
│ │ └── MobileServiceHandler.swift
│ │ ├── Handler
│ │ └── CustomerServiceHandler.swift
│ │ └── main.swift
├── Command Pattern
│ ├── Command Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Command Pattern
│ │ ├── Command
│ │ └── Command.swift
│ │ ├── Concrete Command
│ │ ├── CopyCommand.swift
│ │ ├── PasteCommand.swift
│ │ └── WriteCommand.swift
│ │ ├── Invoker
│ │ └── Invoker.swift
│ │ ├── Receiver
│ │ └── TextEditor.swift
│ │ └── main.swift
├── Interpreter Pattern
│ ├── Interpreter Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ ├── xcdebugger
│ │ │ └── Breakpoints_v2.xcbkptlist
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Interpreter Pattern
│ │ └── main.swift
├── Iterator Pattern
│ ├── Iterator Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Iterator Pattern
│ │ └── main.swift
├── Mediator Pattern
│ ├── Mediator Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ ├── xcdebugger
│ │ │ └── Breakpoints_v2.xcbkptlist
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Mediator Pattern
│ │ ├── Colleague
│ │ ├── CheckBox.swift
│ │ ├── Colleague.swift
│ │ └── TextField.swift
│ │ ├── Concrete Mediator
│ │ └── ProfileUI.swift
│ │ ├── Mediator
│ │ └── Mediator.swift
│ │ └── main.swift
├── Memento Pattern
│ ├── Memento Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Memento Pattern
│ │ ├── Caretaker
│ │ └── GameDataSystem.swift
│ │ ├── Memento
│ │ └── SaveData.swift
│ │ ├── Originator
│ │ └── Game.swift
│ │ └── main.swift
├── Observer Pattern
│ ├── Observer Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Observer Pattern
│ │ ├── Concrete Observer(Subscriber)
│ │ └── Customer.swift
│ │ ├── Concrete Subject(Publisher)
│ │ └── AppleStore.swift
│ │ ├── Observer(Subscriber)
│ │ └── Observer.swift
│ │ ├── Subject(Publisher)
│ │ └── Publisher.swift
│ │ └── main.swift
├── State Pattern
│ ├── State Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── State Pattern
│ │ ├── Concrete State
│ │ ├── SubscribeState.swift
│ │ └── UnSubscribeState.swift
│ │ ├── Context
│ │ └── YoutubeApp.swift
│ │ ├── State
│ │ └── State.swift
│ │ └── main.swift
├── Strategy Pattern
│ ├── Strategy Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Strategy Pattern
│ │ ├── Concrete Strategy
│ │ ├── BikeRoute.swift
│ │ ├── CarRoute.swift
│ │ └── WalkRoute.swift
│ │ ├── Context
│ │ └── Navigation.swift
│ │ ├── Strategy
│ │ └── Strategy.swift
│ │ └── main.swift
├── Template Method Pattern
│ ├── Template Method Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Template Method Pattern
│ │ ├── Abstract Class
│ │ └── DataMining.swift
│ │ ├── Client
│ │ └── Client.swift
│ │ ├── Concrete Class
│ │ ├── ExcelFileDataMining.swift
│ │ ├── PDFFileDataMining.swift
│ │ └── WordFileDataMining.swift
│ │ └── main.swift
└── Visitor Pattern
│ ├── Visitor Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
│ └── Visitor Pattern
│ ├── Client
│ └── Client.swift
│ ├── Concrete Element
│ ├── Email.swift
│ ├── Push.swift
│ └── SMS.swift
│ ├── Concrete Visitor
│ ├── DayPolicyVisitor.swift
│ └── NightPolicyVisitor.swift
│ ├── Element
│ └── Notification.swift
│ ├── Visitor
│ └── NotificationPolicy.swift
│ └── main.swift
├── Creational Pattern
├── AbstractFactoryPattern
│ ├── AbstractFactoryPattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── AbstractFactoryPattern
│ │ ├── AbstractFactory
│ │ ├── Button.swift
│ │ ├── Label.swift
│ │ └── ViewAbstractFactory.swift
│ │ ├── Linux
│ │ ├── LinuxButton.swift
│ │ ├── LinuxLabel.swift
│ │ └── LinuxViewFactory.swift
│ │ ├── Mac
│ │ ├── MacButton.swift
│ │ ├── MacLabel.swift
│ │ └── MacViewFactory.swift
│ │ ├── ViewFactory.swift
│ │ ├── Window
│ │ ├── WindowButton.swift
│ │ ├── WindowLabel.swift
│ │ └── WindowViewFactory.swift
│ │ └── main.swift
├── Builder Pattern
│ ├── Builder Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Builder Pattern
│ │ ├── HambergerBuilder.swift
│ │ ├── Hamburger
│ │ ├── Bread.swift
│ │ ├── Hamberger.swift
│ │ ├── Meat.swift
│ │ ├── Sauce.swift
│ │ └── Vegetable.swift
│ │ ├── HamburgerDirector.swift
│ │ └── main.swift
├── Factory Method Pattern
│ ├── Factory Method Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ ├── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ │ │ └── pingu.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ ├── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ │ └── xcschememanagement.plist
│ │ │ └── pingu.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Factory Method Pattern
│ │ ├── Creator
│ │ ├── PlayerCreator.swift
│ │ └── PlayerFactory.swift
│ │ ├── Product
│ │ ├── MusicPlayer.swift
│ │ ├── Player.swift
│ │ └── VideoPlayer.swift
│ │ └── main.swift
├── Prototype Pattern
│ ├── Prototype Pattern.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ ├── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcuserdata
│ │ │ │ └── ick.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ └── Prototype Pattern
│ │ ├── Concrete Prototype
│ │ ├── Marin.swift
│ │ └── Medic.swift
│ │ ├── Prototype
│ │ └── Prototype.swift
│ │ └── main.swift
└── Singleton Pattern
│ ├── Singleton Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
│ └── Singleton Pattern
│ ├── Singleton.swift
│ └── main.swift
├── README.md
└── Structural Pattern
├── Adapter Pattern
├── Adapter Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── Adapter Pattern
│ ├── Adaptee
│ ├── KakaoLoginService.swift
│ └── NaverLoginService.swift
│ ├── Adapter
│ └── Adapters.swift
│ ├── Service
│ └── OriginalLoginService.swift
│ └── main.swift
├── Bridge Pattern
├── Bridge Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── Bridge Pattern
│ ├── Abstraction
│ ├── Abstraction.swift
│ └── Refined Abstraction.swift
│ ├── Implementor
│ ├── Concrete Implementor.swift
│ └── Implementor.swift
│ └── main.swift
├── Composite Pattern
├── Composite Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── Composite Pattern
│ ├── Component
│ └── Component.swift
│ ├── Composit
│ └── Directory.swift
│ ├── Leaf
│ ├── CodeFile.swift
│ └── MusicFile.swift
│ └── main.swift
├── Decorator Pattern
├── Decorator Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── Decorator Pattern
│ ├── Component
│ └── NotifierComponent.swift
│ ├── Concrete Component
│ └── Notifier.swift
│ ├── Concrete Decorator
│ ├── EmailDecorator.swift
│ └── SlackDecorator.swift
│ ├── Decorator
│ └── NotifierDecorator.swift
│ └── main.swift
├── Facade Pattern
├── Facade Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── Facade Pattern
│ ├── Facade
│ └── Facade.swift
│ ├── SubsystemClass
│ ├── AvailableProduct.swift
│ ├── Customer.swift
│ ├── OrderList.swift
│ └── Product.swift
│ └── main.swift
├── Flyweight Pattern
├── Flyweight Pattern.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── ick.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── Flyweight Pattern
│ ├── Flyweight
│ └── BulletFlyweight.swift
│ ├── FlyweightFactory
│ └── BulletFlyweightFactory.swift
│ ├── UnsharedConcreteFlyweight
│ └── Bullet.swift
│ └── main.swift
└── Proxy Pattern
├── Proxy Pattern.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ └── xcuserdata
│ │ └── ick.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ └── ick.xcuserdatad
│ └── xcschemes
│ └── xcschememanagement.plist
└── Proxy Pattern
├── Client
└── Client.swift
├── Proxy
└── YoutubeVideoProxy.swift
├── Real Subject
└── YoutubeVideo.swift
├── Subject(Service Interface)
└── YoutubeVideoService.swift
└── main.swift
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Chain of Responsibility.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility/Client/Client.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Client.swift
3 | // Chain of Responsibility
4 | //
5 | // Created by Ick on 2021/05/23.
6 | //
7 |
8 | import Foundation
9 | // Client
10 | class Client {
11 | private var firstHandler: CustomerServiceHandler?
12 |
13 | func request(request: String) -> String {
14 | return self.firstHandler?.handle(request: request) ?? "firstHandler를 설정해주세요"
15 | }
16 | func addHandler(handler: CustomerServiceHandler) {
17 | if let firstHandler = firstHandler {
18 | firstHandler.setNext(handler: handler)
19 | } else {
20 | self.firstHandler = handler
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility/Concrete Handler/IPadServiceHandler.swift:
--------------------------------------------------------------------------------
1 | //
2 | // IPadServiceHandler.swift
3 | // Chain of Responsibility
4 | //
5 | // Created by Ick on 2021/05/23.
6 | //
7 |
8 | import Foundation
9 | // Concrete Handler
10 | class IPadeServiceHandler: CustomerServiceHandler {
11 | var nextHandler: CustomerServiceHandler?
12 |
13 | func handle(request: String) -> String {
14 | if request == "iPad" {
15 | return "iPad 부서로 연결합니다."
16 | } else {
17 | if let response = nextHandler?.handle(request: request) {
18 | return response
19 | } else {
20 | return "원하시는 서비스는 제공하지 않습니다."
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility/Concrete Handler/IPhoneServiceHandler.swift:
--------------------------------------------------------------------------------
1 | //
2 | // IPhoneServiceHandler.swift
3 | // Chain of Responsibility
4 | //
5 | // Created by Ick on 2021/05/23.
6 | //
7 |
8 | import Foundation
9 | // Concrete Handler
10 | class IPhoneServiceHandler: CustomerServiceHandler {
11 | var nextHandler: CustomerServiceHandler?
12 |
13 | func handle(request: String) -> String {
14 | if request == "iPhone" {
15 | return "iPhone 부서로 연결합니다."
16 | } else {
17 | if let response = nextHandler?.handle(request: request) {
18 | return response
19 | } else {
20 | return "원하시는 서비스는 제공하지 않습니다."
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility/Concrete Handler/MainAppleServiceHandler.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MainAppleServiceHandler.swift
3 | // Chain of Responsibility
4 | //
5 | // Created by Ick on 2021/05/23.
6 | //
7 |
8 | import Foundation
9 | // Concrete Handler
10 | class MainAppleServiceHandler: CustomerServiceHandler {
11 | var nextHandler: CustomerServiceHandler?
12 |
13 | func handle(request: String) -> String {
14 | if request == "Apple" {
15 | return "Apple 부서로 연결합니다."
16 | } else {
17 | if let response = nextHandler?.handle(request: request) {
18 | return response
19 | } else {
20 | return "원하시는 서비스는 제공하지 않습니다."
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility/Concrete Handler/MobileServiceHandler.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MobileServiceHandler.swift
3 | // Chain of Responsibility
4 | //
5 | // Created by Ick on 2021/05/23.
6 | //
7 |
8 | import Foundation
9 | // Concrete Handler
10 | class MobileServiceHandler: CustomerServiceHandler {
11 | var nextHandler: CustomerServiceHandler?
12 |
13 | func handle(request: String) -> String {
14 | if request == "Mobile" {
15 | return "Mobile 부서로 연결합니다."
16 | } else {
17 | if let response = nextHandler?.handle(request: request) {
18 | return response
19 | } else {
20 | return "원하시는 서비스는 제공하지 않습니다."
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility/Handler/CustomerServiceHandler.swift:
--------------------------------------------------------------------------------
1 | //
2 | // CustomerServiceHandler.swift
3 | // Chain of Responsibility
4 | //
5 | // Created by Ick on 2021/05/23.
6 | //
7 |
8 | import Foundation
9 | // Handler
10 | protocol CustomerServiceHandler: class {
11 | var nextHandler: CustomerServiceHandler? { get set }
12 | func setNext(handler: CustomerServiceHandler)
13 | func handle(request: String) -> String
14 | }
15 |
16 | extension CustomerServiceHandler {
17 | func setNext(handler: CustomerServiceHandler) {
18 | if self.nextHandler == nil {
19 | self.nextHandler = handler
20 | } else {
21 | self.nextHandler?.setNext(handler: handler)
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Chain of Responsibility/Chain of Responsibility/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Chain of Responsibility
4 | //
5 | // Created by Ick on 2021/05/23.
6 | //
7 |
8 | import Foundation
9 |
10 | let client = Client()
11 |
12 | let appleService = MainAppleServiceHandler()
13 | let mobileService = MobileServiceHandler()
14 | let iPhoneService = IPhoneServiceHandler()
15 |
16 | client.addHandler(handler: appleService)
17 | client.addHandler(handler: mobileService)
18 | client.addHandler(handler: iPhoneService)
19 |
20 | print(client.request(request: "iPhone"))
21 | print(client.request(request: "iPad"))
22 |
23 | let iPadService = IPadeServiceHandler()
24 | client.addHandler(handler: iPadService)
25 | print(client.request(request: "iPad"))
26 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Command Pattern/Command Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Command Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern/Command/Command.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Command.swift
3 | // Command Pattern
4 | //
5 | // Created by Ick on 2021/05/25.
6 | //
7 |
8 | import Foundation
9 |
10 | // Command
11 | protocol Command {
12 | var receiver: TextEditor { get set }
13 | var backup: String { get set }
14 |
15 | func execute()
16 | func undo()
17 | }
18 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern/Concrete Command/CopyCommand.swift:
--------------------------------------------------------------------------------
1 | //
2 | // CopyCommand.swift
3 | // Command Pattern
4 | //
5 | // Created by Ick on 2021/05/25.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Command
11 | class CopyCommand: Command {
12 | var receiver: TextEditor
13 | var backup: String = ""
14 |
15 | init(receiver: TextEditor) {
16 | self.receiver = receiver
17 | }
18 |
19 | func undo() {
20 | receiver.clipboard = self.backup
21 | self.backup = ""
22 | }
23 |
24 | func execute() {
25 | self.backup = receiver.clipboard
26 | receiver.clipboard = receiver.text
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern/Concrete Command/PasteCommand.swift:
--------------------------------------------------------------------------------
1 | //
2 | // PasteCommand.swift
3 | // Command Pattern
4 | //
5 | // Created by Ick on 2021/05/25.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Command
11 | class PasteCommand: Command {
12 | var receiver: TextEditor
13 | var backup: String
14 |
15 | init(receiver: TextEditor) {
16 | self.receiver = receiver
17 | self.backup = self.receiver.clipboard
18 | }
19 |
20 | func undo() {
21 | let startIndex = receiver.text.startIndex
22 | let lastIndex = receiver.text.index(startIndex, offsetBy: receiver.text.count - backup.count)
23 | receiver.text = String(receiver.text[startIndex.. Command? {
19 | return history.popLast()
20 | }
21 |
22 | func executeCommand(command: Command) {
23 | command.execute()
24 | self.push(command: command)
25 | }
26 |
27 | func undoCommand() {
28 | let command = self.pop()
29 | if command == nil {
30 | print("되돌릴 작업이 없습니다.")
31 | } else {
32 | command?.undo()
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern/Receiver/TextEditor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TextEditor.swift
3 | // Command Pattern
4 | //
5 | // Created by Ick on 2021/05/25.
6 | //
7 |
8 | import Foundation
9 |
10 | // Receiver
11 | class TextEditor {
12 | var text: String = ""
13 | var clipboard: String = ""
14 | }
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Command Pattern/Command Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Command Pattern
4 | //
5 | // Created by Ick on 2021/05/24.
6 | //
7 |
8 | import Foundation
9 |
10 | let receiver = TextEditor()
11 | let invoker = Invoker()
12 |
13 | invoker.executeCommand(command: WriteCommand(receiver: receiver, backup: "ABC"))
14 | print(receiver.text) // ABC
15 | invoker.executeCommand(command: CopyCommand(receiver: receiver))
16 | invoker.executeCommand(command: PasteCommand(receiver: receiver)) // ABCABC
17 | print(receiver.text)
18 |
19 | invoker.executeCommand(command: WriteCommand(receiver: receiver, backup: "ZZZ")) // ABCABCZZZ
20 | print(receiver.text)
21 |
22 | invoker.executeCommand(command: PasteCommand(receiver: receiver)) // ABCABCZZZABC
23 | print(receiver.text)
24 |
25 | invoker.undoCommand() // ABCABCZZZ
26 | print(receiver.text)
27 |
28 | invoker.undoCommand()
29 | print(receiver.text) // ABCABC
30 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 60967C7226620DF3002C9A84 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60967C7126620DF3002C9A84 /* main.swift */; };
11 | /* End PBXBuildFile section */
12 |
13 | /* Begin PBXCopyFilesBuildPhase section */
14 | 60967C6C26620DF3002C9A84 /* CopyFiles */ = {
15 | isa = PBXCopyFilesBuildPhase;
16 | buildActionMask = 2147483647;
17 | dstPath = /usr/share/man/man1/;
18 | dstSubfolderSpec = 0;
19 | files = (
20 | );
21 | runOnlyForDeploymentPostprocessing = 1;
22 | };
23 | /* End PBXCopyFilesBuildPhase section */
24 |
25 | /* Begin PBXFileReference section */
26 | 60967C6E26620DF3002C9A84 /* Interpreter Pattern */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Interpreter Pattern"; sourceTree = BUILT_PRODUCTS_DIR; };
27 | 60967C7126620DF3002C9A84 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; };
28 | /* End PBXFileReference section */
29 |
30 | /* Begin PBXFrameworksBuildPhase section */
31 | 60967C6B26620DF3002C9A84 /* Frameworks */ = {
32 | isa = PBXFrameworksBuildPhase;
33 | buildActionMask = 2147483647;
34 | files = (
35 | );
36 | runOnlyForDeploymentPostprocessing = 0;
37 | };
38 | /* End PBXFrameworksBuildPhase section */
39 |
40 | /* Begin PBXGroup section */
41 | 60967C6526620DF3002C9A84 = {
42 | isa = PBXGroup;
43 | children = (
44 | 60967C7026620DF3002C9A84 /* Interpreter Pattern */,
45 | 60967C6F26620DF3002C9A84 /* Products */,
46 | );
47 | sourceTree = "";
48 | };
49 | 60967C6F26620DF3002C9A84 /* Products */ = {
50 | isa = PBXGroup;
51 | children = (
52 | 60967C6E26620DF3002C9A84 /* Interpreter Pattern */,
53 | );
54 | name = Products;
55 | sourceTree = "";
56 | };
57 | 60967C7026620DF3002C9A84 /* Interpreter Pattern */ = {
58 | isa = PBXGroup;
59 | children = (
60 | 60967C7126620DF3002C9A84 /* main.swift */,
61 | );
62 | path = "Interpreter Pattern";
63 | sourceTree = "";
64 | };
65 | /* End PBXGroup section */
66 |
67 | /* Begin PBXNativeTarget section */
68 | 60967C6D26620DF3002C9A84 /* Interpreter Pattern */ = {
69 | isa = PBXNativeTarget;
70 | buildConfigurationList = 60967C7526620DF3002C9A84 /* Build configuration list for PBXNativeTarget "Interpreter Pattern" */;
71 | buildPhases = (
72 | 60967C6A26620DF3002C9A84 /* Sources */,
73 | 60967C6B26620DF3002C9A84 /* Frameworks */,
74 | 60967C6C26620DF3002C9A84 /* CopyFiles */,
75 | );
76 | buildRules = (
77 | );
78 | dependencies = (
79 | );
80 | name = "Interpreter Pattern";
81 | productName = "Interpreter Pattern";
82 | productReference = 60967C6E26620DF3002C9A84 /* Interpreter Pattern */;
83 | productType = "com.apple.product-type.tool";
84 | };
85 | /* End PBXNativeTarget section */
86 |
87 | /* Begin PBXProject section */
88 | 60967C6626620DF3002C9A84 /* Project object */ = {
89 | isa = PBXProject;
90 | attributes = {
91 | LastSwiftUpdateCheck = 1200;
92 | LastUpgradeCheck = 1200;
93 | TargetAttributes = {
94 | 60967C6D26620DF3002C9A84 = {
95 | CreatedOnToolsVersion = 12.0.1;
96 | };
97 | };
98 | };
99 | buildConfigurationList = 60967C6926620DF3002C9A84 /* Build configuration list for PBXProject "Interpreter Pattern" */;
100 | compatibilityVersion = "Xcode 9.3";
101 | developmentRegion = en;
102 | hasScannedForEncodings = 0;
103 | knownRegions = (
104 | en,
105 | Base,
106 | );
107 | mainGroup = 60967C6526620DF3002C9A84;
108 | productRefGroup = 60967C6F26620DF3002C9A84 /* Products */;
109 | projectDirPath = "";
110 | projectRoot = "";
111 | targets = (
112 | 60967C6D26620DF3002C9A84 /* Interpreter Pattern */,
113 | );
114 | };
115 | /* End PBXProject section */
116 |
117 | /* Begin PBXSourcesBuildPhase section */
118 | 60967C6A26620DF3002C9A84 /* Sources */ = {
119 | isa = PBXSourcesBuildPhase;
120 | buildActionMask = 2147483647;
121 | files = (
122 | 60967C7226620DF3002C9A84 /* main.swift in Sources */,
123 | );
124 | runOnlyForDeploymentPostprocessing = 0;
125 | };
126 | /* End PBXSourcesBuildPhase section */
127 |
128 | /* Begin XCBuildConfiguration section */
129 | 60967C7326620DF3002C9A84 /* Debug */ = {
130 | isa = XCBuildConfiguration;
131 | buildSettings = {
132 | ALWAYS_SEARCH_USER_PATHS = NO;
133 | CLANG_ANALYZER_NONNULL = YES;
134 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
135 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
136 | CLANG_CXX_LIBRARY = "libc++";
137 | CLANG_ENABLE_MODULES = YES;
138 | CLANG_ENABLE_OBJC_ARC = YES;
139 | CLANG_ENABLE_OBJC_WEAK = YES;
140 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
141 | CLANG_WARN_BOOL_CONVERSION = YES;
142 | CLANG_WARN_COMMA = YES;
143 | CLANG_WARN_CONSTANT_CONVERSION = YES;
144 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
145 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
146 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
147 | CLANG_WARN_EMPTY_BODY = YES;
148 | CLANG_WARN_ENUM_CONVERSION = YES;
149 | CLANG_WARN_INFINITE_RECURSION = YES;
150 | CLANG_WARN_INT_CONVERSION = YES;
151 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
152 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
153 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
154 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
155 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
156 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
157 | CLANG_WARN_STRICT_PROTOTYPES = YES;
158 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
159 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
160 | CLANG_WARN_UNREACHABLE_CODE = YES;
161 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
162 | COPY_PHASE_STRIP = NO;
163 | DEBUG_INFORMATION_FORMAT = dwarf;
164 | ENABLE_STRICT_OBJC_MSGSEND = YES;
165 | ENABLE_TESTABILITY = YES;
166 | GCC_C_LANGUAGE_STANDARD = gnu11;
167 | GCC_DYNAMIC_NO_PIC = NO;
168 | GCC_NO_COMMON_BLOCKS = YES;
169 | GCC_OPTIMIZATION_LEVEL = 0;
170 | GCC_PREPROCESSOR_DEFINITIONS = (
171 | "DEBUG=1",
172 | "$(inherited)",
173 | );
174 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
175 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
176 | GCC_WARN_UNDECLARED_SELECTOR = YES;
177 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
178 | GCC_WARN_UNUSED_FUNCTION = YES;
179 | GCC_WARN_UNUSED_VARIABLE = YES;
180 | MACOSX_DEPLOYMENT_TARGET = 10.15;
181 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
182 | MTL_FAST_MATH = YES;
183 | ONLY_ACTIVE_ARCH = YES;
184 | SDKROOT = macosx;
185 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
186 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
187 | };
188 | name = Debug;
189 | };
190 | 60967C7426620DF3002C9A84 /* Release */ = {
191 | isa = XCBuildConfiguration;
192 | buildSettings = {
193 | ALWAYS_SEARCH_USER_PATHS = NO;
194 | CLANG_ANALYZER_NONNULL = YES;
195 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
196 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
197 | CLANG_CXX_LIBRARY = "libc++";
198 | CLANG_ENABLE_MODULES = YES;
199 | CLANG_ENABLE_OBJC_ARC = YES;
200 | CLANG_ENABLE_OBJC_WEAK = YES;
201 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
202 | CLANG_WARN_BOOL_CONVERSION = YES;
203 | CLANG_WARN_COMMA = YES;
204 | CLANG_WARN_CONSTANT_CONVERSION = YES;
205 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
206 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
207 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
208 | CLANG_WARN_EMPTY_BODY = YES;
209 | CLANG_WARN_ENUM_CONVERSION = YES;
210 | CLANG_WARN_INFINITE_RECURSION = YES;
211 | CLANG_WARN_INT_CONVERSION = YES;
212 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
213 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
214 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
215 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
216 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
217 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
218 | CLANG_WARN_STRICT_PROTOTYPES = YES;
219 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
220 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
221 | CLANG_WARN_UNREACHABLE_CODE = YES;
222 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
223 | COPY_PHASE_STRIP = NO;
224 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
225 | ENABLE_NS_ASSERTIONS = NO;
226 | ENABLE_STRICT_OBJC_MSGSEND = YES;
227 | GCC_C_LANGUAGE_STANDARD = gnu11;
228 | GCC_NO_COMMON_BLOCKS = YES;
229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
231 | GCC_WARN_UNDECLARED_SELECTOR = YES;
232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
233 | GCC_WARN_UNUSED_FUNCTION = YES;
234 | GCC_WARN_UNUSED_VARIABLE = YES;
235 | MACOSX_DEPLOYMENT_TARGET = 10.15;
236 | MTL_ENABLE_DEBUG_INFO = NO;
237 | MTL_FAST_MATH = YES;
238 | SDKROOT = macosx;
239 | SWIFT_COMPILATION_MODE = wholemodule;
240 | SWIFT_OPTIMIZATION_LEVEL = "-O";
241 | };
242 | name = Release;
243 | };
244 | 60967C7626620DF3002C9A84 /* Debug */ = {
245 | isa = XCBuildConfiguration;
246 | buildSettings = {
247 | CODE_SIGN_STYLE = Automatic;
248 | DEVELOPMENT_TEAM = 3K8FAYP34K;
249 | ENABLE_HARDENED_RUNTIME = YES;
250 | PRODUCT_NAME = "$(TARGET_NAME)";
251 | SWIFT_VERSION = 5.0;
252 | };
253 | name = Debug;
254 | };
255 | 60967C7726620DF3002C9A84 /* Release */ = {
256 | isa = XCBuildConfiguration;
257 | buildSettings = {
258 | CODE_SIGN_STYLE = Automatic;
259 | DEVELOPMENT_TEAM = 3K8FAYP34K;
260 | ENABLE_HARDENED_RUNTIME = YES;
261 | PRODUCT_NAME = "$(TARGET_NAME)";
262 | SWIFT_VERSION = 5.0;
263 | };
264 | name = Release;
265 | };
266 | /* End XCBuildConfiguration section */
267 |
268 | /* Begin XCConfigurationList section */
269 | 60967C6926620DF3002C9A84 /* Build configuration list for PBXProject "Interpreter Pattern" */ = {
270 | isa = XCConfigurationList;
271 | buildConfigurations = (
272 | 60967C7326620DF3002C9A84 /* Debug */,
273 | 60967C7426620DF3002C9A84 /* Release */,
274 | );
275 | defaultConfigurationIsVisible = 0;
276 | defaultConfigurationName = Release;
277 | };
278 | 60967C7526620DF3002C9A84 /* Build configuration list for PBXNativeTarget "Interpreter Pattern" */ = {
279 | isa = XCConfigurationList;
280 | buildConfigurations = (
281 | 60967C7626620DF3002C9A84 /* Debug */,
282 | 60967C7726620DF3002C9A84 /* Release */,
283 | );
284 | defaultConfigurationIsVisible = 0;
285 | defaultConfigurationName = Release;
286 | };
287 | /* End XCConfigurationList section */
288 | };
289 | rootObject = 60967C6626620DF3002C9A84 /* Project object */;
290 | }
291 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Interpreter Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Interpreter Pattern/Interpreter Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Interpreter Pattern
4 | //
5 | // Created by Ick on 2021/05/29.
6 | //
7 |
8 | import Foundation
9 |
10 | // 음,, 이 예제는 인터프리터 패턴이라고 하기엔 좀 부족한 부분이 있는 듯 하여 수정이 필요합니다.
11 |
12 | protocol IntegerExpression {
13 | func evaluate(_ context: IntegerContext) -> Int
14 | func replace(string: String, integerExpression: IntegerExpression) -> IntegerExpression
15 | func copied() -> IntegerExpression
16 | }
17 |
18 | final class IntegerContext {
19 | private var data: [String: Int] = [:]
20 | func lookup(name: String) -> Int {
21 | return self.data[name]!
22 | }
23 | func assign(expression: IntegerVariableExpression, value: Int) {
24 | self.data[expression.name] = value
25 | }
26 | }
27 |
28 | final class IntegerVariableExpression: IntegerExpression {
29 | let name: String
30 | init(name: String) {
31 | self.name = name
32 | }
33 | func evaluate(_ context: IntegerContext) -> Int {
34 | return context.lookup(name: self.name)
35 | }
36 |
37 | func replace(string: String, integerExpression: IntegerExpression) -> IntegerExpression {
38 | if name == self.name {
39 | return integerExpression.copied()
40 | } else {
41 | return IntegerVariableExpression(name: self.name)
42 | }
43 | }
44 |
45 | func copied() -> IntegerExpression {
46 | return IntegerVariableExpression(name: self.name)
47 | }
48 | }
49 |
50 | final class AddExpression: IntegerExpression {
51 | private var leftOperand: IntegerExpression
52 | private var rightOperand: IntegerExpression
53 |
54 | init(left: IntegerExpression, right: IntegerExpression) {
55 | self.leftOperand = left
56 | self.rightOperand = right
57 | }
58 | func evaluate(_ context: IntegerContext) -> Int {
59 | return self.leftOperand.evaluate(context) + self.rightOperand.evaluate(context)
60 | }
61 |
62 | func replace(string: String, integerExpression: IntegerExpression) -> IntegerExpression {
63 | return AddExpression(left: leftOperand.replace(string: string, integerExpression: integerExpression),
64 | right: rightOperand.replace(string: string, integerExpression: integerExpression))
65 | }
66 |
67 | func copied() -> IntegerExpression {
68 | return AddExpression(left: self.leftOperand, right: self.rightOperand)
69 | }
70 | }
71 |
72 | var context = IntegerContext()
73 |
74 | var a = IntegerVariableExpression(name: "a")
75 | var b = IntegerVariableExpression(name: "b")
76 | var c = IntegerVariableExpression(name: "c")
77 |
78 | var expression = AddExpression(left: a, right: AddExpression(left: b, right: c))
79 |
80 | context.assign(expression: a, value: 3)
81 | context.assign(expression: b, value: 2)
82 | context.assign(expression: c, value: 1)
83 |
84 | var result = expression.evaluate(context)
85 | print(result)
86 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Iterator Pattern/Iterator Pattern.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 60570CCE26637206005541B7 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60570CCD26637206005541B7 /* main.swift */; };
11 | /* End PBXBuildFile section */
12 |
13 | /* Begin PBXCopyFilesBuildPhase section */
14 | 60570CC826637206005541B7 /* CopyFiles */ = {
15 | isa = PBXCopyFilesBuildPhase;
16 | buildActionMask = 2147483647;
17 | dstPath = /usr/share/man/man1/;
18 | dstSubfolderSpec = 0;
19 | files = (
20 | );
21 | runOnlyForDeploymentPostprocessing = 1;
22 | };
23 | /* End PBXCopyFilesBuildPhase section */
24 |
25 | /* Begin PBXFileReference section */
26 | 60570CCA26637206005541B7 /* Iterator Pattern */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Iterator Pattern"; sourceTree = BUILT_PRODUCTS_DIR; };
27 | 60570CCD26637206005541B7 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; };
28 | /* End PBXFileReference section */
29 |
30 | /* Begin PBXFrameworksBuildPhase section */
31 | 60570CC726637206005541B7 /* Frameworks */ = {
32 | isa = PBXFrameworksBuildPhase;
33 | buildActionMask = 2147483647;
34 | files = (
35 | );
36 | runOnlyForDeploymentPostprocessing = 0;
37 | };
38 | /* End PBXFrameworksBuildPhase section */
39 |
40 | /* Begin PBXGroup section */
41 | 60570CC126637206005541B7 = {
42 | isa = PBXGroup;
43 | children = (
44 | 60570CCC26637206005541B7 /* Iterator Pattern */,
45 | 60570CCB26637206005541B7 /* Products */,
46 | );
47 | sourceTree = "";
48 | };
49 | 60570CCB26637206005541B7 /* Products */ = {
50 | isa = PBXGroup;
51 | children = (
52 | 60570CCA26637206005541B7 /* Iterator Pattern */,
53 | );
54 | name = Products;
55 | sourceTree = "";
56 | };
57 | 60570CCC26637206005541B7 /* Iterator Pattern */ = {
58 | isa = PBXGroup;
59 | children = (
60 | 60570CCD26637206005541B7 /* main.swift */,
61 | );
62 | path = "Iterator Pattern";
63 | sourceTree = "";
64 | };
65 | /* End PBXGroup section */
66 |
67 | /* Begin PBXNativeTarget section */
68 | 60570CC926637206005541B7 /* Iterator Pattern */ = {
69 | isa = PBXNativeTarget;
70 | buildConfigurationList = 60570CD126637206005541B7 /* Build configuration list for PBXNativeTarget "Iterator Pattern" */;
71 | buildPhases = (
72 | 60570CC626637206005541B7 /* Sources */,
73 | 60570CC726637206005541B7 /* Frameworks */,
74 | 60570CC826637206005541B7 /* CopyFiles */,
75 | );
76 | buildRules = (
77 | );
78 | dependencies = (
79 | );
80 | name = "Iterator Pattern";
81 | productName = "Iterator Pattern";
82 | productReference = 60570CCA26637206005541B7 /* Iterator Pattern */;
83 | productType = "com.apple.product-type.tool";
84 | };
85 | /* End PBXNativeTarget section */
86 |
87 | /* Begin PBXProject section */
88 | 60570CC226637206005541B7 /* Project object */ = {
89 | isa = PBXProject;
90 | attributes = {
91 | LastSwiftUpdateCheck = 1200;
92 | LastUpgradeCheck = 1200;
93 | TargetAttributes = {
94 | 60570CC926637206005541B7 = {
95 | CreatedOnToolsVersion = 12.0.1;
96 | };
97 | };
98 | };
99 | buildConfigurationList = 60570CC526637206005541B7 /* Build configuration list for PBXProject "Iterator Pattern" */;
100 | compatibilityVersion = "Xcode 9.3";
101 | developmentRegion = en;
102 | hasScannedForEncodings = 0;
103 | knownRegions = (
104 | en,
105 | Base,
106 | );
107 | mainGroup = 60570CC126637206005541B7;
108 | productRefGroup = 60570CCB26637206005541B7 /* Products */;
109 | projectDirPath = "";
110 | projectRoot = "";
111 | targets = (
112 | 60570CC926637206005541B7 /* Iterator Pattern */,
113 | );
114 | };
115 | /* End PBXProject section */
116 |
117 | /* Begin PBXSourcesBuildPhase section */
118 | 60570CC626637206005541B7 /* Sources */ = {
119 | isa = PBXSourcesBuildPhase;
120 | buildActionMask = 2147483647;
121 | files = (
122 | 60570CCE26637206005541B7 /* main.swift in Sources */,
123 | );
124 | runOnlyForDeploymentPostprocessing = 0;
125 | };
126 | /* End PBXSourcesBuildPhase section */
127 |
128 | /* Begin XCBuildConfiguration section */
129 | 60570CCF26637206005541B7 /* Debug */ = {
130 | isa = XCBuildConfiguration;
131 | buildSettings = {
132 | ALWAYS_SEARCH_USER_PATHS = NO;
133 | CLANG_ANALYZER_NONNULL = YES;
134 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
135 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
136 | CLANG_CXX_LIBRARY = "libc++";
137 | CLANG_ENABLE_MODULES = YES;
138 | CLANG_ENABLE_OBJC_ARC = YES;
139 | CLANG_ENABLE_OBJC_WEAK = YES;
140 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
141 | CLANG_WARN_BOOL_CONVERSION = YES;
142 | CLANG_WARN_COMMA = YES;
143 | CLANG_WARN_CONSTANT_CONVERSION = YES;
144 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
145 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
146 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
147 | CLANG_WARN_EMPTY_BODY = YES;
148 | CLANG_WARN_ENUM_CONVERSION = YES;
149 | CLANG_WARN_INFINITE_RECURSION = YES;
150 | CLANG_WARN_INT_CONVERSION = YES;
151 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
152 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
153 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
154 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
155 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
156 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
157 | CLANG_WARN_STRICT_PROTOTYPES = YES;
158 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
159 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
160 | CLANG_WARN_UNREACHABLE_CODE = YES;
161 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
162 | COPY_PHASE_STRIP = NO;
163 | DEBUG_INFORMATION_FORMAT = dwarf;
164 | ENABLE_STRICT_OBJC_MSGSEND = YES;
165 | ENABLE_TESTABILITY = YES;
166 | GCC_C_LANGUAGE_STANDARD = gnu11;
167 | GCC_DYNAMIC_NO_PIC = NO;
168 | GCC_NO_COMMON_BLOCKS = YES;
169 | GCC_OPTIMIZATION_LEVEL = 0;
170 | GCC_PREPROCESSOR_DEFINITIONS = (
171 | "DEBUG=1",
172 | "$(inherited)",
173 | );
174 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
175 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
176 | GCC_WARN_UNDECLARED_SELECTOR = YES;
177 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
178 | GCC_WARN_UNUSED_FUNCTION = YES;
179 | GCC_WARN_UNUSED_VARIABLE = YES;
180 | MACOSX_DEPLOYMENT_TARGET = 10.15;
181 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
182 | MTL_FAST_MATH = YES;
183 | ONLY_ACTIVE_ARCH = YES;
184 | SDKROOT = macosx;
185 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
186 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
187 | };
188 | name = Debug;
189 | };
190 | 60570CD026637206005541B7 /* Release */ = {
191 | isa = XCBuildConfiguration;
192 | buildSettings = {
193 | ALWAYS_SEARCH_USER_PATHS = NO;
194 | CLANG_ANALYZER_NONNULL = YES;
195 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
196 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
197 | CLANG_CXX_LIBRARY = "libc++";
198 | CLANG_ENABLE_MODULES = YES;
199 | CLANG_ENABLE_OBJC_ARC = YES;
200 | CLANG_ENABLE_OBJC_WEAK = YES;
201 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
202 | CLANG_WARN_BOOL_CONVERSION = YES;
203 | CLANG_WARN_COMMA = YES;
204 | CLANG_WARN_CONSTANT_CONVERSION = YES;
205 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
206 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
207 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
208 | CLANG_WARN_EMPTY_BODY = YES;
209 | CLANG_WARN_ENUM_CONVERSION = YES;
210 | CLANG_WARN_INFINITE_RECURSION = YES;
211 | CLANG_WARN_INT_CONVERSION = YES;
212 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
213 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
214 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
215 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
216 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
217 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
218 | CLANG_WARN_STRICT_PROTOTYPES = YES;
219 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
220 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
221 | CLANG_WARN_UNREACHABLE_CODE = YES;
222 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
223 | COPY_PHASE_STRIP = NO;
224 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
225 | ENABLE_NS_ASSERTIONS = NO;
226 | ENABLE_STRICT_OBJC_MSGSEND = YES;
227 | GCC_C_LANGUAGE_STANDARD = gnu11;
228 | GCC_NO_COMMON_BLOCKS = YES;
229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
231 | GCC_WARN_UNDECLARED_SELECTOR = YES;
232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
233 | GCC_WARN_UNUSED_FUNCTION = YES;
234 | GCC_WARN_UNUSED_VARIABLE = YES;
235 | MACOSX_DEPLOYMENT_TARGET = 10.15;
236 | MTL_ENABLE_DEBUG_INFO = NO;
237 | MTL_FAST_MATH = YES;
238 | SDKROOT = macosx;
239 | SWIFT_COMPILATION_MODE = wholemodule;
240 | SWIFT_OPTIMIZATION_LEVEL = "-O";
241 | };
242 | name = Release;
243 | };
244 | 60570CD226637206005541B7 /* Debug */ = {
245 | isa = XCBuildConfiguration;
246 | buildSettings = {
247 | CODE_SIGN_STYLE = Automatic;
248 | DEVELOPMENT_TEAM = 3K8FAYP34K;
249 | ENABLE_HARDENED_RUNTIME = YES;
250 | PRODUCT_NAME = "$(TARGET_NAME)";
251 | SWIFT_VERSION = 5.0;
252 | };
253 | name = Debug;
254 | };
255 | 60570CD326637206005541B7 /* Release */ = {
256 | isa = XCBuildConfiguration;
257 | buildSettings = {
258 | CODE_SIGN_STYLE = Automatic;
259 | DEVELOPMENT_TEAM = 3K8FAYP34K;
260 | ENABLE_HARDENED_RUNTIME = YES;
261 | PRODUCT_NAME = "$(TARGET_NAME)";
262 | SWIFT_VERSION = 5.0;
263 | };
264 | name = Release;
265 | };
266 | /* End XCBuildConfiguration section */
267 |
268 | /* Begin XCConfigurationList section */
269 | 60570CC526637206005541B7 /* Build configuration list for PBXProject "Iterator Pattern" */ = {
270 | isa = XCConfigurationList;
271 | buildConfigurations = (
272 | 60570CCF26637206005541B7 /* Debug */,
273 | 60570CD026637206005541B7 /* Release */,
274 | );
275 | defaultConfigurationIsVisible = 0;
276 | defaultConfigurationName = Release;
277 | };
278 | 60570CD126637206005541B7 /* Build configuration list for PBXNativeTarget "Iterator Pattern" */ = {
279 | isa = XCConfigurationList;
280 | buildConfigurations = (
281 | 60570CD226637206005541B7 /* Debug */,
282 | 60570CD326637206005541B7 /* Release */,
283 | );
284 | defaultConfigurationIsVisible = 0;
285 | defaultConfigurationName = Release;
286 | };
287 | /* End XCConfigurationList section */
288 | };
289 | rootObject = 60570CC226637206005541B7 /* Project object */;
290 | }
291 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Iterator Pattern/Iterator Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Iterator Pattern/Iterator Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Iterator Pattern/Iterator Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Iterator Pattern/Iterator Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Iterator Pattern/Iterator Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Iterator Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Iterator Pattern/Iterator Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Iterator Pattern
4 | //
5 | // Created by Ick on 2021/05/30.
6 | //
7 |
8 | import Foundation
9 |
10 | // Swift Sequence, IteratorProtocol에 대해 공부 하자!
11 | class WordsCollection {
12 | fileprivate lazy var items = [String]()
13 |
14 | func append(_ item: String) {
15 | self.items.append(item)
16 | }
17 | }
18 |
19 | extension WordsCollection: Sequence {
20 | func makeIterator() -> some IteratorProtocol {
21 | return WordsIterator(self)
22 | }
23 | }
24 |
25 | class WordsIterator: IteratorProtocol {
26 | private let collection: WordsCollection
27 | private var index: Int = 0
28 |
29 | init(_ collection: WordsCollection) {
30 | self.collection = collection
31 | }
32 |
33 | func next() -> String? {
34 | defer { index += 1}
35 | return self.index < self.collection.items.count ? collection.items[index] : nil
36 | }
37 | }
38 |
39 | class Client {
40 | static func clientCode(sequence: S) {
41 | for item in sequence {
42 | print(item)
43 | }
44 | }
45 | }
46 |
47 | let words = WordsCollection()
48 | words.append("First")
49 | words.append("Second")
50 | words.append("Third")
51 |
52 | Client.clientCode(sequence: words)
53 |
54 | enum IterationType {
55 | case inOrder
56 | case preOrder
57 | case postOrder
58 | }
59 |
60 | class Tree {
61 | var value: T
62 | var left: Tree?
63 | var right: Tree?
64 |
65 | init(_ value: T) {
66 | self.value = value
67 | }
68 |
69 | func iterator(_ type: IterationType) -> AnyIterator {
70 | var items = [T]()
71 | switch type {
72 | case .inOrder:
73 | inOrder { (item) in
74 | items.append(item)
75 | }
76 | case .preOrder:
77 | preOrder { (item) in
78 | items.append(item)
79 | }
80 | case .postOrder:
81 | postOrder { (item) in
82 | items.append(item)
83 | }
84 | }
85 | return AnyIterator(items.makeIterator())
86 | }
87 |
88 | private func inOrder(_ body: (T) -> ()) {
89 | left?.inOrder(body)
90 | body(value)
91 | right?.inOrder(body)
92 | }
93 | private func preOrder(_ body: (T) -> ()) {
94 | body(value)
95 | left?.preOrder(body)
96 | right?.preOrder(body)
97 | }
98 | private func postOrder(_ body: (T) -> ()) {
99 | left?.postOrder(body)
100 | right?.postOrder(body)
101 | body(value)
102 | }
103 | }
104 |
105 | let tree = Tree(1)
106 | tree.left = Tree(2)
107 | tree.right = Tree(3)
108 |
109 | tree.left?.left = Tree(4)
110 | tree.left?.right = Tree(5)
111 |
112 | tree.right?.left = Tree(6)
113 | tree.right?.right = Tree(7)
114 |
115 | class ClientC {
116 | static func clientCode(iterator: AnyIterator) {
117 | while case let item? = iterator.next() {
118 | print(item)
119 | }
120 | }
121 | }
122 | print("inOrder")
123 | ClientC.clientCode(iterator: tree.iterator(.inOrder))
124 | print("preOrder")
125 | ClientC.clientCode(iterator: tree.iterator(.preOrder))
126 | print("postOrder")
127 | ClientC.clientCode(iterator: tree.iterator(.postOrder))
128 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Mediator Pattern/Mediator Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Mediator Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern/Colleague/CheckBox.swift:
--------------------------------------------------------------------------------
1 | //
2 | // CheckBox.swift
3 | // Mediator Pattern
4 | //
5 | // Created by Ick on 2021/05/30.
6 | //
7 |
8 | import Foundation
9 |
10 | // Collegue
11 | class CheckBox: Colleague {
12 | var isSelect: Bool = false {
13 | didSet {
14 | if isSelect {
15 | print("CheckBox 선택")
16 | } else {
17 | print("CheckBox 선택 해제")
18 | }
19 | }
20 | }
21 |
22 | func checkBoxClick() {
23 | self.isSelect = !self.isSelect
24 | if self.isSelect {
25 | self.mediator?.notify(sender: self, event: .checkBoxSelect)
26 | } else {
27 | self.mediator?.notify(sender: self, event: .checkBoxUnselect)
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern/Colleague/Colleague.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Colleague.swift
3 | // Mediator Pattern
4 | //
5 | // Created by Ick on 2021/05/30.
6 | //
7 |
8 | import Foundation
9 |
10 | // Base Colleague
11 | class Colleague {
12 | var mediator: Mediator?
13 |
14 | func setMediator(mediator: Mediator) {
15 | self.mediator = mediator
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern/Colleague/TextField.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TextField.swift
3 | // Mediator Pattern
4 | //
5 | // Created by Ick on 2021/05/30.
6 | //
7 |
8 | import Foundation
9 |
10 | // Collegue
11 | class TextField: Colleague {
12 | var isHidden: Bool = true {
13 | didSet {
14 | if isHidden {
15 | print("TextField 비활성화")
16 | } else {
17 | print("TextField 활성화")
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern/Concrete Mediator/ProfileUI.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ProfileUI.swift
3 | // Mediator Pattern
4 | //
5 | // Created by Ick on 2021/05/30.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Mediator
11 | class ProfileUI: Mediator {
12 | var checkBox: CheckBox
13 | var textField: TextField
14 |
15 | init(checkBox: CheckBox, textField: TextField) {
16 | self.checkBox = checkBox
17 | self.textField = textField
18 |
19 | self.checkBox.setMediator(mediator: self)
20 | self.textField.setMediator(mediator: self)
21 | }
22 |
23 | func notify(sender: Colleague, event: EventType) {
24 | switch event {
25 | case .checkBoxSelect:
26 | self.textField.isHidden = false
27 | case .checkBoxUnselect:
28 | self.textField.isHidden = true
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern/Mediator/Mediator.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Mediator.swift
3 | // Mediator Pattern
4 | //
5 | // Created by Ick on 2021/05/30.
6 | //
7 |
8 | import Foundation
9 |
10 | // Mediator
11 | protocol Mediator {
12 | func notify(sender: Colleague, event: EventType)
13 | }
14 |
15 | enum EventType {
16 | case checkBoxSelect
17 | case checkBoxUnselect
18 | }
19 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Mediator Pattern/Mediator Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Mediator Pattern
4 | //
5 | // Created by Ick on 2021/05/30.
6 | //
7 |
8 | import Foundation
9 |
10 | let checkBox = CheckBox()
11 | let textField = TextField()
12 | let profileUI = ProfileUI(checkBox: checkBox, textField: textField)
13 |
14 | profileUI.checkBox.checkBoxClick()
15 | profileUI.checkBox.checkBoxClick()
16 |
17 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 60FA6AA5266CBD7A00B35EE0 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60FA6AA4266CBD7A00B35EE0 /* main.swift */; };
11 | 60FA6AB0266CC2EF00B35EE0 /* GameDataSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60FA6AAF266CC2EF00B35EE0 /* GameDataSystem.swift */; };
12 | 60FA6AB3266CC2F300B35EE0 /* Game.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60FA6AB2266CC2F300B35EE0 /* Game.swift */; };
13 | 60FA6AB6266CC2F900B35EE0 /* SaveData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60FA6AB5266CC2F900B35EE0 /* SaveData.swift */; };
14 | /* End PBXBuildFile section */
15 |
16 | /* Begin PBXCopyFilesBuildPhase section */
17 | 60FA6A9F266CBD7A00B35EE0 /* CopyFiles */ = {
18 | isa = PBXCopyFilesBuildPhase;
19 | buildActionMask = 2147483647;
20 | dstPath = /usr/share/man/man1/;
21 | dstSubfolderSpec = 0;
22 | files = (
23 | );
24 | runOnlyForDeploymentPostprocessing = 1;
25 | };
26 | /* End PBXCopyFilesBuildPhase section */
27 |
28 | /* Begin PBXFileReference section */
29 | 60FA6AA1266CBD7A00B35EE0 /* Memento Pattern */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Memento Pattern"; sourceTree = BUILT_PRODUCTS_DIR; };
30 | 60FA6AA4266CBD7A00B35EE0 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; };
31 | 60FA6AAF266CC2EF00B35EE0 /* GameDataSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameDataSystem.swift; sourceTree = ""; };
32 | 60FA6AB2266CC2F300B35EE0 /* Game.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Game.swift; sourceTree = ""; };
33 | 60FA6AB5266CC2F900B35EE0 /* SaveData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveData.swift; sourceTree = ""; };
34 | /* End PBXFileReference section */
35 |
36 | /* Begin PBXFrameworksBuildPhase section */
37 | 60FA6A9E266CBD7A00B35EE0 /* Frameworks */ = {
38 | isa = PBXFrameworksBuildPhase;
39 | buildActionMask = 2147483647;
40 | files = (
41 | );
42 | runOnlyForDeploymentPostprocessing = 0;
43 | };
44 | /* End PBXFrameworksBuildPhase section */
45 |
46 | /* Begin PBXGroup section */
47 | 60FA6A98266CBD7A00B35EE0 = {
48 | isa = PBXGroup;
49 | children = (
50 | 60FA6AA3266CBD7A00B35EE0 /* Memento Pattern */,
51 | 60FA6AA2266CBD7A00B35EE0 /* Products */,
52 | );
53 | sourceTree = "";
54 | };
55 | 60FA6AA2266CBD7A00B35EE0 /* Products */ = {
56 | isa = PBXGroup;
57 | children = (
58 | 60FA6AA1266CBD7A00B35EE0 /* Memento Pattern */,
59 | );
60 | name = Products;
61 | sourceTree = "";
62 | };
63 | 60FA6AA3266CBD7A00B35EE0 /* Memento Pattern */ = {
64 | isa = PBXGroup;
65 | children = (
66 | 60FA6AAC266CC2D400B35EE0 /* Originator */,
67 | 60FA6AAD266CC2DA00B35EE0 /* Memento */,
68 | 60FA6AAE266CC2DE00B35EE0 /* Caretaker */,
69 | 60FA6AA4266CBD7A00B35EE0 /* main.swift */,
70 | );
71 | path = "Memento Pattern";
72 | sourceTree = "";
73 | };
74 | 60FA6AAC266CC2D400B35EE0 /* Originator */ = {
75 | isa = PBXGroup;
76 | children = (
77 | 60FA6AB2266CC2F300B35EE0 /* Game.swift */,
78 | );
79 | path = Originator;
80 | sourceTree = "";
81 | };
82 | 60FA6AAD266CC2DA00B35EE0 /* Memento */ = {
83 | isa = PBXGroup;
84 | children = (
85 | 60FA6AB5266CC2F900B35EE0 /* SaveData.swift */,
86 | );
87 | path = Memento;
88 | sourceTree = "";
89 | };
90 | 60FA6AAE266CC2DE00B35EE0 /* Caretaker */ = {
91 | isa = PBXGroup;
92 | children = (
93 | 60FA6AAF266CC2EF00B35EE0 /* GameDataSystem.swift */,
94 | );
95 | path = Caretaker;
96 | sourceTree = "";
97 | };
98 | /* End PBXGroup section */
99 |
100 | /* Begin PBXNativeTarget section */
101 | 60FA6AA0266CBD7A00B35EE0 /* Memento Pattern */ = {
102 | isa = PBXNativeTarget;
103 | buildConfigurationList = 60FA6AA8266CBD7A00B35EE0 /* Build configuration list for PBXNativeTarget "Memento Pattern" */;
104 | buildPhases = (
105 | 60FA6A9D266CBD7A00B35EE0 /* Sources */,
106 | 60FA6A9E266CBD7A00B35EE0 /* Frameworks */,
107 | 60FA6A9F266CBD7A00B35EE0 /* CopyFiles */,
108 | );
109 | buildRules = (
110 | );
111 | dependencies = (
112 | );
113 | name = "Memento Pattern";
114 | productName = "Memento Pattern";
115 | productReference = 60FA6AA1266CBD7A00B35EE0 /* Memento Pattern */;
116 | productType = "com.apple.product-type.tool";
117 | };
118 | /* End PBXNativeTarget section */
119 |
120 | /* Begin PBXProject section */
121 | 60FA6A99266CBD7A00B35EE0 /* Project object */ = {
122 | isa = PBXProject;
123 | attributes = {
124 | LastSwiftUpdateCheck = 1200;
125 | LastUpgradeCheck = 1200;
126 | TargetAttributes = {
127 | 60FA6AA0266CBD7A00B35EE0 = {
128 | CreatedOnToolsVersion = 12.0.1;
129 | };
130 | };
131 | };
132 | buildConfigurationList = 60FA6A9C266CBD7A00B35EE0 /* Build configuration list for PBXProject "Memento Pattern" */;
133 | compatibilityVersion = "Xcode 9.3";
134 | developmentRegion = en;
135 | hasScannedForEncodings = 0;
136 | knownRegions = (
137 | en,
138 | Base,
139 | );
140 | mainGroup = 60FA6A98266CBD7A00B35EE0;
141 | productRefGroup = 60FA6AA2266CBD7A00B35EE0 /* Products */;
142 | projectDirPath = "";
143 | projectRoot = "";
144 | targets = (
145 | 60FA6AA0266CBD7A00B35EE0 /* Memento Pattern */,
146 | );
147 | };
148 | /* End PBXProject section */
149 |
150 | /* Begin PBXSourcesBuildPhase section */
151 | 60FA6A9D266CBD7A00B35EE0 /* Sources */ = {
152 | isa = PBXSourcesBuildPhase;
153 | buildActionMask = 2147483647;
154 | files = (
155 | 60FA6AB0266CC2EF00B35EE0 /* GameDataSystem.swift in Sources */,
156 | 60FA6AB3266CC2F300B35EE0 /* Game.swift in Sources */,
157 | 60FA6AB6266CC2F900B35EE0 /* SaveData.swift in Sources */,
158 | 60FA6AA5266CBD7A00B35EE0 /* main.swift in Sources */,
159 | );
160 | runOnlyForDeploymentPostprocessing = 0;
161 | };
162 | /* End PBXSourcesBuildPhase section */
163 |
164 | /* Begin XCBuildConfiguration section */
165 | 60FA6AA6266CBD7A00B35EE0 /* Debug */ = {
166 | isa = XCBuildConfiguration;
167 | buildSettings = {
168 | ALWAYS_SEARCH_USER_PATHS = NO;
169 | CLANG_ANALYZER_NONNULL = YES;
170 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
171 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
172 | CLANG_CXX_LIBRARY = "libc++";
173 | CLANG_ENABLE_MODULES = YES;
174 | CLANG_ENABLE_OBJC_ARC = YES;
175 | CLANG_ENABLE_OBJC_WEAK = YES;
176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
177 | CLANG_WARN_BOOL_CONVERSION = YES;
178 | CLANG_WARN_COMMA = YES;
179 | CLANG_WARN_CONSTANT_CONVERSION = YES;
180 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
182 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
183 | CLANG_WARN_EMPTY_BODY = YES;
184 | CLANG_WARN_ENUM_CONVERSION = YES;
185 | CLANG_WARN_INFINITE_RECURSION = YES;
186 | CLANG_WARN_INT_CONVERSION = YES;
187 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
188 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
189 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
190 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
191 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
192 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
193 | CLANG_WARN_STRICT_PROTOTYPES = YES;
194 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
195 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
196 | CLANG_WARN_UNREACHABLE_CODE = YES;
197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
198 | COPY_PHASE_STRIP = NO;
199 | DEBUG_INFORMATION_FORMAT = dwarf;
200 | ENABLE_STRICT_OBJC_MSGSEND = YES;
201 | ENABLE_TESTABILITY = YES;
202 | GCC_C_LANGUAGE_STANDARD = gnu11;
203 | GCC_DYNAMIC_NO_PIC = NO;
204 | GCC_NO_COMMON_BLOCKS = YES;
205 | GCC_OPTIMIZATION_LEVEL = 0;
206 | GCC_PREPROCESSOR_DEFINITIONS = (
207 | "DEBUG=1",
208 | "$(inherited)",
209 | );
210 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
211 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
212 | GCC_WARN_UNDECLARED_SELECTOR = YES;
213 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
214 | GCC_WARN_UNUSED_FUNCTION = YES;
215 | GCC_WARN_UNUSED_VARIABLE = YES;
216 | MACOSX_DEPLOYMENT_TARGET = 10.15;
217 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
218 | MTL_FAST_MATH = YES;
219 | ONLY_ACTIVE_ARCH = YES;
220 | SDKROOT = macosx;
221 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
222 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
223 | };
224 | name = Debug;
225 | };
226 | 60FA6AA7266CBD7A00B35EE0 /* Release */ = {
227 | isa = XCBuildConfiguration;
228 | buildSettings = {
229 | ALWAYS_SEARCH_USER_PATHS = NO;
230 | CLANG_ANALYZER_NONNULL = YES;
231 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
232 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
233 | CLANG_CXX_LIBRARY = "libc++";
234 | CLANG_ENABLE_MODULES = YES;
235 | CLANG_ENABLE_OBJC_ARC = YES;
236 | CLANG_ENABLE_OBJC_WEAK = YES;
237 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
238 | CLANG_WARN_BOOL_CONVERSION = YES;
239 | CLANG_WARN_COMMA = YES;
240 | CLANG_WARN_CONSTANT_CONVERSION = YES;
241 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
242 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
243 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
244 | CLANG_WARN_EMPTY_BODY = YES;
245 | CLANG_WARN_ENUM_CONVERSION = YES;
246 | CLANG_WARN_INFINITE_RECURSION = YES;
247 | CLANG_WARN_INT_CONVERSION = YES;
248 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
249 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
250 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
251 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
252 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
253 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
254 | CLANG_WARN_STRICT_PROTOTYPES = YES;
255 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
256 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
257 | CLANG_WARN_UNREACHABLE_CODE = YES;
258 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
259 | COPY_PHASE_STRIP = NO;
260 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
261 | ENABLE_NS_ASSERTIONS = NO;
262 | ENABLE_STRICT_OBJC_MSGSEND = YES;
263 | GCC_C_LANGUAGE_STANDARD = gnu11;
264 | GCC_NO_COMMON_BLOCKS = YES;
265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
267 | GCC_WARN_UNDECLARED_SELECTOR = YES;
268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
269 | GCC_WARN_UNUSED_FUNCTION = YES;
270 | GCC_WARN_UNUSED_VARIABLE = YES;
271 | MACOSX_DEPLOYMENT_TARGET = 10.15;
272 | MTL_ENABLE_DEBUG_INFO = NO;
273 | MTL_FAST_MATH = YES;
274 | SDKROOT = macosx;
275 | SWIFT_COMPILATION_MODE = wholemodule;
276 | SWIFT_OPTIMIZATION_LEVEL = "-O";
277 | };
278 | name = Release;
279 | };
280 | 60FA6AA9266CBD7A00B35EE0 /* Debug */ = {
281 | isa = XCBuildConfiguration;
282 | buildSettings = {
283 | CODE_SIGN_STYLE = Automatic;
284 | DEVELOPMENT_TEAM = 3K8FAYP34K;
285 | ENABLE_HARDENED_RUNTIME = YES;
286 | PRODUCT_NAME = "$(TARGET_NAME)";
287 | SWIFT_VERSION = 5.0;
288 | };
289 | name = Debug;
290 | };
291 | 60FA6AAA266CBD7A00B35EE0 /* Release */ = {
292 | isa = XCBuildConfiguration;
293 | buildSettings = {
294 | CODE_SIGN_STYLE = Automatic;
295 | DEVELOPMENT_TEAM = 3K8FAYP34K;
296 | ENABLE_HARDENED_RUNTIME = YES;
297 | PRODUCT_NAME = "$(TARGET_NAME)";
298 | SWIFT_VERSION = 5.0;
299 | };
300 | name = Release;
301 | };
302 | /* End XCBuildConfiguration section */
303 |
304 | /* Begin XCConfigurationList section */
305 | 60FA6A9C266CBD7A00B35EE0 /* Build configuration list for PBXProject "Memento Pattern" */ = {
306 | isa = XCConfigurationList;
307 | buildConfigurations = (
308 | 60FA6AA6266CBD7A00B35EE0 /* Debug */,
309 | 60FA6AA7266CBD7A00B35EE0 /* Release */,
310 | );
311 | defaultConfigurationIsVisible = 0;
312 | defaultConfigurationName = Release;
313 | };
314 | 60FA6AA8266CBD7A00B35EE0 /* Build configuration list for PBXNativeTarget "Memento Pattern" */ = {
315 | isa = XCConfigurationList;
316 | buildConfigurations = (
317 | 60FA6AA9266CBD7A00B35EE0 /* Debug */,
318 | 60FA6AAA266CBD7A00B35EE0 /* Release */,
319 | );
320 | defaultConfigurationIsVisible = 0;
321 | defaultConfigurationName = Release;
322 | };
323 | /* End XCConfigurationList section */
324 | };
325 | rootObject = 60FA6A99266CBD7A00B35EE0 /* Project object */;
326 | }
327 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Memento Pattern/Memento Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Memento Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern/Caretaker/GameDataSystem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // GameDataSystem.swift
3 | // Memento Pattern
4 | //
5 | // Created by Ick on 2021/06/06.
6 | //
7 |
8 | import Foundation
9 |
10 | // Caretaker
11 | class GameDataSystem {
12 | private var history: [SaveData] = []
13 |
14 | func save(snapshot: SaveData) {
15 | self.history.append(snapshot)
16 | }
17 |
18 | func load() {
19 | if let snapshot = self.history.popLast() {
20 | print("최근 저장 상태를 불러옵니다.\n")
21 | snapshot.load()
22 | } else {
23 | print("저장 기록이 없습니다.\n")
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern/Memento/SaveData.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SaveData.swift
3 | // Memento Pattern
4 | //
5 | // Created by Ick on 2021/06/06.
6 | //
7 |
8 | import Foundation
9 |
10 | // Memento
11 | class SaveData {
12 | var originator: Game
13 | var level: Int = 0
14 | var score: Int = 0
15 |
16 | init(originator: Game) {
17 | self.originator = originator
18 | self.level = originator.level
19 | self.score = originator.score
20 | }
21 |
22 | func load() {
23 | self.originator.setLevel(level: self.level)
24 | self.originator.setScore(score: self.score)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern/Originator/Game.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Game.swift
3 | // Memento Pattern
4 | //
5 | // Created by Ick on 2021/06/06.
6 | //
7 |
8 | import Foundation
9 |
10 | // Originator
11 | class Game {
12 | var level: Int = 0
13 | var score: Int = 0
14 |
15 | func setLevel(level: Int) {
16 | self.level = level
17 | }
18 |
19 | func setScore(score: Int) {
20 | self.score = score
21 | }
22 |
23 | func makeSnapshot() -> SaveData {
24 | print("Level : \(self.level), Score: \(self.score) 상태를 저장합니다.\n")
25 | return SaveData(originator: self)
26 | }
27 |
28 | func printCurrentState() {
29 | print("현재 상태 Level : \(self.level), Score: \(self.score)")
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Memento Pattern/Memento Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Memento Pattern
4 | //
5 | // Created by Ick on 2021/06/06.
6 | //
7 |
8 | import Foundation
9 |
10 | let originator = Game()
11 | let caretaker = GameDataSystem()
12 | originator.setLevel(level: 5)
13 | originator.setScore(score: 3)
14 |
15 | let memento = originator.makeSnapshot()
16 | caretaker.save(snapshot: memento)
17 |
18 | // 게임을 하다가 레벨과 점수가 이전 저장 했을 때 보다 낮아짐
19 | originator.setLevel(level: 1)
20 | originator.setScore(score: 1)
21 | originator.printCurrentState()
22 |
23 | // 복구하여 레벨과 점수 복구
24 | caretaker.load()
25 | originator.printCurrentState()
26 |
27 | caretaker.load()
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Observer Pattern/Observer Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Observer Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern/Concrete Observer(Subscriber)/Customer.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Customer.swift
3 | // Observer Pattern
4 | //
5 | // Created by Ick on 2021/06/28.
6 | //
7 |
8 | import Foundation
9 | // Concrete Observer(Subscriber)
10 | class Customer: Observer {
11 | var id: String
12 | init(id: String) {
13 | self.id = id
14 | }
15 | func update(message: String) {
16 | print("\(id)님 \(message)수신\n")
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern/Concrete Subject(Publisher)/AppleStore.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppleStore.swift
3 | // Observer Pattern
4 | //
5 | // Created by Ick on 2021/06/28.
6 | //
7 |
8 | import Foundation
9 | // Concrete Subject(Publisher)
10 | class AppleStore: Publisher {
11 | var observers: [Observer]
12 |
13 | init(observers: [Observer]) {
14 | self.observers = observers
15 | }
16 |
17 | func subscribe(observer: Observer) {
18 | self.observers.append(observer)
19 | }
20 |
21 | func unSubscribe(observer: Observer) {
22 | if let index = self.observers.firstIndex(where: { $0.id == observer.id }) {
23 | self.observers.remove(at: index)
24 | }
25 | }
26 |
27 | func notify(message: String) {
28 | for observer in observers {
29 | observer.update(message: message)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern/Observer(Subscriber)/Observer.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Observer.swift
3 | // Observer Pattern
4 | //
5 | // Created by Ick on 2021/06/28.
6 | //
7 |
8 | import Foundation
9 | // Observer(Subscriber) Interface
10 | protocol Observer {
11 | var id: String { get set }
12 | func update(message: String)
13 | }
14 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern/Subject(Publisher)/Publisher.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Publisher.swift
3 | // Observer Pattern
4 | //
5 | // Created by Ick on 2021/06/28.
6 | //
7 |
8 | import Foundation
9 | // Subject(Publisher) Interface
10 | protocol Publisher {
11 | var observers: [Observer] { get set }
12 | func subscribe(observer: Observer)
13 | func unSubscribe(observer: Observer)
14 | func notify(message: String)
15 | }
16 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Observer Pattern/Observer Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Observer Pattern
4 | //
5 | // Created by Ick on 2021/06/27.
6 | //
7 |
8 | import Foundation
9 |
10 | let appleStore = AppleStore(observers: [])
11 | let pingu = Customer(id: "Pingu")
12 | let pinga = Customer(id: "Pinga")
13 | let roby = Customer(id: "Roby")
14 | let ick = Customer(id: "Ick")
15 |
16 | appleStore.subscribe(observer: pingu)
17 | appleStore.subscribe(observer: roby)
18 |
19 | appleStore.notify(message: "iPhone 재고 입고!")
20 |
21 | appleStore.unSubscribe(observer: roby)
22 | appleStore.notify(message: "iPad 재고 입고!")
23 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/State Pattern/State Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | State Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern/Concrete State/SubscribeState.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SubscribeState.swift
3 | // State Pattern
4 | //
5 | // Created by Ick on 2021/06/29.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete State
11 | class SubscribeState : State {
12 | func playBackground() {
13 | print("결제를 해서 백그라운드에서도 재생중")
14 | }
15 | func playForeground() {
16 | print("영상 재생 중")
17 | }
18 | func videoDownload() {
19 | print("결제를 해서 비디오 다운로드 가능")
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern/Concrete State/UnSubscribeState.swift:
--------------------------------------------------------------------------------
1 | //
2 | // UnSubscribeState.swift
3 | // State Pattern
4 | //
5 | // Created by Ick on 2021/06/29.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete State
11 | class UnSubscribeState: State {
12 | func playBackground() {
13 | print("결제를 안하면 백그라운드에서는 재생 할 수 없어요.")
14 | }
15 | func playForeground() {
16 | print("영상 재생 중")
17 | }
18 | func videoDownload() {
19 | print("결제를 안하면 비디오 다운로드가 불가능해요.")
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern/Context/YoutubeApp.swift:
--------------------------------------------------------------------------------
1 | //
2 | // YoutubeApp.swift
3 | // State Pattern
4 | //
5 | // Created by Ick on 2021/06/29.
6 | //
7 |
8 | import Foundation
9 |
10 | // Context
11 | class YoutubeApp {
12 | var youtubePremiumState: State
13 |
14 | init(subscribeState: State) {
15 | self.youtubePremiumState = subscribeState
16 | }
17 |
18 | func subscribe() {
19 | print("\n유튜브 프리미엄 구독 시작\n")
20 | self.youtubePremiumState = SubscribeState()
21 | }
22 |
23 | func unSubscribe() {
24 | print("유튜브 프리미엄 구독 해지\n")
25 | self.youtubePremiumState = UnSubscribeState()
26 | }
27 |
28 | func clickHomeButton() {
29 | self.youtubePremiumState.playBackground()
30 | }
31 |
32 | func clickAppIcon() {
33 | self.youtubePremiumState.playForeground()
34 | }
35 |
36 | func clickDownload() {
37 | self.youtubePremiumState.videoDownload()
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern/State/State.swift:
--------------------------------------------------------------------------------
1 | //
2 | // State.swift
3 | // State Pattern
4 | //
5 | // Created by Ick on 2021/06/29.
6 | //
7 |
8 | import Foundation
9 |
10 | // State Interface
11 | protocol State {
12 | func playBackground()
13 | func playForeground()
14 | func videoDownload()
15 | }
16 |
--------------------------------------------------------------------------------
/Behavioral Pattern/State Pattern/State Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // State Pattern
4 | //
5 | // Created by Ick on 2021/06/28.
6 | //
7 |
8 | import Foundation
9 |
10 | let youtubeApp = YoutubeApp(subscribeState: UnSubscribeState())
11 |
12 | youtubeApp.clickAppIcon()
13 | youtubeApp.clickHomeButton()
14 | youtubeApp.clickDownload()
15 |
16 | youtubeApp.subscribe()
17 |
18 | youtubeApp.clickAppIcon()
19 | youtubeApp.clickHomeButton()
20 | youtubeApp.clickDownload()
21 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Strategy Pattern/Strategy Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Strategy Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern/Concrete Strategy/BikeRoute.swift:
--------------------------------------------------------------------------------
1 | //
2 | // BikeRoute.swift
3 | // Strategy Pattern
4 | //
5 | // Created by Ick on 2021/06/30.
6 | //
7 |
8 | import Foundation
9 | // Concrete Strategy
10 | class BikeRoute: Strategy {
11 | func algorithmExecute() {
12 | print("자전거 경로 찾기 완료!\n")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern/Concrete Strategy/CarRoute.swift:
--------------------------------------------------------------------------------
1 | //
2 | // CarRoute.swift
3 | // Strategy Pattern
4 | //
5 | // Created by Ick on 2021/06/30.
6 | //
7 |
8 | import Foundation
9 | // Concrete Strategy
10 | class CarRoute: Strategy {
11 | func algorithmExecute() {
12 | print("자동차 경로 찾기 완료!\n")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern/Concrete Strategy/WalkRoute.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WalkRoute.swift
3 | // Strategy Pattern
4 | //
5 | // Created by Ick on 2021/06/30.
6 | //
7 |
8 | import Foundation
9 | // Concrete Strategy
10 | class WalkRoute: Strategy {
11 | func algorithmExecute() {
12 | print("도보 경로 찾기 완료!\n")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern/Context/Navigation.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Navigation.swift
3 | // Strategy Pattern
4 | //
5 | // Created by Ick on 2021/06/30.
6 | //
7 |
8 | import Foundation
9 | // Context
10 | class Navigation {
11 | private var routeAlgorithm: Strategy?
12 |
13 | func execute() {
14 | self.routeAlgorithm?.algorithmExecute()
15 | }
16 |
17 | func setStrategy(strategy: Strategy) {
18 | self.routeAlgorithm = strategy
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern/Strategy/Strategy.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Strategy.swift
3 | // Strategy Pattern
4 | //
5 | // Created by Ick on 2021/06/30.
6 | //
7 |
8 | import Foundation
9 | // Strategy
10 | protocol Strategy {
11 | func algorithmExecute()
12 | }
13 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Strategy Pattern/Strategy Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Strategy Pattern
4 | //
5 | // Created by Ick on 2021/06/30.
6 | //
7 |
8 | import Foundation
9 |
10 | let navigation = Navigation()
11 | navigation.setStrategy(strategy: CarRoute())
12 | navigation.execute()
13 |
14 | navigation.setStrategy(strategy: WalkRoute())
15 | navigation.execute()
16 |
17 | navigation.setStrategy(strategy: BikeRoute())
18 | navigation.execute()
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Template Method Pattern/Template Method Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Template Method Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern/Abstract Class/DataMining.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DataMining.swift
3 | // Template Method Pattern
4 | //
5 | // Created by Ick on 2021/07/03.
6 | //
7 |
8 | import Foundation
9 | // Abstract Class
10 | class DataMining {
11 | final func dataMining() {
12 | getData()
13 | dataProcess()
14 | dataAnalysis()
15 | }
16 |
17 | func getData() {
18 | print("데이터를 불러옵니다.")
19 | }
20 | func dataProcess() {
21 | print("데이터 처리완료")
22 | }
23 | func dataAnalysis() {
24 | print("데이터 분석완료\n")
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern/Client/Client.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Client.swift
3 | // Template Method Pattern
4 | //
5 | // Created by Ick on 2021/07/03.
6 | //
7 |
8 | import Foundation
9 |
10 | enum FileType {
11 | case pdf
12 | case word
13 | case excel
14 | }
15 | class Client {
16 | static func dataMining(fileType: FileType) {
17 | switch fileType {
18 | case .pdf:
19 | PDFFileDataMining().dataMining()
20 | case .word:
21 | WordFileDataMining().dataMining()
22 | case .excel:
23 | ExcelFileDataMining().dataMining()
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern/Concrete Class/ExcelFileDataMining.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ExcelFileDataMining.swift
3 | // Template Method Pattern
4 | //
5 | // Created by Ick on 2021/07/03.
6 | //
7 |
8 | import Foundation
9 | // Concrete Method
10 | class ExcelFileDataMining: DataMining {
11 | override func getData() {
12 | print("Excel File 데이터를 불러옵니다.")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern/Concrete Class/PDFFileDataMining.swift:
--------------------------------------------------------------------------------
1 | //
2 | // PDFFileDataMining.swift
3 | // Template Method Pattern
4 | //
5 | // Created by Ick on 2021/07/03.
6 | //
7 |
8 | import Foundation
9 | // Concrete Method
10 | class PDFFileDataMining: DataMining {
11 | override func getData() {
12 | print("PDF File 데이터를 불러옵니다.")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern/Concrete Class/WordFileDataMining.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WordFileDataMining.swift
3 | // Template Method Pattern
4 | //
5 | // Created by Ick on 2021/07/03.
6 | //
7 |
8 | import Foundation
9 | // Concrete Method
10 | class WordFileDataMining: DataMining {
11 | override func getData() {
12 | print("Word File 데이터를 불러옵니다.")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Template Method Pattern/Template Method Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Template Method Pattern
4 | //
5 | // Created by Ick on 2021/07/03.
6 | //
7 |
8 | import Foundation
9 |
10 | Client.dataMining(fileType: .pdf)
11 | Client.dataMining(fileType: .word)
12 | Client.dataMining(fileType: .excel)
13 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Behavioral Pattern/Visitor Pattern/Visitor Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Visitor Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Client/Client.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Client.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 |
10 | class Client {
11 | func alert(notifications: [Notification], policy: NotificationPolicy) {
12 | print(policy.policyType)
13 | notifications.forEach { notitication in
14 | if notitication.accept(visitor: policy) {
15 | print("\(notitication.notificationType) notification send complete")
16 | } else {
17 | print("\(notitication.notificationType) notification can't send now")
18 | }
19 | }
20 | print("\n")
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Concrete Element/Email.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Email.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 | // Concrete Element
10 | class Email: Notification {
11 |
12 | let emailAddressOfSender: String
13 | var notificationType: String {
14 | return "Email"
15 | }
16 | init(emailAddressOfSender: String) {
17 | self.emailAddressOfSender = emailAddressOfSender
18 | }
19 |
20 | func accept(visitor: NotificationPolicy) -> Bool {
21 | visitor.isTurnedOn(for: self)
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Concrete Element/Push.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Push.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 | // Concrete Element
10 | class Push: Notification {
11 |
12 | let userIdOfSender: String
13 | var notificationType: String {
14 | return "Push"
15 | }
16 | init(userIdOfSender: String) {
17 | self.userIdOfSender = userIdOfSender
18 | }
19 |
20 | func accept(visitor: NotificationPolicy) -> Bool {
21 | visitor.isTurnedOn(for: self)
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Concrete Element/SMS.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SMS.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 | // Concrete Element
10 | class SMS: Notification {
11 |
12 | let phoneNumberOfSender: String
13 | var notificationType: String {
14 | return "SMS"
15 | }
16 | init(phoneNumberOfSender: String) {
17 | self.phoneNumberOfSender = phoneNumberOfSender
18 | }
19 |
20 | func accept(visitor: NotificationPolicy) -> Bool {
21 | visitor.isTurnedOn(for: self)
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Concrete Visitor/DayPolicyVisitor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DayPolicyVisitor.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 | // Concrete Visitor
10 | class DayPolicyVisitor: NotificationPolicy {
11 | var policyType: String {
12 | return "Day Policy"
13 | }
14 | func isTurnedOn(for email: Email) -> Bool {
15 | return true
16 | }
17 |
18 | func isTurnedOn(for sms: SMS) -> Bool {
19 | return true
20 | }
21 |
22 | func isTurnedOn(for push: Push) -> Bool {
23 | return true
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Concrete Visitor/NightPolicyVisitor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NightPolicyVisitor.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 | // Concrete Visitor
10 | class NightPolicyVisitor: NotificationPolicy {
11 | var policyType: String {
12 | return "Night Policy"
13 | }
14 | func isTurnedOn(for email: Email) -> Bool {
15 | return false
16 | }
17 |
18 | func isTurnedOn(for sms: SMS) -> Bool {
19 | return false
20 | }
21 |
22 | func isTurnedOn(for push: Push) -> Bool {
23 | return true
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Element/Notification.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Notification.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 | // Element Interface
10 | protocol Notification {
11 | var notificationType: String { get }
12 | func accept(visitor: NotificationPolicy) -> Bool
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/Visitor/NotificationPolicy.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NotificationPolicy.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 | // Visitor Interface
10 | protocol NotificationPolicy {
11 | var policyType: String { get }
12 | func isTurnedOn(for email: Email) -> Bool
13 | func isTurnedOn(for sms: SMS) -> Bool
14 | func isTurnedOn(for push: Push) -> Bool
15 | }
16 |
--------------------------------------------------------------------------------
/Behavioral Pattern/Visitor Pattern/Visitor Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Visitor Pattern
4 | //
5 | // Created by Ick on 2021/07/04.
6 | //
7 |
8 | import Foundation
9 |
10 | let client = Client()
11 | let emailNoti = Email(emailAddressOfSender: "pingu@pingu.com")
12 | let smsNoti = SMS(phoneNumberOfSender: "010-1111-1111")
13 | let pushNoti = Push(userIdOfSender: "pingu")
14 |
15 | client.alert(notifications: [emailNoti, smsNoti, pushNoti], policy: NightPolicyVisitor())
16 | client.alert(notifications: [emailNoti, smsNoti, pushNoti], policy: DayPolicyVisitor())
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | AbstractFactoryPattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/AbstractFactory/Button.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Button.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | protocol Button {
11 | func click()
12 | }
13 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/AbstractFactory/Label.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Label.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | protocol Label {
11 | var text: String { get set }
12 | }
13 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/AbstractFactory/ViewAbstractFactory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewAbstractFactory.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | protocol ViewAbstractFactory {
11 | func createButton() -> Button
12 | func createLabel() -> Label
13 | }
14 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Linux/LinuxButton.swift:
--------------------------------------------------------------------------------
1 | //
2 | // LinuxButton.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class LinuxButton: Button {
11 | func click() {
12 | print("Linux Button Click")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Linux/LinuxLabel.swift:
--------------------------------------------------------------------------------
1 | //
2 | // LinuxLabel.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class LinuxLabel: Label {
11 | var text: String
12 | init(text: String) {
13 | self.text = text
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Linux/LinuxViewFactory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // LinuxViewFactory.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class LinuxViewFactory: ViewAbstractFactory {
11 | func createButton() -> Button {
12 | return LinuxButton()
13 | }
14 | func createLabel() -> Label {
15 | return LinuxLabel(text: "Linux Label")
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Mac/MacButton.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MacButton.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class MacButton: Button {
11 | func click() {
12 | print("Mac Button Click!")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Mac/MacLabel.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MacLabel.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class MacLabel: Label {
11 | var text: String
12 | init(text: String) {
13 | self.text = text
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Mac/MacViewFactory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MacViewFactory.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class MacViewFactory: ViewAbstractFactory {
11 | func createButton() -> Button {
12 | return MacButton()
13 | }
14 |
15 | func createLabel() -> Label {
16 | return MacLabel(text: "Mac Label")
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/ViewFactory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewFactory.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class ViewFactory {
11 | public static var factory: ViewAbstractFactory {
12 | #if os(macOS)
13 | return MacViewFactory()
14 | #elseif os(Windows)
15 | return WindowViewFactory()
16 | #elseif os(Linux)
17 | return LinuxViewFactory()
18 | #endif
19 | }
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Window/WindowButton.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WindowButton.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class WindowButton: Button {
11 | func click() {
12 | print("Window Button Click!")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Window/WindowLabel.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WindowLabel.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class WindowLabel: Label {
11 | var text: String
12 | init(text: String) {
13 | self.text = text
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/Window/WindowViewFactory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WindowViewFactory.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | class WindowViewFactory: ViewAbstractFactory {
11 | func createButton() -> Button {
12 | return WindowButton()
13 | }
14 |
15 | func createLabel() -> Label {
16 | return WindowLabel(text: "Window Label")
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Creational Pattern/AbstractFactoryPattern/AbstractFactoryPattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // AbstractFactoryPattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | let factory = ViewFactory.factory
11 | let button = factory.createButton()
12 | let label = factory.createLabel()
13 |
14 | button.click()
15 | print(label.text)
16 |
17 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Creational Pattern/Builder Pattern/Builder Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Builder Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/HambergerBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // HambergerBuilder.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | public class HamburgerBuilder {
11 | public private(set) var meat: Meat = .beef
12 | public private(set) var sauces: Set = []
13 | public private(set) var vegetables: Set = []
14 | public private(set) var bread: Bread = .brownBread
15 |
16 | public func addSauce(_ sauce: Sauce) {
17 | sauces.insert(sauce)
18 | }
19 | public func removeSauce(_ sauce: Sauce) {
20 | sauces.remove(sauce)
21 | }
22 | public func addVegetable(_ vegetable: Vegetable) {
23 | vegetables.insert(vegetable)
24 | }
25 | public func removeVegetable(_ vegetable: Vegetable) {
26 | vegetables.remove(vegetable)
27 | }
28 | public func setMeat(_ meat: Meat) {
29 | self.meat = meat
30 | }
31 | public func setBread(_ bread: Bread) {
32 | self.bread = bread
33 | }
34 |
35 | public func build() -> Hamburger {
36 | return Hamburger(meat: meat, sauce: sauces, vegetable: vegetables, bread: bread)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/Hamburger/Bread.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Bread.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | public enum Bread: String {
11 | case brownBread
12 | case hotDogBun
13 | case mealBread
14 | case ryeBread
15 | }
16 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/Hamburger/Hamberger.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Hamberger.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | public struct Hamburger {
11 | public let meat: Meat
12 | public let sauce: Set
13 | public let vegetable: Set
14 | public let bread: Bread
15 |
16 | func getAllProperty() {
17 | print("Meat = \(meat)")
18 | print("Sauce = \(sauce)")
19 | print("Vegetable = \(vegetable)")
20 | print("Bread = \(bread)\n")
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/Hamburger/Meat.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Meat.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | public enum Meat: String {
11 | case beef
12 | case chicken
13 | case pork
14 | }
15 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/Hamburger/Sauce.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Sauce.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | public enum Sauce: String {
11 | case mayonnaise
12 | case mustard
13 | case ketchup
14 | case secret
15 | }
16 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/Hamburger/Vegetable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Vegetable.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | public enum Vegetable: String {
11 | case cabbage
12 | case lettuce
13 | case pickels
14 | case tomatoes
15 | }
16 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/HamburgerDirector.swift:
--------------------------------------------------------------------------------
1 | //
2 | // HamburgerDirector.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | class HamburgerDirector {
11 | public func createBeefBurger() -> Hamburger {
12 | let builder = HamburgerBuilder()
13 | builder.setMeat(.beef)
14 | builder.addSauce(.ketchup)
15 | builder.addSauce(.mustard)
16 | builder.addVegetable(.pickels)
17 | builder.addVegetable(.lettuce)
18 | builder.setBread(.ryeBread)
19 | return builder.build()
20 | }
21 | public func createChickenBurger() -> Hamburger {
22 | let builder = HamburgerBuilder()
23 | builder.setMeat(.chicken)
24 | builder.addSauce(.secret)
25 | builder.addSauce(.mayonnaise)
26 | builder.addVegetable(.cabbage)
27 | builder.addVegetable(.tomatoes)
28 | builder.setBread(.brownBread)
29 | return builder.build()
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Creational Pattern/Builder Pattern/Builder Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Builder Pattern
4 | //
5 | // Created by Ick on 2021/05/08.
6 | //
7 |
8 | import Foundation
9 |
10 | let builder = HamburgerBuilder()
11 | var hamburger = builder.build()
12 | print("첫번째 버거")
13 | hamburger.getAllProperty()
14 |
15 | print("두번째 버거")
16 | builder.setMeat(.chicken)
17 | builder.setBread(.hotDogBun)
18 | builder.addSauce(.secret)
19 | builder.addVegetable(.cabbage)
20 | hamburger = builder.build()
21 | hamburger.getAllProperty()
22 |
23 | let director = HamburgerDirector()
24 | print("Director가 만든 비프버거")
25 | hamburger = director.createBeefBurger()
26 | hamburger.getAllProperty()
27 |
28 | var hamburgerWithoutBuilder = Hamburger(meat: .beef,
29 | sauce: [.ketchup],
30 | vegetable: [.cabbage],
31 | bread: .brownBread)
32 | print("빌더 없이 직접 만든 수제버거")
33 | hamburgerWithoutBuilder.getAllProperty()
34 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/project.xcworkspace/xcuserdata/pingu.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/project.xcworkspace/xcuserdata/pingu.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Factory Method Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern.xcodeproj/xcuserdata/pingu.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Factory Method Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern/Creator/PlayerCreator.swift:
--------------------------------------------------------------------------------
1 | //
2 | // PlayerCreator.swift
3 | // Factory Method Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 | // Creator
10 | protocol PlayerCreator {
11 | func createPlayer(content: String) -> Player
12 | }
13 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern/Creator/PlayerFactory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // PlayerFactory.swift
3 | // Factory Method Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | // Factory (Concrete Creator)
11 | struct MusicPlayerFactory: PlayerCreator {
12 | func createPlayer(content: String) -> Player {
13 | return MusicPlayer(content: content)
14 | }
15 | }
16 |
17 | struct VideoPlayerFactory: PlayerCreator {
18 | func createPlayer(content: String) -> Player {
19 | return VideoPlayer(content: content)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern/Product/MusicPlayer.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MusicPlayer.swift
3 | // Factory Method Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 | // Concrete Product
10 | class MusicPlayer: Player {
11 | var content: String
12 | required init(content: String) {
13 | self.content = content
14 | }
15 |
16 | func play() {
17 | print("MusicPlayer Play")
18 | }
19 |
20 | func pause() {
21 | print("MusicPlayer Pause")
22 | }
23 |
24 | func changeContent(name: String) {
25 | print("\(self.content)에서 \(name)로 음악 변경\n")
26 | self.content = name
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern/Product/Player.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Player.swift
3 | // Factory Method Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | // Product Interface
11 | protocol Player {
12 | var content: String { get set }
13 | init(content: String)
14 | func play()
15 | func pause()
16 | func changeContent(name: String)
17 | }
18 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern/Product/VideoPlayer.swift:
--------------------------------------------------------------------------------
1 | //
2 | // VideoPlayer.swift
3 | // Factory Method Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Product
11 | class VideoPlayer: Player {
12 | var content: String
13 | required init(content: String) {
14 | self.content = content
15 | }
16 |
17 | func play() {
18 | print("VideoPlayer Play")
19 | }
20 |
21 | func pause() {
22 | print("VideoPlayer Pause")
23 | }
24 |
25 | func changeContent(name: String) {
26 | print("\(self.content)에서 \(name)로 비디오 변경\n")
27 | self.content = name
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Creational Pattern/Factory Method Pattern/Factory Method Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Factory Method Pattern
4 | //
5 | // Created by Ick on 2021/05/09.
6 | //
7 |
8 | import Foundation
9 |
10 | struct Client {
11 | func getPlayer(
12 | with factory: PlayerCreator,
13 | content: String
14 | ) -> Player {
15 | return factory.createPlayer(content: content)
16 | }
17 | }
18 |
19 | let client = Client()
20 |
21 | let musicPlayer = client.getPlayer(with: MusicPlayerFactory(), content: "핑구 BGM")
22 | let videoPlayer = client.getPlayer(with: VideoPlayerFactory(), content: "핑구 비디오")
23 |
24 | musicPlayer.play()
25 | musicPlayer.changeContent(name: "에스파 노래")
26 |
27 | videoPlayer.pause()
28 | videoPlayer.changeContent(name: "어벤져스")
29 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 6099FECA264971D8001729BF /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6099FEC9264971D8001729BF /* main.swift */; };
11 | 6099FED2264971ED001729BF /* Prototype.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6099FED1264971ED001729BF /* Prototype.swift */; };
12 | 6099FED726498AE9001729BF /* Marin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6099FED626498AE9001729BF /* Marin.swift */; };
13 | 6099FEDB26498AEC001729BF /* Medic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6099FEDA26498AEC001729BF /* Medic.swift */; };
14 | /* End PBXBuildFile section */
15 |
16 | /* Begin PBXCopyFilesBuildPhase section */
17 | 6099FEC4264971D8001729BF /* CopyFiles */ = {
18 | isa = PBXCopyFilesBuildPhase;
19 | buildActionMask = 2147483647;
20 | dstPath = /usr/share/man/man1/;
21 | dstSubfolderSpec = 0;
22 | files = (
23 | );
24 | runOnlyForDeploymentPostprocessing = 1;
25 | };
26 | /* End PBXCopyFilesBuildPhase section */
27 |
28 | /* Begin PBXFileReference section */
29 | 6099FEC6264971D8001729BF /* Prototype Pattern */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Prototype Pattern"; sourceTree = BUILT_PRODUCTS_DIR; };
30 | 6099FEC9264971D8001729BF /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; };
31 | 6099FED1264971ED001729BF /* Prototype.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Prototype.swift; sourceTree = ""; };
32 | 6099FED626498AE9001729BF /* Marin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Marin.swift; sourceTree = ""; };
33 | 6099FEDA26498AEC001729BF /* Medic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Medic.swift; sourceTree = ""; };
34 | /* End PBXFileReference section */
35 |
36 | /* Begin PBXFrameworksBuildPhase section */
37 | 6099FEC3264971D8001729BF /* Frameworks */ = {
38 | isa = PBXFrameworksBuildPhase;
39 | buildActionMask = 2147483647;
40 | files = (
41 | );
42 | runOnlyForDeploymentPostprocessing = 0;
43 | };
44 | /* End PBXFrameworksBuildPhase section */
45 |
46 | /* Begin PBXGroup section */
47 | 6099FEBD264971D8001729BF = {
48 | isa = PBXGroup;
49 | children = (
50 | 6099FEC8264971D8001729BF /* Prototype Pattern */,
51 | 6099FEC7264971D8001729BF /* Products */,
52 | );
53 | sourceTree = "";
54 | };
55 | 6099FEC7264971D8001729BF /* Products */ = {
56 | isa = PBXGroup;
57 | children = (
58 | 6099FEC6264971D8001729BF /* Prototype Pattern */,
59 | );
60 | name = Products;
61 | sourceTree = "";
62 | };
63 | 6099FEC8264971D8001729BF /* Prototype Pattern */ = {
64 | isa = PBXGroup;
65 | children = (
66 | 6099FED526498ADD001729BF /* Concrete Prototype */,
67 | 6099FED426498AD5001729BF /* Prototype */,
68 | 6099FEC9264971D8001729BF /* main.swift */,
69 | );
70 | path = "Prototype Pattern";
71 | sourceTree = "";
72 | };
73 | 6099FED426498AD5001729BF /* Prototype */ = {
74 | isa = PBXGroup;
75 | children = (
76 | 6099FED1264971ED001729BF /* Prototype.swift */,
77 | );
78 | path = Prototype;
79 | sourceTree = "";
80 | };
81 | 6099FED526498ADD001729BF /* Concrete Prototype */ = {
82 | isa = PBXGroup;
83 | children = (
84 | 6099FED626498AE9001729BF /* Marin.swift */,
85 | 6099FEDA26498AEC001729BF /* Medic.swift */,
86 | );
87 | path = "Concrete Prototype";
88 | sourceTree = "";
89 | };
90 | /* End PBXGroup section */
91 |
92 | /* Begin PBXNativeTarget section */
93 | 6099FEC5264971D8001729BF /* Prototype Pattern */ = {
94 | isa = PBXNativeTarget;
95 | buildConfigurationList = 6099FECD264971D8001729BF /* Build configuration list for PBXNativeTarget "Prototype Pattern" */;
96 | buildPhases = (
97 | 6099FEC2264971D8001729BF /* Sources */,
98 | 6099FEC3264971D8001729BF /* Frameworks */,
99 | 6099FEC4264971D8001729BF /* CopyFiles */,
100 | );
101 | buildRules = (
102 | );
103 | dependencies = (
104 | );
105 | name = "Prototype Pattern";
106 | productName = "Prototype Pattern";
107 | productReference = 6099FEC6264971D8001729BF /* Prototype Pattern */;
108 | productType = "com.apple.product-type.tool";
109 | };
110 | /* End PBXNativeTarget section */
111 |
112 | /* Begin PBXProject section */
113 | 6099FEBE264971D8001729BF /* Project object */ = {
114 | isa = PBXProject;
115 | attributes = {
116 | LastSwiftUpdateCheck = 1200;
117 | LastUpgradeCheck = 1200;
118 | TargetAttributes = {
119 | 6099FEC5264971D8001729BF = {
120 | CreatedOnToolsVersion = 12.0.1;
121 | };
122 | };
123 | };
124 | buildConfigurationList = 6099FEC1264971D8001729BF /* Build configuration list for PBXProject "Prototype Pattern" */;
125 | compatibilityVersion = "Xcode 9.3";
126 | developmentRegion = en;
127 | hasScannedForEncodings = 0;
128 | knownRegions = (
129 | en,
130 | Base,
131 | );
132 | mainGroup = 6099FEBD264971D8001729BF;
133 | productRefGroup = 6099FEC7264971D8001729BF /* Products */;
134 | projectDirPath = "";
135 | projectRoot = "";
136 | targets = (
137 | 6099FEC5264971D8001729BF /* Prototype Pattern */,
138 | );
139 | };
140 | /* End PBXProject section */
141 |
142 | /* Begin PBXSourcesBuildPhase section */
143 | 6099FEC2264971D8001729BF /* Sources */ = {
144 | isa = PBXSourcesBuildPhase;
145 | buildActionMask = 2147483647;
146 | files = (
147 | 6099FEDB26498AEC001729BF /* Medic.swift in Sources */,
148 | 6099FED2264971ED001729BF /* Prototype.swift in Sources */,
149 | 6099FED726498AE9001729BF /* Marin.swift in Sources */,
150 | 6099FECA264971D8001729BF /* main.swift in Sources */,
151 | );
152 | runOnlyForDeploymentPostprocessing = 0;
153 | };
154 | /* End PBXSourcesBuildPhase section */
155 |
156 | /* Begin XCBuildConfiguration section */
157 | 6099FECB264971D8001729BF /* Debug */ = {
158 | isa = XCBuildConfiguration;
159 | buildSettings = {
160 | ALWAYS_SEARCH_USER_PATHS = NO;
161 | CLANG_ANALYZER_NONNULL = YES;
162 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
163 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
164 | CLANG_CXX_LIBRARY = "libc++";
165 | CLANG_ENABLE_MODULES = YES;
166 | CLANG_ENABLE_OBJC_ARC = YES;
167 | CLANG_ENABLE_OBJC_WEAK = YES;
168 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
169 | CLANG_WARN_BOOL_CONVERSION = YES;
170 | CLANG_WARN_COMMA = YES;
171 | CLANG_WARN_CONSTANT_CONVERSION = YES;
172 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
173 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
174 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
175 | CLANG_WARN_EMPTY_BODY = YES;
176 | CLANG_WARN_ENUM_CONVERSION = YES;
177 | CLANG_WARN_INFINITE_RECURSION = YES;
178 | CLANG_WARN_INT_CONVERSION = YES;
179 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
180 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
181 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
182 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
183 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
184 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
185 | CLANG_WARN_STRICT_PROTOTYPES = YES;
186 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
187 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
188 | CLANG_WARN_UNREACHABLE_CODE = YES;
189 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
190 | COPY_PHASE_STRIP = NO;
191 | DEBUG_INFORMATION_FORMAT = dwarf;
192 | ENABLE_STRICT_OBJC_MSGSEND = YES;
193 | ENABLE_TESTABILITY = YES;
194 | GCC_C_LANGUAGE_STANDARD = gnu11;
195 | GCC_DYNAMIC_NO_PIC = NO;
196 | GCC_NO_COMMON_BLOCKS = YES;
197 | GCC_OPTIMIZATION_LEVEL = 0;
198 | GCC_PREPROCESSOR_DEFINITIONS = (
199 | "DEBUG=1",
200 | "$(inherited)",
201 | );
202 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
203 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
204 | GCC_WARN_UNDECLARED_SELECTOR = YES;
205 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
206 | GCC_WARN_UNUSED_FUNCTION = YES;
207 | GCC_WARN_UNUSED_VARIABLE = YES;
208 | MACOSX_DEPLOYMENT_TARGET = 10.15;
209 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
210 | MTL_FAST_MATH = YES;
211 | ONLY_ACTIVE_ARCH = YES;
212 | SDKROOT = macosx;
213 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
214 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
215 | };
216 | name = Debug;
217 | };
218 | 6099FECC264971D8001729BF /* Release */ = {
219 | isa = XCBuildConfiguration;
220 | buildSettings = {
221 | ALWAYS_SEARCH_USER_PATHS = NO;
222 | CLANG_ANALYZER_NONNULL = YES;
223 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
225 | CLANG_CXX_LIBRARY = "libc++";
226 | CLANG_ENABLE_MODULES = YES;
227 | CLANG_ENABLE_OBJC_ARC = YES;
228 | CLANG_ENABLE_OBJC_WEAK = YES;
229 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
230 | CLANG_WARN_BOOL_CONVERSION = YES;
231 | CLANG_WARN_COMMA = YES;
232 | CLANG_WARN_CONSTANT_CONVERSION = YES;
233 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
234 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
235 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
236 | CLANG_WARN_EMPTY_BODY = YES;
237 | CLANG_WARN_ENUM_CONVERSION = YES;
238 | CLANG_WARN_INFINITE_RECURSION = YES;
239 | CLANG_WARN_INT_CONVERSION = YES;
240 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
241 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
242 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
243 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
244 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
245 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
246 | CLANG_WARN_STRICT_PROTOTYPES = YES;
247 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
248 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
249 | CLANG_WARN_UNREACHABLE_CODE = YES;
250 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
251 | COPY_PHASE_STRIP = NO;
252 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
253 | ENABLE_NS_ASSERTIONS = NO;
254 | ENABLE_STRICT_OBJC_MSGSEND = YES;
255 | GCC_C_LANGUAGE_STANDARD = gnu11;
256 | GCC_NO_COMMON_BLOCKS = YES;
257 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
258 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
259 | GCC_WARN_UNDECLARED_SELECTOR = YES;
260 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
261 | GCC_WARN_UNUSED_FUNCTION = YES;
262 | GCC_WARN_UNUSED_VARIABLE = YES;
263 | MACOSX_DEPLOYMENT_TARGET = 10.15;
264 | MTL_ENABLE_DEBUG_INFO = NO;
265 | MTL_FAST_MATH = YES;
266 | SDKROOT = macosx;
267 | SWIFT_COMPILATION_MODE = wholemodule;
268 | SWIFT_OPTIMIZATION_LEVEL = "-O";
269 | };
270 | name = Release;
271 | };
272 | 6099FECE264971D8001729BF /* Debug */ = {
273 | isa = XCBuildConfiguration;
274 | buildSettings = {
275 | CODE_SIGN_STYLE = Automatic;
276 | DEVELOPMENT_TEAM = 3K8FAYP34K;
277 | ENABLE_HARDENED_RUNTIME = YES;
278 | PRODUCT_NAME = "$(TARGET_NAME)";
279 | SWIFT_VERSION = 5.0;
280 | };
281 | name = Debug;
282 | };
283 | 6099FECF264971D8001729BF /* Release */ = {
284 | isa = XCBuildConfiguration;
285 | buildSettings = {
286 | CODE_SIGN_STYLE = Automatic;
287 | DEVELOPMENT_TEAM = 3K8FAYP34K;
288 | ENABLE_HARDENED_RUNTIME = YES;
289 | PRODUCT_NAME = "$(TARGET_NAME)";
290 | SWIFT_VERSION = 5.0;
291 | };
292 | name = Release;
293 | };
294 | /* End XCBuildConfiguration section */
295 |
296 | /* Begin XCConfigurationList section */
297 | 6099FEC1264971D8001729BF /* Build configuration list for PBXProject "Prototype Pattern" */ = {
298 | isa = XCConfigurationList;
299 | buildConfigurations = (
300 | 6099FECB264971D8001729BF /* Debug */,
301 | 6099FECC264971D8001729BF /* Release */,
302 | );
303 | defaultConfigurationIsVisible = 0;
304 | defaultConfigurationName = Release;
305 | };
306 | 6099FECD264971D8001729BF /* Build configuration list for PBXNativeTarget "Prototype Pattern" */ = {
307 | isa = XCConfigurationList;
308 | buildConfigurations = (
309 | 6099FECE264971D8001729BF /* Debug */,
310 | 6099FECF264971D8001729BF /* Release */,
311 | );
312 | defaultConfigurationIsVisible = 0;
313 | defaultConfigurationName = Release;
314 | };
315 | /* End XCConfigurationList section */
316 | };
317 | rootObject = 6099FEBE264971D8001729BF /* Project object */;
318 | }
319 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Creational Pattern/Prototype Pattern/Prototype Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Prototype Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern/Concrete Prototype/Marin.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Marin.swift
3 | // Prototype Pattern
4 | //
5 | // Created by Ick on 2021/05/11.
6 | //
7 |
8 | import Foundation
9 |
10 |
11 | // Concrete Prototype
12 | public class Marin: Prototype {
13 |
14 | public var health: Int
15 | public var attack: Int
16 | public var defence: Int
17 |
18 | public init(health: Int, attack: Int, defence: Int) {
19 | self.health = health
20 | self.attack = attack
21 | self.defence = defence
22 | }
23 |
24 | public required convenience init(prototype: Marin) {
25 | self.init(health: prototype.health, attack: prototype.attack, defence: prototype.defence)
26 | }
27 |
28 | func printStatus() {
29 | print("Marin Health: \(health) Attack: \(attack) Defence: \(defence)")
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern/Concrete Prototype/Medic.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Medic.swift
3 | // Prototype Pattern
4 | //
5 | // Created by Ick on 2021/05/11.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Prototype
11 | public class Medic: Prototype {
12 |
13 | public var health: Int
14 | public var mana: Int
15 | public var defence: Int
16 |
17 | public init(health: Int, mana: Int, defence: Int) {
18 | self.health = health
19 | self.mana = mana
20 | self.defence = defence
21 | }
22 |
23 | public required convenience init(prototype: Medic) {
24 | self.init(health: prototype.health, mana: prototype.mana, defence: prototype.defence)
25 | }
26 | func printStatus() {
27 | print("Medic Health: \(health) Mana: \(mana) Defence: \(defence)\n")
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern/Prototype/Prototype.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Prototype.swift
3 | // Prototype Pattern
4 | //
5 | // Created by Ick on 2021/05/10.
6 | //
7 |
8 | import Foundation
9 |
10 | // Prototype
11 | public protocol Prototype: class {
12 | init(prototype: Self)
13 | }
14 | extension Prototype {
15 | public func clone() -> Self {
16 | return type(of: self).init(prototype: self)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Creational Pattern/Prototype Pattern/Prototype Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Prototype Pattern
4 | //
5 | // Created by Ick on 2021/05/10.
6 | //
7 |
8 | import Foundation
9 |
10 | //var marin = Marin(health: 40, attack: 5, defence: 1)
11 | //let medic = Medic(health: 50, mana: 20, defence: 1)
12 | //
13 | //print("Original")
14 | //marin.printStatus()
15 | //medic.printStatus()
16 | //
17 | //var newMarin = marin.clone()
18 | //let newMedic = medic.clone()
19 | //
20 | //print("Clone")
21 | //newMarin.printStatus()
22 | //newMedic.printStatus()
23 |
24 | var marin = Marin(health: 40, attack: 5, defence: 1)
25 | var shallowCopyMarin = marin
26 | var deepCopyMarin = marin.clone()
27 |
28 | shallowCopyMarin.health += 7
29 | deepCopyMarin.defence += 5
30 |
31 | marin.printStatus()
32 | deepCopyMarin.printStatus()
33 |
34 | var marinAddress: UnsafeMutablePointer = .init(&marin)
35 | var shallowCopyMarinAddress: UnsafeMutablePointer = .init(&shallowCopyMarin)
36 | var deepCopyMarinAddress: UnsafeMutablePointer = .init(&deepCopyMarin)
37 | print("원본 마린 주소 : \(marinAddress)")
38 | print("얕은 복사 마린 주소 : \(shallowCopyMarinAddress)")
39 | print("깊은 복사 마린 주소 : \(deepCopyMarinAddress)")
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Creational Pattern/Singleton Pattern/Singleton Pattern.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 609212E9264AAF550044F66B /* Singleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 609212E8264AAF550044F66B /* Singleton.swift */; };
11 | 609625A8264AA6A6003C6881 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 609625A7264AA6A6003C6881 /* main.swift */; };
12 | /* End PBXBuildFile section */
13 |
14 | /* Begin PBXCopyFilesBuildPhase section */
15 | 609625A2264AA6A6003C6881 /* CopyFiles */ = {
16 | isa = PBXCopyFilesBuildPhase;
17 | buildActionMask = 2147483647;
18 | dstPath = /usr/share/man/man1/;
19 | dstSubfolderSpec = 0;
20 | files = (
21 | );
22 | runOnlyForDeploymentPostprocessing = 1;
23 | };
24 | /* End PBXCopyFilesBuildPhase section */
25 |
26 | /* Begin PBXFileReference section */
27 | 609212E8264AAF550044F66B /* Singleton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Singleton.swift; sourceTree = ""; };
28 | 609625A4264AA6A6003C6881 /* Singleton Pattern */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Singleton Pattern"; sourceTree = BUILT_PRODUCTS_DIR; };
29 | 609625A7264AA6A6003C6881 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; };
30 | /* End PBXFileReference section */
31 |
32 | /* Begin PBXFrameworksBuildPhase section */
33 | 609625A1264AA6A6003C6881 /* Frameworks */ = {
34 | isa = PBXFrameworksBuildPhase;
35 | buildActionMask = 2147483647;
36 | files = (
37 | );
38 | runOnlyForDeploymentPostprocessing = 0;
39 | };
40 | /* End PBXFrameworksBuildPhase section */
41 |
42 | /* Begin PBXGroup section */
43 | 6096259B264AA6A6003C6881 = {
44 | isa = PBXGroup;
45 | children = (
46 | 609625A6264AA6A6003C6881 /* Singleton Pattern */,
47 | 609625A5264AA6A6003C6881 /* Products */,
48 | );
49 | sourceTree = "";
50 | };
51 | 609625A5264AA6A6003C6881 /* Products */ = {
52 | isa = PBXGroup;
53 | children = (
54 | 609625A4264AA6A6003C6881 /* Singleton Pattern */,
55 | );
56 | name = Products;
57 | sourceTree = "";
58 | };
59 | 609625A6264AA6A6003C6881 /* Singleton Pattern */ = {
60 | isa = PBXGroup;
61 | children = (
62 | 609625A7264AA6A6003C6881 /* main.swift */,
63 | 609212E8264AAF550044F66B /* Singleton.swift */,
64 | );
65 | path = "Singleton Pattern";
66 | sourceTree = "";
67 | };
68 | /* End PBXGroup section */
69 |
70 | /* Begin PBXNativeTarget section */
71 | 609625A3264AA6A6003C6881 /* Singleton Pattern */ = {
72 | isa = PBXNativeTarget;
73 | buildConfigurationList = 609625AB264AA6A6003C6881 /* Build configuration list for PBXNativeTarget "Singleton Pattern" */;
74 | buildPhases = (
75 | 609625A0264AA6A6003C6881 /* Sources */,
76 | 609625A1264AA6A6003C6881 /* Frameworks */,
77 | 609625A2264AA6A6003C6881 /* CopyFiles */,
78 | );
79 | buildRules = (
80 | );
81 | dependencies = (
82 | );
83 | name = "Singleton Pattern";
84 | productName = "Singleton Pattern";
85 | productReference = 609625A4264AA6A6003C6881 /* Singleton Pattern */;
86 | productType = "com.apple.product-type.tool";
87 | };
88 | /* End PBXNativeTarget section */
89 |
90 | /* Begin PBXProject section */
91 | 6096259C264AA6A6003C6881 /* Project object */ = {
92 | isa = PBXProject;
93 | attributes = {
94 | LastSwiftUpdateCheck = 1200;
95 | LastUpgradeCheck = 1200;
96 | TargetAttributes = {
97 | 609625A3264AA6A6003C6881 = {
98 | CreatedOnToolsVersion = 12.0.1;
99 | };
100 | };
101 | };
102 | buildConfigurationList = 6096259F264AA6A6003C6881 /* Build configuration list for PBXProject "Singleton Pattern" */;
103 | compatibilityVersion = "Xcode 9.3";
104 | developmentRegion = en;
105 | hasScannedForEncodings = 0;
106 | knownRegions = (
107 | en,
108 | Base,
109 | );
110 | mainGroup = 6096259B264AA6A6003C6881;
111 | productRefGroup = 609625A5264AA6A6003C6881 /* Products */;
112 | projectDirPath = "";
113 | projectRoot = "";
114 | targets = (
115 | 609625A3264AA6A6003C6881 /* Singleton Pattern */,
116 | );
117 | };
118 | /* End PBXProject section */
119 |
120 | /* Begin PBXSourcesBuildPhase section */
121 | 609625A0264AA6A6003C6881 /* Sources */ = {
122 | isa = PBXSourcesBuildPhase;
123 | buildActionMask = 2147483647;
124 | files = (
125 | 609625A8264AA6A6003C6881 /* main.swift in Sources */,
126 | 609212E9264AAF550044F66B /* Singleton.swift in Sources */,
127 | );
128 | runOnlyForDeploymentPostprocessing = 0;
129 | };
130 | /* End PBXSourcesBuildPhase section */
131 |
132 | /* Begin XCBuildConfiguration section */
133 | 609625A9264AA6A6003C6881 /* Debug */ = {
134 | isa = XCBuildConfiguration;
135 | buildSettings = {
136 | ALWAYS_SEARCH_USER_PATHS = NO;
137 | CLANG_ANALYZER_NONNULL = YES;
138 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
139 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
140 | CLANG_CXX_LIBRARY = "libc++";
141 | CLANG_ENABLE_MODULES = YES;
142 | CLANG_ENABLE_OBJC_ARC = YES;
143 | CLANG_ENABLE_OBJC_WEAK = YES;
144 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
145 | CLANG_WARN_BOOL_CONVERSION = YES;
146 | CLANG_WARN_COMMA = YES;
147 | CLANG_WARN_CONSTANT_CONVERSION = YES;
148 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
149 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
150 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
151 | CLANG_WARN_EMPTY_BODY = YES;
152 | CLANG_WARN_ENUM_CONVERSION = YES;
153 | CLANG_WARN_INFINITE_RECURSION = YES;
154 | CLANG_WARN_INT_CONVERSION = YES;
155 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
156 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
157 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
158 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
159 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
160 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
161 | CLANG_WARN_STRICT_PROTOTYPES = YES;
162 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
163 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
164 | CLANG_WARN_UNREACHABLE_CODE = YES;
165 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
166 | COPY_PHASE_STRIP = NO;
167 | DEBUG_INFORMATION_FORMAT = dwarf;
168 | ENABLE_STRICT_OBJC_MSGSEND = YES;
169 | ENABLE_TESTABILITY = YES;
170 | GCC_C_LANGUAGE_STANDARD = gnu11;
171 | GCC_DYNAMIC_NO_PIC = NO;
172 | GCC_NO_COMMON_BLOCKS = YES;
173 | GCC_OPTIMIZATION_LEVEL = 0;
174 | GCC_PREPROCESSOR_DEFINITIONS = (
175 | "DEBUG=1",
176 | "$(inherited)",
177 | );
178 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
179 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
180 | GCC_WARN_UNDECLARED_SELECTOR = YES;
181 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
182 | GCC_WARN_UNUSED_FUNCTION = YES;
183 | GCC_WARN_UNUSED_VARIABLE = YES;
184 | MACOSX_DEPLOYMENT_TARGET = 10.15;
185 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
186 | MTL_FAST_MATH = YES;
187 | ONLY_ACTIVE_ARCH = YES;
188 | SDKROOT = macosx;
189 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
190 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
191 | };
192 | name = Debug;
193 | };
194 | 609625AA264AA6A6003C6881 /* Release */ = {
195 | isa = XCBuildConfiguration;
196 | buildSettings = {
197 | ALWAYS_SEARCH_USER_PATHS = NO;
198 | CLANG_ANALYZER_NONNULL = YES;
199 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
200 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
201 | CLANG_CXX_LIBRARY = "libc++";
202 | CLANG_ENABLE_MODULES = YES;
203 | CLANG_ENABLE_OBJC_ARC = YES;
204 | CLANG_ENABLE_OBJC_WEAK = YES;
205 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
206 | CLANG_WARN_BOOL_CONVERSION = YES;
207 | CLANG_WARN_COMMA = YES;
208 | CLANG_WARN_CONSTANT_CONVERSION = YES;
209 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
210 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
211 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
212 | CLANG_WARN_EMPTY_BODY = YES;
213 | CLANG_WARN_ENUM_CONVERSION = YES;
214 | CLANG_WARN_INFINITE_RECURSION = YES;
215 | CLANG_WARN_INT_CONVERSION = YES;
216 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
217 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
218 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
219 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
220 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
221 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
222 | CLANG_WARN_STRICT_PROTOTYPES = YES;
223 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
224 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
225 | CLANG_WARN_UNREACHABLE_CODE = YES;
226 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
227 | COPY_PHASE_STRIP = NO;
228 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
229 | ENABLE_NS_ASSERTIONS = NO;
230 | ENABLE_STRICT_OBJC_MSGSEND = YES;
231 | GCC_C_LANGUAGE_STANDARD = gnu11;
232 | GCC_NO_COMMON_BLOCKS = YES;
233 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
234 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
235 | GCC_WARN_UNDECLARED_SELECTOR = YES;
236 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
237 | GCC_WARN_UNUSED_FUNCTION = YES;
238 | GCC_WARN_UNUSED_VARIABLE = YES;
239 | MACOSX_DEPLOYMENT_TARGET = 10.15;
240 | MTL_ENABLE_DEBUG_INFO = NO;
241 | MTL_FAST_MATH = YES;
242 | SDKROOT = macosx;
243 | SWIFT_COMPILATION_MODE = wholemodule;
244 | SWIFT_OPTIMIZATION_LEVEL = "-O";
245 | };
246 | name = Release;
247 | };
248 | 609625AC264AA6A6003C6881 /* Debug */ = {
249 | isa = XCBuildConfiguration;
250 | buildSettings = {
251 | CODE_SIGN_STYLE = Automatic;
252 | DEVELOPMENT_TEAM = 3K8FAYP34K;
253 | ENABLE_HARDENED_RUNTIME = YES;
254 | PRODUCT_NAME = "$(TARGET_NAME)";
255 | SWIFT_VERSION = 5.0;
256 | };
257 | name = Debug;
258 | };
259 | 609625AD264AA6A6003C6881 /* Release */ = {
260 | isa = XCBuildConfiguration;
261 | buildSettings = {
262 | CODE_SIGN_STYLE = Automatic;
263 | DEVELOPMENT_TEAM = 3K8FAYP34K;
264 | ENABLE_HARDENED_RUNTIME = YES;
265 | PRODUCT_NAME = "$(TARGET_NAME)";
266 | SWIFT_VERSION = 5.0;
267 | };
268 | name = Release;
269 | };
270 | /* End XCBuildConfiguration section */
271 |
272 | /* Begin XCConfigurationList section */
273 | 6096259F264AA6A6003C6881 /* Build configuration list for PBXProject "Singleton Pattern" */ = {
274 | isa = XCConfigurationList;
275 | buildConfigurations = (
276 | 609625A9264AA6A6003C6881 /* Debug */,
277 | 609625AA264AA6A6003C6881 /* Release */,
278 | );
279 | defaultConfigurationIsVisible = 0;
280 | defaultConfigurationName = Release;
281 | };
282 | 609625AB264AA6A6003C6881 /* Build configuration list for PBXNativeTarget "Singleton Pattern" */ = {
283 | isa = XCConfigurationList;
284 | buildConfigurations = (
285 | 609625AC264AA6A6003C6881 /* Debug */,
286 | 609625AD264AA6A6003C6881 /* Release */,
287 | );
288 | defaultConfigurationIsVisible = 0;
289 | defaultConfigurationName = Release;
290 | };
291 | /* End XCConfigurationList section */
292 | };
293 | rootObject = 6096259C264AA6A6003C6881 /* Project object */;
294 | }
295 |
--------------------------------------------------------------------------------
/Creational Pattern/Singleton Pattern/Singleton Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Creational Pattern/Singleton Pattern/Singleton Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Creational Pattern/Singleton Pattern/Singleton Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Creational Pattern/Singleton Pattern/Singleton Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Creational Pattern/Singleton Pattern/Singleton Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Singleton Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Creational Pattern/Singleton Pattern/Singleton Pattern/Singleton.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Singleton.swift
3 | // Singleton Pattern
4 | //
5 | // Created by Ick on 2021/05/11.
6 | //
7 |
8 | import Foundation
9 |
10 | // Singleton Class
11 | class DBManager {
12 | static let shared = DBManager()
13 |
14 | public var database: [String]
15 |
16 | private init() {
17 | database = []
18 | }
19 | public func addData(data: String) {
20 | self.database.append(data)
21 | }
22 | public func deleteData(data: String) {
23 | if let index = self.database.firstIndex(of: data) {
24 | self.database.remove(at: index)
25 | } else {
26 | print("데이터가 없습니다.")
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Creational Pattern/Singleton Pattern/Singleton Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Singleton Pattern
4 | //
5 | // Created by Ick on 2021/05/11.
6 | //
7 |
8 | import Foundation
9 |
10 | print(DBManager.shared.database)
11 | DBManager.shared.addData(data: "Hello")
12 | print(DBManager.shared.database)
13 |
14 |
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Swift Design Pattern Study
2 |
3 | 디자인 패턴을 Swift로 공부하고 정리한 내용입니다.
4 |
5 | > # [Creational Pattern](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Creational_Pattern)
6 | - ## [Abstract Factory](https://icksw.tistory.com/235)
7 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Creational%20Pattern/AbstractFactoryPattern/AbstractFactoryPattern)
8 | - ## [Builder](https://icksw.tistory.com/236)
9 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Creational%20Pattern/Builder%20Pattern/Builder%20Pattern)
10 | - ## [Factory Methods](https://icksw.tistory.com/237)
11 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Creational%20Pattern/Factory%20Method%20Pattern/Factory%20Method%20Pattern)
12 | - ## [Prototype](https://icksw.tistory.com/238)
13 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Creational%20Pattern/Prototype%20Pattern/Prototype%20Pattern)
14 | - ## [Singleton](https://icksw.tistory.com/239)
15 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Creational%20Pattern/Singleton%20Pattern/Singleton%20Pattern)
16 |
17 | > # [Structural Pattern](https://icksw.tistory.com/240)
18 | - ## [Adapter](https://icksw.tistory.com/241)
19 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Structural%20Pattern/Adapter%20Pattern/Adapter%20Pattern)
20 | - ## [Bridge](https://icksw.tistory.com/242)
21 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Structural%20Pattern/Bridge%20Pattern/Bridge%20Pattern)
22 | - ## [Composite](https://icksw.tistory.com/243)
23 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Structural%20Pattern/Composite%20Pattern)
24 | - ## [Decorator](https://icksw.tistory.com/244)
25 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Structural%20Pattern/Decorator%20Pattern/Decorator%20Pattern)
26 | - ## [Facade](https://icksw.tistory.com/246)
27 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Structural%20Pattern/Facade%20Pattern/Facade%20Pattern)
28 | - ## [Flyweight](https://icksw.tistory.com/247)
29 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Structural%20Pattern/Flyweight%20Pattern/Flyweight%20Pattern)
30 | - ## [Proxy](https://icksw.tistory.com/248)
31 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Structural%20Pattern/Proxy%20Pattern/Proxy%20Pattern)
32 |
33 | > # [Behavioral Pattern](https://icksw.tistory.com/249)
34 | - ## [Chain of Responsibility](https://icksw.tistory.com/250)
35 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Chain%20of%20Responsibility/Chain%20of%20Responsibility)
36 | - ## [Command](https://icksw.tistory.com/251)
37 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Command%20Pattern/Command%20Pattern)
38 | - ## [Interpreter](https://icksw.tistory.com/252)
39 | - ## [Iterator](https://icksw.tistory.com/253)
40 | - ## [Mediator](https://icksw.tistory.com/254)
41 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Mediator%20Pattern/Mediator%20Pattern)
42 | - ## [Memento](https://icksw.tistory.com/255)
43 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Memento%20Pattern/Memento%20Pattern)
44 | - ## [Observer](https://icksw.tistory.com/257)
45 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Observer%20Pattern)
46 | - ## [State](https://icksw.tistory.com/258)
47 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/State%20Pattern)
48 | - ## [Strategy](https://icksw.tistory.com/259)
49 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Strategy%20Pattern)
50 | - ## [Template Method](http://icksw.tistory.com/260)
51 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Template%20Method%20Pattern)
52 | - ## [Visitor](https://icksw.tistory.com/261)
53 | - [Code](https://github.com/iDevPingu/Swift_Design_Pattern_Study/tree/main/Behavioral%20Pattern/Visitor%20Pattern)
54 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Structural Pattern/Adapter Pattern/Adapter Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Adapter Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern/Adaptee/KakaoLoginService.swift:
--------------------------------------------------------------------------------
1 | //
2 | // KakaoAccount.swift
3 | // Adapter Pattern
4 | //
5 | // Created by Ick on 2021/05/13.
6 | //
7 |
8 | import Foundation
9 |
10 | struct KakaoAccount {
11 | var email: String
12 | var password: String
13 | var kakaoToken: String
14 | }
15 |
16 |
17 | class KakaoAccountLogin {
18 | func login(email: String,
19 | password: String,
20 | completion: @escaping(KakaoAccount?, LoginError?) -> Void) {
21 | if !email.hasSuffix("kakao.com") {
22 | completion(nil, LoginError(errorMessage: "email 에러"))
23 | return
24 | }
25 | let token = "아무도 모르는 Kakao 비밀 토큰"
26 | let user = KakaoAccount(email: email, password: password, kakaoToken: token)
27 | completion(user, nil)
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern/Adaptee/NaverLoginService.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NaverAccount.swift
3 | // Adapter Pattern
4 | //
5 | // Created by Ick on 2021/05/13.
6 | //
7 |
8 | import Foundation
9 |
10 | struct NaverAccount {
11 | var email: String
12 | var password: String
13 | var naverToken: String
14 | }
15 |
16 | class NaverAccountLogin {
17 | func login(email: String,
18 | password: String,
19 | completion: @escaping(NaverAccount?, LoginError?) -> Void) {
20 | if !email.hasSuffix("naver.com") {
21 | completion(nil, LoginError(errorMessage: "email 에러"))
22 | return
23 | }
24 | let token = "아무도 모르는 Naver 비밀 토큰"
25 | let user = NaverAccount(email: email, password: password, naverToken: token)
26 | completion(user, nil)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern/Adapter/Adapters.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Adapters.swift
3 | // Adapter Pattern
4 | //
5 | // Created by Ick on 2021/05/13.
6 | //
7 |
8 | import Foundation
9 |
10 | // Adapter
11 | class NaverAccountAdapter: LoginService {
12 |
13 | private var authenticator = NaverAccountLogin()
14 |
15 | func login(email: String,
16 | password: String,
17 | success: @escaping (User?, Token?) -> Void,
18 | failure: @escaping (LoginError?) -> Void) {
19 | authenticator.login(email: email, password: password) { (naverAccount, error) in
20 | guard let naverAccount = naverAccount else {
21 | failure(error)
22 | return
23 | }
24 |
25 | let user = User(email: naverAccount.email,
26 | password: naverAccount.password)
27 | let token = Token(value: naverAccount.naverToken)
28 | success(user, token)
29 | }
30 | }
31 | }
32 |
33 | class KakaoAccountAdapter: LoginService {
34 |
35 | private var authenticator = KakaoAccountLogin()
36 |
37 | func login(email: String,
38 | password: String,
39 | success: @escaping (User?, Token?) -> Void,
40 | failure: @escaping (LoginError?) -> Void) {
41 | authenticator.login(email: email, password: password) { (kakaoAccount, error) in
42 | guard let kakaoAccount = kakaoAccount else {
43 | failure(error)
44 | return
45 | }
46 |
47 | let user = User(email: kakaoAccount.email,
48 | password: kakaoAccount.password)
49 | let token = Token(value: kakaoAccount.kakaoToken)
50 | success(user, token)
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern/Service/OriginalLoginService.swift:
--------------------------------------------------------------------------------
1 | //
2 | // OriginalLoginService.swift
3 | // Adapter Pattern
4 | //
5 | // Created by Ick on 2021/05/13.
6 | //
7 |
8 | import Foundation
9 |
10 | // 기존 로그인 서비스 프로토콜
11 | protocol LoginService {
12 | func login(email: String,
13 | password: String,
14 | success: @escaping (User?, Token?) -> Void,
15 | failure: @escaping (LoginError?) -> Void)
16 | }
17 |
18 | struct User {
19 | let email: String
20 | let password: String
21 | }
22 |
23 | struct Token {
24 | let value: String
25 | }
26 |
27 | struct LoginError: Error {
28 | var errorMessage: String
29 | }
30 |
31 |
32 | class NormalLogin: LoginService {
33 | func login(email: String, password: String, success: @escaping (User?, Token?) -> Void, failure: @escaping (LoginError?) -> Void) {
34 | if !email.hasSuffix("normal.com") {
35 | failure(LoginError(errorMessage: "email 에러"))
36 | return
37 | }
38 | let token = Token(value: "아무도 모르는 Normal 비밀 토큰")
39 | let user = User(email: email, password: password)
40 | success(user, token)
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Structural Pattern/Adapter Pattern/Adapter Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Adapter Pattern
4 | //
5 | // Created by Ick on 2021/05/13.
6 | //
7 |
8 | import Foundation
9 | enum LoginType {
10 | case normal
11 | case naver
12 | case kakao
13 | }
14 |
15 | while true {
16 | print("""
17 | 원하시는 로그인 방법을 선택해 주세요.
18 | 1. 기본 로그인
19 | 2. 네이버 로그인
20 | 3. 카카오 로그인
21 | """)
22 | print("로그인 방법 : ", separator: "", terminator: "")
23 | let loginType = readLine()
24 | if loginType == "1" {
25 | print("Normal Login")
26 | login(loginType: .normal)
27 | break
28 | } else if loginType == "2" {
29 | print("Naver Login")
30 | login(loginType: .naver)
31 | break
32 | } else if loginType == "3" {
33 | print("Kakao Login")
34 | login(loginType: .kakao)
35 | break
36 | } else {
37 | print("잘못된 입력입니다. 다시 선택해주세요.")
38 | continue
39 | }
40 | }
41 | func login(loginType: LoginType) {
42 | var authentication: LoginService?
43 | print("Email을 입력하세요 : ", terminator: "")
44 | let email = readLine()!
45 | print("Password를 입력하세요 : ", terminator: "")
46 | let password = readLine()!
47 |
48 | switch loginType {
49 | case .normal:
50 | authentication = NormalLogin()
51 | authentication?.login(email: email, password: password, success: { (normalAccount, token) in
52 | if let email = normalAccount?.email, let token = token?.value {
53 | print("Normal 계정 로그인 성공!")
54 | print("normalAccount : \(email)")
55 | print("normalToken : \(token)")
56 | }
57 | }, failure: { (error) in
58 | if let error = error {
59 | print(error.errorMessage)
60 | }
61 | })
62 | case .naver:
63 | authentication = NaverAccountAdapter()
64 | authentication?.login(email: email, password: password, success: { (naverAccount, token) in
65 | if let email = naverAccount?.email, let token = token?.value {
66 | print("Naver 계정 로그인 성공!")
67 | print("naverAccount : \(email)")
68 | print("naverToken : \(token)")
69 | }
70 | }, failure: { (error) in
71 | if let error = error {
72 | print(error.errorMessage)
73 | }
74 | })
75 | case .kakao:
76 | authentication = KakaoAccountAdapter()
77 | authentication?.login(email: email, password: password, success: { (kakaoAccount, token) in
78 | if let email = kakaoAccount?.email, let token = token?.value {
79 | print("Kakao 계정 로그인 성공!")
80 | print("kakaoAccount : \(email)")
81 | print("kakaoToken : \(token)")
82 | }
83 | }, failure: { (error) in
84 | if let error = error {
85 | print(error.errorMessage)
86 | }
87 | })
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Structural Pattern/Bridge Pattern/Bridge Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Bridge Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern/Abstraction/Abstraction.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Abstraction.swift
3 | // Bridge Pattern
4 | //
5 | // Created by Ick on 2021/05/16.
6 | //
7 |
8 | import Foundation
9 | // Abstraction
10 | class SoundButton {
11 | // Bridge
12 | var soundButtonImplementor: SoundButtonImplementor?
13 |
14 | init(implementor: SoundButtonImplementor) {
15 | self.soundButtonImplementor = implementor
16 | }
17 |
18 | func up() {
19 | self.soundButtonImplementor?.volumeUp()
20 | }
21 | func down() {
22 | self.soundButtonImplementor?.volumeDown()
23 | }
24 | func set(percent: Float) {
25 | self.soundButtonImplementor?.setVolume(percent: percent)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern/Abstraction/Refined Abstraction.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Refined Abstraction.swift
3 | // Bridge Pattern
4 | //
5 | // Created by Ick on 2021/05/16.
6 | //
7 |
8 | import Foundation
9 |
10 | // Refined Abstraction
11 | //class AdvancedSoundButton: SoundButton {
12 | // func mute() {
13 | // self.soundButtonImplementor?.setVolume(percent: 0.0)
14 | // }
15 | //}
16 |
17 | // Refined Abstraction
18 | extension SoundButton {
19 | func mute() {
20 | self.soundButtonImplementor?.setVolume(percent: 0.0)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern/Implementor/Concrete Implementor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Concrete Implementor.swift
3 | // Bridge Pattern
4 | //
5 | // Created by Ick on 2021/05/16.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Implementor
11 | class TvSoundButton: SoundButtonImplementor {
12 | var volume: Float = 0
13 | func volumeUp() {
14 | if volume >= 1.0 {
15 | print("TV 볼륨이 최대값입니다.")
16 | } else {
17 | volume = min(volume + 0.1, 1.0)
18 | print("TV 볼륨 \(volume)으로 올림")
19 | }
20 | }
21 |
22 | func volumeDown() {
23 | if volume <= 0.0 {
24 | print("TV 볼륨이 최저값입니다.")
25 | } else {
26 | volume = max(volume - 0.1, 0.0)
27 | print("TV 볼륨 \(volume)으로 내림")
28 | }
29 | }
30 | func setVolume(percent: Float) {
31 | if percent < 0.0 || percent > 1.0 {
32 | print("잘못된 TV 볼륨 값")
33 | } else {
34 | volume = percent
35 | print("TV 볼륨 \(volume)으로 세팅")
36 | }
37 | }
38 | }
39 |
40 | // Concrete Implementor
41 | class RadioSoundButton: SoundButtonImplementor {
42 | var volume: Float = 0
43 | func volumeUp() {
44 | if volume >= 1.0 {
45 | print("Radio 볼륨이 최대값입니다.")
46 | } else {
47 | volume = min(volume + 0.1, 1.0)
48 | print("Radio 볼륨 \(volume)으로 올림")
49 | }
50 | }
51 |
52 | func volumeDown() {
53 | if volume <= 0.0 {
54 | print("Radio 볼륨이 최저값입니다.")
55 | } else {
56 | volume = max(volume - 0.1, 0.0)
57 | print("Radio 볼륨 \(volume)으로 내림")
58 | }
59 | }
60 | func setVolume(percent: Float) {
61 | if percent < 0.0 || percent > 1.0 {
62 | print("잘못된 Radio 볼륨 값")
63 | } else {
64 | volume = percent
65 | print("Radio 볼륨 \(volume)으로 세팅")
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern/Implementor/Implementor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Implementor.swift
3 | // Bridge Pattern
4 | //
5 | // Created by Ick on 2021/05/16.
6 | //
7 |
8 | import Foundation
9 |
10 | // Implementor
11 | protocol SoundButtonImplementor {
12 | var volume: Float { get set }
13 | func volumeUp()
14 | func volumeDown()
15 | func setVolume(percent: Float)
16 | }
17 |
--------------------------------------------------------------------------------
/Structural Pattern/Bridge Pattern/Bridge Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Bridge Pattern
4 | //
5 | // Created by Ick on 2021/05/16.
6 | //
7 |
8 | import Foundation
9 |
10 | let tv = TvSoundButton()
11 | let soundButton = SoundButton(implementor: tv)
12 | soundButton.down()
13 |
14 | let radio = RadioSoundButton()
15 | soundButton.soundButtonImplementor = radio
16 | soundButton.set(percent: 0.5)
17 |
18 | soundButton.mute()
19 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Structural Pattern/Composite Pattern/Composite Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Composite Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern/Component/Component.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Component.swift
3 | // Composite Pattern
4 | //
5 | // Created by Ick on 2021/05/18.
6 | //
7 |
8 | import Foundation
9 |
10 | protocol FileComponent {
11 | var size: Int { get set }
12 | var name: String { get set }
13 | func open()
14 | func getSize() -> Int
15 | }
16 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern/Composit/Directory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Directory.swift
3 | // Composite Pattern
4 | //
5 | // Created by Ick on 2021/05/18.
6 | //
7 |
8 | import Foundation
9 |
10 | final class Directory: FileComponent {
11 | var size: Int
12 | var name: String
13 | var files: [FileComponent] = []
14 | func open() {
15 | print("\(self.name) Directory의 모든 File Open")
16 | for file in files {
17 | file.open()
18 | }
19 | print("\(self.name) Directory의 모든 File Open 완료\n")
20 | }
21 |
22 | func getSize() -> Int {
23 | var sum: Int = 0
24 | for file in files {
25 | sum += file.getSize()
26 | }
27 | return sum
28 | }
29 |
30 | func addFile(file: FileComponent) {
31 | self.files.append(file)
32 | self.size += file.size
33 | }
34 |
35 | init(size: Int, name: String) {
36 | self.size = size
37 | self.name = name
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern/Leaf/CodeFile.swift:
--------------------------------------------------------------------------------
1 | //
2 | // CodeFile.swift
3 | // Composite Pattern
4 | //
5 | // Created by Ick on 2021/05/18.
6 | //
7 |
8 | import Foundation
9 |
10 | final class CodeFile: FileComponent {
11 | var size: Int
12 | var name: String
13 | var language: String
14 |
15 | func open() {
16 | print("\(self.name) Code Language : \(self.language)")
17 | }
18 |
19 | func getSize() -> Int {
20 | return self.size
21 | }
22 |
23 | init(size: Int, name: String, language: String) {
24 | self.size = size
25 | self.name = name
26 | self.language = language
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern/Leaf/MusicFile.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MusicFile.swift
3 | // Composite Pattern
4 | //
5 | // Created by Ick on 2021/05/18.
6 | //
7 |
8 | import Foundation
9 |
10 | final class MusicFile: FileComponent {
11 | var size: Int
12 | var name: String
13 | var artist: String
14 |
15 | func open() {
16 | print("\(self.name) Music Artist : \(self.artist)")
17 | }
18 |
19 | func getSize() -> Int {
20 | return self.size
21 | }
22 |
23 | init(size: Int, name: String, artist: String) {
24 | self.size = size
25 | self.name = name
26 | self.artist = artist
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Structural Pattern/Composite Pattern/Composite Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Composite Pattern
4 | //
5 | // Created by Ick on 2021/05/18.
6 | //
7 |
8 | import Foundation
9 |
10 | let rootDirectory = Directory(size: 0, name: "Root")
11 | let musicDirectory = Directory(size: 0, name: "Music")
12 | let codeDirectory = Directory(size: 0, name: "Code")
13 |
14 | let iUMusicFile = MusicFile(size: 10, name: "Lilac", artist: "IU")
15 | let pinguMusicFile = MusicFile(size: 12, name: "PinguBGM", artist: "Pingu")
16 |
17 | let swiftCodeFile = CodeFile(size: 3, name: "iOS", language: "Swift")
18 | let kotlinCodeFile = CodeFile(size: 5, name: "Android", language: "kotlin")
19 |
20 | musicDirectory.addFile(file: iUMusicFile)
21 | musicDirectory.addFile(file: pinguMusicFile)
22 |
23 | codeDirectory.addFile(file: swiftCodeFile)
24 | codeDirectory.addFile(file: kotlinCodeFile)
25 |
26 | rootDirectory.addFile(file: musicDirectory)
27 | rootDirectory.addFile(file: codeDirectory)
28 |
29 | rootDirectory.open()
30 |
31 |
32 | print("RootDirectory Size : \(rootDirectory.getSize())")
33 | print("MusicDirectory Size : \(musicDirectory.getSize())")
34 | print("CodeDirectory Size : \(codeDirectory.getSize())")
35 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Structural Pattern/Decorator Pattern/Decorator Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Decorator Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern/Component/NotifierComponent.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NotifierComponent.swift
3 | // Decorator Pattern
4 | //
5 | // Created by Ick on 2021/05/19.
6 | //
7 |
8 | import Foundation
9 |
10 | // Component
11 | protocol NotifierComponent {
12 | func notify(message: String)
13 | }
14 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern/Concrete Component/Notifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Notifier.swift
3 | // Decorator Pattern
4 | //
5 | // Created by Ick on 2021/05/19.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Component
11 | class Notifier: NotifierComponent {
12 | func notify(message: String) {
13 | print("\(message) 전송완료")
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern/Concrete Decorator/EmailDecorator.swift:
--------------------------------------------------------------------------------
1 | //
2 | // EmailDecorator.swift
3 | // Decorator Pattern
4 | //
5 | // Created by Ick on 2021/05/19.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Decorator
11 | class EmailDecorator: NotifierDecorator {
12 | var wrappee: NotifierComponent
13 |
14 | required init(notifier: NotifierComponent) {
15 | self.wrappee = notifier
16 | }
17 |
18 | func notify(message: String) {
19 | let to = getInfo()
20 | print("\(to)에게 Email로 \(message) 전송완료\n")
21 | self.wrappee.notify(message: message)
22 | }
23 |
24 | func getInfo() -> String {
25 | print("보낼 Email 주소를 입력하세요 : ", separator: "", terminator: "")
26 | return readLine()!
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern/Concrete Decorator/SlackDecorator.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SlackDecorator.swift
3 | // Decorator Pattern
4 | //
5 | // Created by Ick on 2021/05/19.
6 | //
7 |
8 | import Foundation
9 |
10 | // Concrete Decorator
11 | class SlackDecorator: NotifierDecorator {
12 | var wrappee: NotifierComponent
13 |
14 | required init(notifier: NotifierComponent) {
15 | self.wrappee = notifier
16 | }
17 |
18 | func notify(message: String) {
19 | let to = companyInfo()
20 | print("\(to) Slack 채널에 \(message) 전송완료\n")
21 | wrappee.notify(message: message)
22 | }
23 |
24 | func companyInfo() -> String {
25 | print("보낼 Company 채널을 입력하세요 : ", separator: "", terminator: "")
26 | return readLine()!
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern/Decorator/NotifierDecorator.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NotifierDecorator.swift
3 | // Decorator Pattern
4 | //
5 | // Created by Ick on 2021/05/19.
6 | //
7 |
8 | import Foundation
9 |
10 | protocol NotifierDecorator: NotifierComponent {
11 | var wrappee: NotifierComponent { get set }
12 | init(notifier: NotifierComponent)
13 | }
14 |
--------------------------------------------------------------------------------
/Structural Pattern/Decorator Pattern/Decorator Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Decorator Pattern
4 | //
5 | // Created by Ick on 2021/05/19.
6 | //
7 |
8 | import Foundation
9 |
10 | let notifier = Notifier()
11 | let emailNotifier = EmailDecorator(notifier: notifier)
12 | let slackNotifier = SlackDecorator(notifier: emailNotifier)
13 | slackNotifier.notify(message: "Hello")
14 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Structural Pattern/Facade Pattern/Facade Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Facade Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern/Facade/Facade.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Facade.swift
3 | // Facade Pattern
4 | //
5 | // Created by Ick on 2021/05/21.
6 | //
7 |
8 | import Foundation
9 |
10 | class OrderFacade {
11 | let productDB: AvailableProduct
12 | let orderDB: OrderList
13 |
14 | init(productDB: AvailableProduct, orderDB: OrderList) {
15 | self.productDB = productDB
16 | self.orderDB = orderDB
17 | }
18 |
19 | func order(product: Product, customer: Customer) {
20 | print("\(customer.name)님이 \(product.name)를 주문하셨습니다.")
21 | if let count = self.productDB.productList[product] {
22 | if count == 0 {
23 | print("\(product.name) 재고가 없습니다.\n")
24 | } else if count > 0 {
25 | self.productDB.productList[product] = count - 1
26 |
27 | var orderList = self.orderDB.orderList[customer, default: []]
28 | orderList.append(product)
29 | self.orderDB.orderList[customer] = orderList
30 | print("\(customer.name)님의 \(product.name)를 주문 접수 완료!\n")
31 | }
32 | } else {
33 | print("존재하지 않는 제품입니다.\n")
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern/SubsystemClass/AvailableProduct.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AvailableProduct.swift
3 | // Facade Pattern
4 | //
5 | // Created by Ick on 2021/05/21.
6 | //
7 |
8 | import Foundation
9 |
10 | // 재고 관리
11 | class AvailableProduct {
12 | var productList: [Product: Int] = [:]
13 |
14 | init(productList: [Product: Int]) {
15 | self.productList = productList
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern/SubsystemClass/Customer.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Customer.swift
3 | // Facade Pattern
4 | //
5 | // Created by Ick on 2021/05/21.
6 | //
7 |
8 | import Foundation
9 |
10 | struct Customer {
11 | let identifier: String
12 | var name: String
13 | var address: String
14 | }
15 |
16 | extension Customer: Hashable {
17 | func hash(into hasher: inout Hasher) {
18 | hasher.combine(identifier)
19 | }
20 | static func == (lhs: Customer, rhs: Customer) -> Bool {
21 | return lhs.identifier == rhs.identifier
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern/SubsystemClass/OrderList.swift:
--------------------------------------------------------------------------------
1 | //
2 | // OrderList.swift
3 | // Facade Pattern
4 | //
5 | // Created by Ick on 2021/05/21.
6 | //
7 |
8 | import Foundation
9 |
10 | // 주문 현황
11 | class OrderList {
12 | var orderList: [Customer: [Product]] = [:]
13 | }
14 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern/SubsystemClass/Product.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Product.swift
3 | // Facade Pattern
4 | //
5 | // Created by Ick on 2021/05/21.
6 | //
7 |
8 | import Foundation
9 |
10 | struct Product {
11 | let identifier: String
12 | var name: String
13 | var cost: Int
14 | }
15 |
16 | extension Product: Hashable {
17 | func hash(into hasher: inout Hasher) {
18 | hasher.combine(identifier)
19 | }
20 | static func == (lhs: Product, rhs: Product) -> Bool {
21 | return lhs.identifier == rhs.identifier
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Structural Pattern/Facade Pattern/Facade Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Facade Pattern
4 | //
5 | // Created by Ick on 2021/05/20.
6 | //
7 |
8 | import Foundation
9 |
10 | let macBook = Product(identifier: "product-01", name: "MacBook", cost: 2000000)
11 | let iPad = Product(identifier: "product-02", name: "iPad", cost: 1200000)
12 | let iPhone = Product(identifier: "product-03", name: "iPhone", cost: 1000000)
13 |
14 | let productDB = AvailableProduct(productList: [macBook: 4, iPad: 3, iPhone: 1])
15 |
16 | let pingu = Customer(identifier: "customer-01", name: "Pingu", address: "남극 이글루")
17 | let ick = Customer(identifier: "customer-02", name: "Ick", address: "한국 서울")
18 |
19 | let orderFacade = OrderFacade(productDB: productDB, orderDB: OrderList())
20 |
21 | orderFacade.order(product: iPhone, customer: pingu)
22 | orderFacade.order(product: iPhone, customer: pingu)
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 60B5E03A265809990046A60F /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60B5E039265809990046A60F /* main.swift */; };
11 | 60B5E0422658163E0046A60F /* BulletFlyweight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60B5E0412658163E0046A60F /* BulletFlyweight.swift */; };
12 | 60B5E045265816560046A60F /* Bullet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60B5E044265816560046A60F /* Bullet.swift */; };
13 | 60B5E0482658165D0046A60F /* BulletFlyweightFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60B5E0472658165D0046A60F /* BulletFlyweightFactory.swift */; };
14 | /* End PBXBuildFile section */
15 |
16 | /* Begin PBXCopyFilesBuildPhase section */
17 | 60B5E034265809990046A60F /* CopyFiles */ = {
18 | isa = PBXCopyFilesBuildPhase;
19 | buildActionMask = 2147483647;
20 | dstPath = /usr/share/man/man1/;
21 | dstSubfolderSpec = 0;
22 | files = (
23 | );
24 | runOnlyForDeploymentPostprocessing = 1;
25 | };
26 | /* End PBXCopyFilesBuildPhase section */
27 |
28 | /* Begin PBXFileReference section */
29 | 60B5E036265809990046A60F /* Flyweight Pattern */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Flyweight Pattern"; sourceTree = BUILT_PRODUCTS_DIR; };
30 | 60B5E039265809990046A60F /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; };
31 | 60B5E0412658163E0046A60F /* BulletFlyweight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BulletFlyweight.swift; sourceTree = ""; };
32 | 60B5E044265816560046A60F /* Bullet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bullet.swift; sourceTree = ""; };
33 | 60B5E0472658165D0046A60F /* BulletFlyweightFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BulletFlyweightFactory.swift; sourceTree = ""; };
34 | /* End PBXFileReference section */
35 |
36 | /* Begin PBXFrameworksBuildPhase section */
37 | 60B5E033265809990046A60F /* Frameworks */ = {
38 | isa = PBXFrameworksBuildPhase;
39 | buildActionMask = 2147483647;
40 | files = (
41 | );
42 | runOnlyForDeploymentPostprocessing = 0;
43 | };
44 | /* End PBXFrameworksBuildPhase section */
45 |
46 | /* Begin PBXGroup section */
47 | 60B5E02D265809990046A60F = {
48 | isa = PBXGroup;
49 | children = (
50 | 60B5E038265809990046A60F /* Flyweight Pattern */,
51 | 60B5E037265809990046A60F /* Products */,
52 | );
53 | sourceTree = "";
54 | };
55 | 60B5E037265809990046A60F /* Products */ = {
56 | isa = PBXGroup;
57 | children = (
58 | 60B5E036265809990046A60F /* Flyweight Pattern */,
59 | );
60 | name = Products;
61 | sourceTree = "";
62 | };
63 | 60B5E038265809990046A60F /* Flyweight Pattern */ = {
64 | isa = PBXGroup;
65 | children = (
66 | 60B5E04A265816800046A60F /* Flyweight */,
67 | 60B5E04B2658168D0046A60F /* UnsharedConcreteFlyweight */,
68 | 60B5E04C265816970046A60F /* FlyweightFactory */,
69 | 60B5E039265809990046A60F /* main.swift */,
70 | );
71 | path = "Flyweight Pattern";
72 | sourceTree = "";
73 | };
74 | 60B5E04A265816800046A60F /* Flyweight */ = {
75 | isa = PBXGroup;
76 | children = (
77 | 60B5E0412658163E0046A60F /* BulletFlyweight.swift */,
78 | );
79 | path = Flyweight;
80 | sourceTree = "";
81 | };
82 | 60B5E04B2658168D0046A60F /* UnsharedConcreteFlyweight */ = {
83 | isa = PBXGroup;
84 | children = (
85 | 60B5E044265816560046A60F /* Bullet.swift */,
86 | );
87 | path = UnsharedConcreteFlyweight;
88 | sourceTree = "";
89 | };
90 | 60B5E04C265816970046A60F /* FlyweightFactory */ = {
91 | isa = PBXGroup;
92 | children = (
93 | 60B5E0472658165D0046A60F /* BulletFlyweightFactory.swift */,
94 | );
95 | path = FlyweightFactory;
96 | sourceTree = "";
97 | };
98 | /* End PBXGroup section */
99 |
100 | /* Begin PBXNativeTarget section */
101 | 60B5E035265809990046A60F /* Flyweight Pattern */ = {
102 | isa = PBXNativeTarget;
103 | buildConfigurationList = 60B5E03D265809990046A60F /* Build configuration list for PBXNativeTarget "Flyweight Pattern" */;
104 | buildPhases = (
105 | 60B5E032265809990046A60F /* Sources */,
106 | 60B5E033265809990046A60F /* Frameworks */,
107 | 60B5E034265809990046A60F /* CopyFiles */,
108 | );
109 | buildRules = (
110 | );
111 | dependencies = (
112 | );
113 | name = "Flyweight Pattern";
114 | productName = "Flyweight Pattern";
115 | productReference = 60B5E036265809990046A60F /* Flyweight Pattern */;
116 | productType = "com.apple.product-type.tool";
117 | };
118 | /* End PBXNativeTarget section */
119 |
120 | /* Begin PBXProject section */
121 | 60B5E02E265809990046A60F /* Project object */ = {
122 | isa = PBXProject;
123 | attributes = {
124 | LastSwiftUpdateCheck = 1200;
125 | LastUpgradeCheck = 1200;
126 | TargetAttributes = {
127 | 60B5E035265809990046A60F = {
128 | CreatedOnToolsVersion = 12.0.1;
129 | };
130 | };
131 | };
132 | buildConfigurationList = 60B5E031265809990046A60F /* Build configuration list for PBXProject "Flyweight Pattern" */;
133 | compatibilityVersion = "Xcode 9.3";
134 | developmentRegion = en;
135 | hasScannedForEncodings = 0;
136 | knownRegions = (
137 | en,
138 | Base,
139 | );
140 | mainGroup = 60B5E02D265809990046A60F;
141 | productRefGroup = 60B5E037265809990046A60F /* Products */;
142 | projectDirPath = "";
143 | projectRoot = "";
144 | targets = (
145 | 60B5E035265809990046A60F /* Flyweight Pattern */,
146 | );
147 | };
148 | /* End PBXProject section */
149 |
150 | /* Begin PBXSourcesBuildPhase section */
151 | 60B5E032265809990046A60F /* Sources */ = {
152 | isa = PBXSourcesBuildPhase;
153 | buildActionMask = 2147483647;
154 | files = (
155 | 60B5E0482658165D0046A60F /* BulletFlyweightFactory.swift in Sources */,
156 | 60B5E03A265809990046A60F /* main.swift in Sources */,
157 | 60B5E045265816560046A60F /* Bullet.swift in Sources */,
158 | 60B5E0422658163E0046A60F /* BulletFlyweight.swift in Sources */,
159 | );
160 | runOnlyForDeploymentPostprocessing = 0;
161 | };
162 | /* End PBXSourcesBuildPhase section */
163 |
164 | /* Begin XCBuildConfiguration section */
165 | 60B5E03B265809990046A60F /* Debug */ = {
166 | isa = XCBuildConfiguration;
167 | buildSettings = {
168 | ALWAYS_SEARCH_USER_PATHS = NO;
169 | CLANG_ANALYZER_NONNULL = YES;
170 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
171 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
172 | CLANG_CXX_LIBRARY = "libc++";
173 | CLANG_ENABLE_MODULES = YES;
174 | CLANG_ENABLE_OBJC_ARC = YES;
175 | CLANG_ENABLE_OBJC_WEAK = YES;
176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
177 | CLANG_WARN_BOOL_CONVERSION = YES;
178 | CLANG_WARN_COMMA = YES;
179 | CLANG_WARN_CONSTANT_CONVERSION = YES;
180 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
182 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
183 | CLANG_WARN_EMPTY_BODY = YES;
184 | CLANG_WARN_ENUM_CONVERSION = YES;
185 | CLANG_WARN_INFINITE_RECURSION = YES;
186 | CLANG_WARN_INT_CONVERSION = YES;
187 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
188 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
189 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
190 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
191 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
192 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
193 | CLANG_WARN_STRICT_PROTOTYPES = YES;
194 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
195 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
196 | CLANG_WARN_UNREACHABLE_CODE = YES;
197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
198 | COPY_PHASE_STRIP = NO;
199 | DEBUG_INFORMATION_FORMAT = dwarf;
200 | ENABLE_STRICT_OBJC_MSGSEND = YES;
201 | ENABLE_TESTABILITY = YES;
202 | GCC_C_LANGUAGE_STANDARD = gnu11;
203 | GCC_DYNAMIC_NO_PIC = NO;
204 | GCC_NO_COMMON_BLOCKS = YES;
205 | GCC_OPTIMIZATION_LEVEL = 0;
206 | GCC_PREPROCESSOR_DEFINITIONS = (
207 | "DEBUG=1",
208 | "$(inherited)",
209 | );
210 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
211 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
212 | GCC_WARN_UNDECLARED_SELECTOR = YES;
213 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
214 | GCC_WARN_UNUSED_FUNCTION = YES;
215 | GCC_WARN_UNUSED_VARIABLE = YES;
216 | MACOSX_DEPLOYMENT_TARGET = 10.15;
217 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
218 | MTL_FAST_MATH = YES;
219 | ONLY_ACTIVE_ARCH = YES;
220 | SDKROOT = macosx;
221 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
222 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
223 | };
224 | name = Debug;
225 | };
226 | 60B5E03C265809990046A60F /* Release */ = {
227 | isa = XCBuildConfiguration;
228 | buildSettings = {
229 | ALWAYS_SEARCH_USER_PATHS = NO;
230 | CLANG_ANALYZER_NONNULL = YES;
231 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
232 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
233 | CLANG_CXX_LIBRARY = "libc++";
234 | CLANG_ENABLE_MODULES = YES;
235 | CLANG_ENABLE_OBJC_ARC = YES;
236 | CLANG_ENABLE_OBJC_WEAK = YES;
237 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
238 | CLANG_WARN_BOOL_CONVERSION = YES;
239 | CLANG_WARN_COMMA = YES;
240 | CLANG_WARN_CONSTANT_CONVERSION = YES;
241 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
242 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
243 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
244 | CLANG_WARN_EMPTY_BODY = YES;
245 | CLANG_WARN_ENUM_CONVERSION = YES;
246 | CLANG_WARN_INFINITE_RECURSION = YES;
247 | CLANG_WARN_INT_CONVERSION = YES;
248 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
249 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
250 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
251 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
252 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
253 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
254 | CLANG_WARN_STRICT_PROTOTYPES = YES;
255 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
256 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
257 | CLANG_WARN_UNREACHABLE_CODE = YES;
258 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
259 | COPY_PHASE_STRIP = NO;
260 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
261 | ENABLE_NS_ASSERTIONS = NO;
262 | ENABLE_STRICT_OBJC_MSGSEND = YES;
263 | GCC_C_LANGUAGE_STANDARD = gnu11;
264 | GCC_NO_COMMON_BLOCKS = YES;
265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
267 | GCC_WARN_UNDECLARED_SELECTOR = YES;
268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
269 | GCC_WARN_UNUSED_FUNCTION = YES;
270 | GCC_WARN_UNUSED_VARIABLE = YES;
271 | MACOSX_DEPLOYMENT_TARGET = 10.15;
272 | MTL_ENABLE_DEBUG_INFO = NO;
273 | MTL_FAST_MATH = YES;
274 | SDKROOT = macosx;
275 | SWIFT_COMPILATION_MODE = wholemodule;
276 | SWIFT_OPTIMIZATION_LEVEL = "-O";
277 | };
278 | name = Release;
279 | };
280 | 60B5E03E265809990046A60F /* Debug */ = {
281 | isa = XCBuildConfiguration;
282 | buildSettings = {
283 | CODE_SIGN_STYLE = Automatic;
284 | DEVELOPMENT_TEAM = 3K8FAYP34K;
285 | ENABLE_HARDENED_RUNTIME = YES;
286 | PRODUCT_NAME = "$(TARGET_NAME)";
287 | SWIFT_VERSION = 5.0;
288 | };
289 | name = Debug;
290 | };
291 | 60B5E03F265809990046A60F /* Release */ = {
292 | isa = XCBuildConfiguration;
293 | buildSettings = {
294 | CODE_SIGN_STYLE = Automatic;
295 | DEVELOPMENT_TEAM = 3K8FAYP34K;
296 | ENABLE_HARDENED_RUNTIME = YES;
297 | PRODUCT_NAME = "$(TARGET_NAME)";
298 | SWIFT_VERSION = 5.0;
299 | };
300 | name = Release;
301 | };
302 | /* End XCBuildConfiguration section */
303 |
304 | /* Begin XCConfigurationList section */
305 | 60B5E031265809990046A60F /* Build configuration list for PBXProject "Flyweight Pattern" */ = {
306 | isa = XCConfigurationList;
307 | buildConfigurations = (
308 | 60B5E03B265809990046A60F /* Debug */,
309 | 60B5E03C265809990046A60F /* Release */,
310 | );
311 | defaultConfigurationIsVisible = 0;
312 | defaultConfigurationName = Release;
313 | };
314 | 60B5E03D265809990046A60F /* Build configuration list for PBXNativeTarget "Flyweight Pattern" */ = {
315 | isa = XCConfigurationList;
316 | buildConfigurations = (
317 | 60B5E03E265809990046A60F /* Debug */,
318 | 60B5E03F265809990046A60F /* Release */,
319 | );
320 | defaultConfigurationIsVisible = 0;
321 | defaultConfigurationName = Release;
322 | };
323 | /* End XCConfigurationList section */
324 | };
325 | rootObject = 60B5E02E265809990046A60F /* Project object */;
326 | }
327 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Structural Pattern/Flyweight Pattern/Flyweight Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Flyweight Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern/Flyweight/BulletFlyweight.swift:
--------------------------------------------------------------------------------
1 | //
2 | // BulletFlyweight.swift
3 | // Flyweight Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | // Flyweight
11 | class BulletFlyweight {
12 | let color: String
13 | let size: Float
14 |
15 | init(color: String, size: Float) {
16 | self.color = color
17 | self.size = size
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern/FlyweightFactory/BulletFlyweightFactory.swift:
--------------------------------------------------------------------------------
1 | //
2 | // BulletFlyweightFactory.swift
3 | // Flyweight Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | // Flyweight Factory
11 | class BulletFlyweightFactory {
12 | static private var bulletFlyweightList: [BulletFlyweight] = []
13 |
14 | static func getBulletFlyweight(color: String, size: Float) -> BulletFlyweight {
15 | if let flyweightIndex = self.bulletFlyweightList.firstIndex(where: { (bullet) -> Bool in
16 | return bullet.color == color && bullet.size == size
17 | }) {
18 | return self.bulletFlyweightList[flyweightIndex]
19 | } else {
20 | self.bulletFlyweightList.append(BulletFlyweight(color: color, size: size))
21 | print("\(color),\(size) Flyweight 객체 생성")
22 | return self.bulletFlyweightList.last ?? BulletFlyweight(color: color, size: size)
23 | }
24 | }
25 |
26 | static var flyweightCount: Int {
27 | return self.bulletFlyweightList.count
28 | }
29 |
30 | private init() {}
31 | }
32 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern/UnsharedConcreteFlyweight/Bullet.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Bullet.swift
3 | // Flyweight Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | // Unshared Concrete Flyweight
11 | class Bullet {
12 | var x: Float
13 | var y: Float
14 | var velocity: Float
15 |
16 | private var extrinsicState: BulletFlyweight
17 |
18 | init(x: Float, y: Float, velocity: Float, extrinsicState: BulletFlyweight) {
19 | self.x = x
20 | self.y = y
21 | self.velocity = velocity
22 | self.extrinsicState = extrinsicState
23 | }
24 | func getState() {
25 | print("Flyweight : \(x),\(y),\(velocity) 값을 갖는 \(extrinsicState.color), \(extrinsicState.size) 총알")
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Structural Pattern/Flyweight Pattern/Flyweight Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Flyweight Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | var bullets: [Bullet] = []
11 |
12 | for i in 0..<5 {
13 | let i = Float(i)
14 | bullets.append(Bullet(x: i, y: i, velocity: i*5, extrinsicState: BulletFlyweightFactory.getBulletFlyweight(color: "Red", size: 12.0)))
15 | }
16 |
17 | for i in 0..<5 {
18 | let i = Float(i)
19 | bullets.append(Bullet(x: i, y: i, velocity: i*5, extrinsicState: BulletFlyweightFactory.getBulletFlyweight(color: "Red", size: 24.0)))
20 | }
21 |
22 | print("Flyweight 객체 수 : \(BulletFlyweightFactory.flyweightCount)")
23 |
24 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDevPingu/Swift_Design_Pattern_Study/74603ab54ac39da01ef108f2e1a8264678406c6f/Structural Pattern/Proxy Pattern/Proxy Pattern.xcodeproj/project.xcworkspace/xcuserdata/ick.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern.xcodeproj/xcuserdata/ick.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Proxy Pattern.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern/Client/Client.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Client.swift
3 | // Proxy Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | // Client
11 | class Client {
12 | var auth: AccessAuth
13 |
14 | init(auth: AccessAuth) {
15 | self.auth = auth
16 | }
17 | }
18 |
19 | enum AccessAuth {
20 | case owner
21 | case guest
22 | }
23 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern/Proxy/YoutubeVideoProxy.swift:
--------------------------------------------------------------------------------
1 | //
2 | // YoutubeVideoProxy.swift
3 | // Proxy Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | // Proxy
11 | class YoutubeVideoProxy: YoutubeVideoService {
12 |
13 | private var youtubeVideo: YoutubeVideoService?
14 | private var id: Int
15 | private var name: String
16 | private var client: Client
17 |
18 | init(id: Int, name: String, client: Client) {
19 | self.id = id
20 | self.name = name
21 | self.client = client
22 | }
23 | func showTitle() {
24 | print("\(id), \(name) Youtube Video")
25 | }
26 | func showPreview() {
27 | if let youtubeVideo = self.youtubeVideo {
28 | youtubeVideo.showPreview()
29 | } else {
30 | loadVideoInfo()
31 | self.youtubeVideo?.showPreview()
32 | }
33 | }
34 |
35 | private func loadVideoInfo() {
36 | if let _ = self.youtubeVideo {
37 | print("Cache File Exist!\n")
38 | } else {
39 | print("load Video...🐧")
40 | self.youtubeVideo = YoutubeVideo(id: self.id, name: self.name)
41 | }
42 |
43 | }
44 |
45 | func setName(name: String) {
46 | if client.auth == .guest {
47 | print("Guest는 이름 수정 불가\n")
48 | } else if client.auth == .owner {
49 | self.loadVideoInfo()
50 | self.name = name
51 | self.youtubeVideo?.setName(name: name)
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern/Real Subject/YoutubeVideo.swift:
--------------------------------------------------------------------------------
1 | //
2 | // YoutubeVideo.swift
3 | // Proxy Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | // Real Service
11 | class YoutubeVideo: YoutubeVideoService {
12 |
13 | private var id: Int
14 | private var name: String
15 |
16 | init(id: Int, name: String) {
17 | self.id = id
18 | self.name = name
19 | }
20 |
21 | func showPreview() {
22 | print("\(name) Preview Play 😀\n")
23 | }
24 |
25 | func setName(name: String) {
26 | print("\(self.name)에서 \(name)으로 이름 수정 완료\n")
27 | self.name = name
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern/Subject(Service Interface)/YoutubeVideoService.swift:
--------------------------------------------------------------------------------
1 | //
2 | // YoutubeVideoService.swift
3 | // Proxy Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | // Subject (Service Interface)
11 | protocol YoutubeVideoService {
12 | func showPreview()
13 | func setName(name: String)
14 | }
15 |
--------------------------------------------------------------------------------
/Structural Pattern/Proxy Pattern/Proxy Pattern/main.swift:
--------------------------------------------------------------------------------
1 | //
2 | // main.swift
3 | // Proxy Pattern
4 | //
5 | // Created by Ick on 2021/05/22.
6 | //
7 |
8 | import Foundation
9 |
10 | let owner = Client(auth: .owner)
11 | let ownerProxy = YoutubeVideoProxy(id: 1, name: "LOL Game Video", client: owner)
12 |
13 | ownerProxy.showTitle()
14 | ownerProxy.showPreview() // 실제 비디오 객체 필요 -> 생성 후 캐시에 저장
15 | ownerProxy.setName(name: "LOL 비디오") // 실제 비디오 객체 필요 -> 캐시에 이미 존재
16 |
17 | let guest = Client(auth: .guest)
18 | let guestProxy = YoutubeVideoProxy(id: 2, name: "Funny Video", client: guest)
19 |
20 | guestProxy.showTitle()
21 | guestProxy.setName(name: "내가 이름 바꿀거지롱") // Guest 권한이라 이름 변경 불가능
22 |
23 |
--------------------------------------------------------------------------------