SlideShare a Scribd company logo
Swift 3 :
Protocols
군산대학교 컴퓨터정보통신공학부 컴퓨터정보공학전공
남 광 우
kwnam@kunsan.ac.kr
Swift 3 Tour and Language Guide by Apple
Protocol
• 정의
• 특정 태스크나 기능들에 대한 메소드, 속성, 또는 요
구사항들의 기본 사항들을 정의
• Java 등의 인터페이스(interface)
• 사용
• interface와 동일하게 다중 구현이 가능
• 객체 상속은 1개만
protocol 프로토콜이름 {
// protocol definition goes here
}
Protocol
• 사용
• protocol의 다중 구현
• class와 potocol의 복합 사용
struct SomeStructure: FirstProtocol, AnotherProtocol {
// structure definition goes here
}
class SomeClass: SomeSuperclass, FirstProtocol, AnotherProtocol {
// class definition goes here
}
Protocol : Property
• Property 구현 요구사항 정의
• static 키워드
protocol SomeProtocol {
var mustBeSettable: Int { get set }
var doesNotNeedToBeSettable: Int { get }
}
protocol AnotherProtocol {
static var someTypeProperty: Int { get set }
}
Protocol : Property
• protocol 사용의 예
• FullyNamed protocol
• Person struct
protocol FullyNamed {
var fullName: String { get }
}
struct Person: FullyNamed {
var fullName: String
}
let john = Person(fullName: "John Appleseed")
// john.fullName is "John Appleseed"
Protocol : Property
• protocol 사용의 예
• Starship class
class Starship: FullyNamed {
var prefix: String?
var name: String
init(name: String, prefix: String? = nil) {
self.name = name
self.prefix = prefix
}
var fullName: String {
return (prefix != nil ? prefix! + " " : "") + name
}
}
var ncc1701 = Starship(name: "Enterprise", prefix: "USS")
// ncc1701.fullName is "USS Enterprise"
Protocol : Method
• method protocol
• method protocol의 예
protocol SomeProtocol {
static func someTypeMethod()
}
protocol RandomNumberGenerator {
func random() -> Double
}
Protocol : Method
• method protocol의 예
class LinearCongruentialGenerator: RandomNumberGenerator {
var lastRandom = 42.0
let m = 139968.0
let a = 3877.0
let c = 29573.0
func random() -> Double {
lastRandom = ((lastRandom * a +).truncatingRemainder(dividingBy:m))
return lastRandom / m
}
}
let generator = LinearCongruentialGenerator()
print("Here's a random number: (generator.random())")
// Prints "Here's a random number: 0.37464991998171“
print("And another one: (generator.random())")
// Prints "And another one: 0.729023776863283"
Protocol : Mutating Method
• mutating method protocol
• 예
protocol Togglable {
mutating func toggle()
}
enum OnOffSwitch: Togglable {
case off, on
mutating func toggle() {
switch self {
case .off:
self = .on
case .on:
self = .off
}
}
}
var lightSwitch = OnOffSwitch.off
lightSwitch.toggle()
// lightSwitch is now equal to .on
Protocol : Initializer
• init protocol
• initializer 프로토콜을 구현 할 경우 required 명시
protocol SomeProtocol {
init(someParameter: Int)
}
class SomeClass: SomeProtocol {
required init(someParameter: Int) {
// initializer implementation goes here
}
}
Protocol : Initializer
• init protocol의 예 
• 복합 상속에서의 사용
protocol SomeProtocol {
init()
}
class SomeSuperClass {
init() {
// initializer implementation goes here
}
}
class SomeSubClass: SomeSuperClass, SomeProtocol {
required override init() {
// initializer implementation goes here
}
}
Type으로서의 protocol
• Type으로 protocol 사용 예 
• RandomNumberGenerator
• 사용
class Dice {
let sides: Int
let generator: RandomNumberGenerator
init(sides: Int, generator: RandomNumberGenerator) {
self.sides = sides
self.generator = generator
}
func roll() -> Int {
return Int( generator.random() * Double(sides)) + 1
}
}
var d6 = Dice(sides: 6, generator: LinearCongruentialGenerator())
for _ in 1...5 {
print("Random dice roll is (d6.roll())")
}
Delegation 패턴에서의 사용
• Delegation(위임) 패턴이란?
• 특정 클래스의 구현 중 일부를 다른 클래스에서 구현
할 수 있도록 하는 패턴
참고 : http://seorenn.blogspot.kr/2015/01/swift‐delegation‐pattern.html
class  A
protocol  P {
pmethod
}
var delegate: P
amethod(){
//다른 클래스에
서 구현할 메소드
dp.pmethod() 
}
class  B : P
var da : A
a = A();
b = B();
a.delegate = b;
pmethod(){
}
da.amethod();
class  C : P
var da : A
pmethod(){
}
da.amethod();
a = A();
c = C();
a.delegate = c;
Delegation 패턴에서의 사용
• DiceGame에서의 Delegation
protocol DiceGame {
var dice: Dice { get }
func play()
}
protocol DiceGameDelegate {
func gameDidStart(_ game: DiceGame)
func game(_ game: DiceGame, idStartNewTurnWithDiceRoll diceRoll: Int)
func gameDidEnd(_ game: DiceGame)
}
Delegation 패턴에서의 사용
• DiceGame에서의 Delegation
class SnakesAndLadders: DiceGame {
let finalSquare = 25
let dice = Dice(sides: 6, generator: LinearCongruentialGenerator())
var square = 0
var board: [Int]
init() {
board = Array(repeating: 0, count: finalSquare + 1)
board[03] = +08; board[06] = +11; board[09] = +09; board[10] = +02
board[14] = -10; board[19] = -11; board[22] = -02; board[24] = -08
}
var delegate: DiceGameDelegate?
func play() {
square = 0
delegate?.gameDidStart(self)
gameLoop: while square != finalSquare {
let diceRoll = dice.roll()
delegate?.game(self, didStartNewTurnWithDiceRoll: diceRoll)
switch square + diceRoll {
case finalSquare:
break gameLoop
case let newSquare where newSquare > finalSquare:
continue gameLoop
default:
square += diceRoll
square += board[square]
}
}
delegate?.gameDidEnd(self)
}
}
Delegation 패턴에서의 사용
• DiceGameTracker의 구현
class DiceGameTracker: DiceGameDelegate {
var numberOfTurns = 0
func gameDidStart(_ game: DiceGame) {
numberOfTurns = 0
if game is SnakesAndLadders {
print("Started a new game of Snakes and Ladders")
}
print("The game is using a (game.dice.sides)-sided dice")
}
func game(_ game: DiceGame, didStartNewTurnWithDiceRoll diceRoll: Int) {
numberOfTurns += 1
print("Rolled a (diceRoll)")
}
func gameDidEnd(_ game: DiceGame) {
print("The game lasted for (numberOfTurns) turns")
}
}
Delegation 패턴에서의 사용
• DiceGame과 DiceGameTracker의 연결
let tracker = DiceGameTracker()
let game = SnakesAndLadders()
game.delegate = tracker
game.play()
// Started a new game of Snakes and Ladders
// The game is using a 6-sided dice
// Rolled a 3
// Rolled a 5
// Rolled a 4
// Rolled a 5
// The game lasted for 4 turn
Extension과 Protocol
protocol TextRepresentable {
var textualDescription: String { get }
}
extension Dice: TextRepresentable {
var textualDescription: String {
return "A (sides)-sided dice"
}
}
let d12 = Dice(sides: 12, generator: LinearCongruentialGenerator())
print(d12.textualDescription)
// Prints "A 12-sided dice"
class Dice {
let sides: Int
let generator: RandomNumberGenerator
init(sides: Int, generator: RandomNumberGenerator) {
self.sides = sides
self.generator = generator
}
func roll() -> Int {
return Int( generator.random() * Double(sides)) + 1
}
}
extension SnakesAndLadders: TextRepresentable {
var textualDescription: String {
return "A game of Snakes and Ladders with (finalSquare) squares"
}
}
print( game.textualDescription )
// Prints "A game of Snakes and Ladders with 25 squares"
Extension과 Protocol
let tracker = DiceGameTracker()
let game = SnakesAndLadders()
game.delegate = tracker
game.play()
Protocol Adoption
struct Hamster {
var name: String
var textualDescription: String {
return "A hamster named (name)"
}
}
extension Hamster: TextRepresentable {}
let simonTheHamster = Hamster(name: "Simon")
let somethingTextRepresentable: TextRepresentable = simonTheHamster
print( somethingTextRepresentable.textualDescription )
// Prints "A hamster named Simon"
Protocol Type의 Collection
let things: [TextRepresentable] = [game, d12, simonTheHamster]
for thing in things {
print(thing.textualDescription)
}
// A game of Snakes and Ladders with 25 squares
// A 12-sided dice
// A hamster named Simon
Protocol 상속
protocol InheritingProtocol: SomeProtocol, AnotherProtocol {
// protocol definition goes here
}
protocol PrettyTextRepresentable: TextRepresentable {
var prettyTextualDescription: String { get }
}
• Protocol의 상속 정의
• protocol 상속의 예
extension SnakesAndLadders: PrettyTextRepresentable {
var prettyTextualDescription: String {
var output = textualDescription + ":n"
for index in 1...finalSquare {
switch board[index] {
case let ladder where ladder > 0:
output += "▲ "
case let snake where snake < 0:
output += "▼ "
default:
output += "○ "
}
}
return output
}
}
• 상속된 protocol의 사용
Protocol 상속
print(game.prettyTextualDescription)
// A game of Snakes and Ladders with 25 squares:
// ○ ○ ▲ ○ ○ ▲ ○ ○ ▲ ▲ ○ ○ ○ ▼ ○ ○ ○ ○ ▼ ○ ○ ▼ ○ ▼
Class-Only Protocol
protocol SomeClassOnlyProtocol: class, SomeInheritedProtocol {
// class-only protocol definition goes here
}
• class 프로토콜
& protocol composition
protocol Named {
var name: String { get }
}
protocol Aged {
var age: Int { get }
}
struct Person: Named, Aged {
var name: String
var age: Int
}
func wishHappyBirthday(to celebrator: Named & Aged) {
print("Happy birthday, (celebrator.name), you're (celebrator.age)!")
}
let birthdayPerson = Person(name: "Malcolm", age: 21)
wishHappyBirthday(to: birthdayPerson)
// Prints "Happy birthday, Malcolm, you're 21!"
Protocol 체크
• protocol의 타입 체크
• is :  상속 체크
• as?  :  특정 프로토콜로 downcast 함
특정 프로토콜을 구현하지 않은 경우 nil 반환
• as!  : 특정 프로토콜로 downcast 함
특정 프로토콜을 구현하지 않은 경우 error
Protocol 체크
protocol HasArea {
var area: Double { get }
}
class Circle: HasArea {
let pi = 3.1415927
var radius: Double
var area: Double { return pi * radius * radius }
init(radius: Double) { self.radius = radius }
}
class Country: HasArea {
var area: Double
init(area: Double) { self.area = area }
}
Protocol 체크
class Animal {
var legs: Int
init(legs: Int) { self.legs = legs }
}
let objects: [AnyObject] = [
Circle(radius: 2.0),
Country(area: 243_610),
Animal(legs: 4)
]
for object in objects {
if let objectWithArea = object as? HasArea {
print("Area is (objectWithArea.area)")
} else {
print("Something that doesn't have an area")
}
}
// Area is 12.5663708
// Area is 243610.0
// Something that doesn't have an area
optional protocol 구현
@objc protocol CounterDataSource {
@objc optional func increment(forCount count: Int) -> Int
@objc optional var fixedIncrement: Int { get }
}
class Counter {
var count = 0
var dataSource: CounterDataSource?
func increment() {
if let amount = dataSource?.increment?(forCount: count) {
count += amount
} else if let amount = dataSource?.fixedIncrement {
count += amount
}
}
}
• @objc
optional protocol 구현
• @objc 의 예
class ThreeSource: NSObject, CounterDataSource {
let fixedIncrement = 3
}
var counter = Counter()
counter.dataSource = ThreeSource()
for _ in 1...4 {
counter.increment()
print(counter.count)
}
// 3
// 6
// 9
// 12
optional protocol 구현
• @objc 의 예
class ThreeSource: NSObject, CounterDataSource {
let fixedIncrement = 3
}
@objc class TowardsZeroSource: NSObject, CounterDataSource {
func increment(forCount count: Int) -> Int {
if count == 0 {
return 0
} else if count < 0 {
return 1
} else {
return -1
}
}
}
counter.count = -4
counter.dataSource = TowardsZeroSource()
for _ in 1...5 {
counter.increment()
print(counter.count)
}

More Related Content

What's hot

Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicNew Relic
 
sizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may mattersizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may matter
Dawid Weiss
 
Grammarware Memes
Grammarware MemesGrammarware Memes
Grammarware Memes
Eelco Visser
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
Jung Kim
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
roxlu
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011
Stephen Chin
 
C++ 11 usage experience
C++ 11 usage experienceC++ 11 usage experience
C++ 11 usage experience
GlobalLogic Ukraine
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
Jacek Laskowski
 
Swift internals
Swift internalsSwift internals
Swift internals
Jung Kim
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
Mahmoud Samir Fayed
 
Pig Introduction to Pig
Pig Introduction to PigPig Introduction to Pig
Pig Introduction to Pig
Chris Wilkes
 
Java string handling
Java string handlingJava string handling
Java string handling
GaneshKumarKanthiah
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
nikomatsakis
 
LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기
Wanbok Choi
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたTaro Matsuzawa
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
OUM SAOKOSAL
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 

What's hot (20)

Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
Threads in python
Threads in pythonThreads in python
Threads in python
 
Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New Relic
 
sizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may mattersizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may matter
 
Grammarware Memes
Grammarware MemesGrammarware Memes
Grammarware Memes
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011
 
C++ 11 usage experience
C++ 11 usage experienceC++ 11 usage experience
C++ 11 usage experience
 
oop objects_classes
oop objects_classesoop objects_classes
oop objects_classes
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Swift internals
Swift internalsSwift internals
Swift internals
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
 
Pig Introduction to Pig
Pig Introduction to PigPig Introduction to Pig
Pig Introduction to Pig
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 

Viewers also liked

집단지성 프로그래밍 02-추천시스템 만들기
집단지성 프로그래밍 02-추천시스템 만들기집단지성 프로그래밍 02-추천시스템 만들기
집단지성 프로그래밍 02-추천시스템 만들기
Kwang Woo NAM
 
Swift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : EnumerationSwift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : Enumeration
Kwang Woo NAM
 
집단지성 프로그래밍 06-의사결정트리-01
집단지성 프로그래밍 06-의사결정트리-01집단지성 프로그래밍 06-의사결정트리-01
집단지성 프로그래밍 06-의사결정트리-01
Kwang Woo NAM
 
집단지성 프로그래밍 01-데이터마이닝 개요
집단지성 프로그래밍 01-데이터마이닝 개요집단지성 프로그래밍 01-데이터마이닝 개요
집단지성 프로그래밍 01-데이터마이닝 개요
Kwang Woo NAM
 
Swift 3 Programming for iOS
Swift 3 Programming for iOSSwift 3 Programming for iOS
Swift 3 Programming for iOS
Kwang Woo NAM
 
집단지성 프로그래밍 04-검색과 랭킹-02
집단지성 프로그래밍 04-검색과 랭킹-02집단지성 프로그래밍 04-검색과 랭킹-02
집단지성 프로그래밍 04-검색과 랭킹-02
Kwang Woo NAM
 
집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링
Kwang Woo NAM
 
[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축
Kwang Woo NAM
 
[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석
Kwang Woo NAM
 
[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요
Kwang Woo NAM
 
집단지성 프로그래밍 05-문서필터링-02
집단지성 프로그래밍 05-문서필터링-02집단지성 프로그래밍 05-문서필터링-02
집단지성 프로그래밍 05-문서필터링-02
Kwang Woo NAM
 
[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용
Kwang Woo NAM
 
[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해
Kwang Woo NAM
 
[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델
Kwang Woo NAM
 
[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계
Kwang Woo NAM
 
[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도
Kwang Woo NAM
 
[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델
Kwang Woo NAM
 
[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보
Kwang Woo NAM
 
Swift 3 Programming for iOS: error handling
Swift 3 Programming for iOS: error handlingSwift 3 Programming for iOS: error handling
Swift 3 Programming for iOS: error handling
Kwang Woo NAM
 
Swift 3 Programming for iOS : class and structure
Swift 3 Programming for iOS : class and structureSwift 3 Programming for iOS : class and structure
Swift 3 Programming for iOS : class and structure
Kwang Woo NAM
 

Viewers also liked (20)

집단지성 프로그래밍 02-추천시스템 만들기
집단지성 프로그래밍 02-추천시스템 만들기집단지성 프로그래밍 02-추천시스템 만들기
집단지성 프로그래밍 02-추천시스템 만들기
 
Swift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : EnumerationSwift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : Enumeration
 
집단지성 프로그래밍 06-의사결정트리-01
집단지성 프로그래밍 06-의사결정트리-01집단지성 프로그래밍 06-의사결정트리-01
집단지성 프로그래밍 06-의사결정트리-01
 
집단지성 프로그래밍 01-데이터마이닝 개요
집단지성 프로그래밍 01-데이터마이닝 개요집단지성 프로그래밍 01-데이터마이닝 개요
집단지성 프로그래밍 01-데이터마이닝 개요
 
Swift 3 Programming for iOS
Swift 3 Programming for iOSSwift 3 Programming for iOS
Swift 3 Programming for iOS
 
집단지성 프로그래밍 04-검색과 랭킹-02
집단지성 프로그래밍 04-검색과 랭킹-02집단지성 프로그래밍 04-검색과 랭킹-02
집단지성 프로그래밍 04-검색과 랭킹-02
 
집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링
 
[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축
 
[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석
 
[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요
 
집단지성 프로그래밍 05-문서필터링-02
집단지성 프로그래밍 05-문서필터링-02집단지성 프로그래밍 05-문서필터링-02
집단지성 프로그래밍 05-문서필터링-02
 
[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용
 
[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해
 
[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델
 
[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계
 
[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도
 
[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델
 
[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보
 
Swift 3 Programming for iOS: error handling
Swift 3 Programming for iOS: error handlingSwift 3 Programming for iOS: error handling
Swift 3 Programming for iOS: error handling
 
Swift 3 Programming for iOS : class and structure
Swift 3 Programming for iOS : class and structureSwift 3 Programming for iOS : class and structure
Swift 3 Programming for iOS : class and structure
 

Similar to Swift 3 Programming for iOS : Protocol

Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio
 
The Ring programming language version 1.9 book - Part 101 of 210
The Ring programming language version 1.9 book - Part 101 of 210The Ring programming language version 1.9 book - Part 101 of 210
The Ring programming language version 1.9 book - Part 101 of 210
Mahmoud Samir Fayed
 
From android/java to swift (3)
From android/java to swift (3)From android/java to swift (3)
From android/java to swift (3)
allanh0526
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
Simon Ritter
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
Oswald Campesato
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
Joseph Kuo
 
Swift Study #7
Swift Study #7Swift Study #7
Swift Study #7
chanju Jeon
 
外部環境への依存をテストする
外部環境への依存をテストする外部環境への依存をテストする
外部環境への依存をテストする
Shunsuke Maeda
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
Emertxe Information Technologies Pvt Ltd
 
ELK stack at weibo.com
ELK stack at weibo.comELK stack at weibo.com
ELK stack at weibo.com
琛琳 饶
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
Lars Marius Garshol
 
Writing Docker monitoring agent with Go
Writing Docker monitoring agent with GoWriting Docker monitoring agent with Go
Writing Docker monitoring agent with Go
Naoki AINOYA
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
Sivadon Chaisiri
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
James Ford
 
Vapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymoreVapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymore
Milan Vít
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopyayaria
 
The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212
Mahmoud Samir Fayed
 

Similar to Swift 3 Programming for iOS : Protocol (20)

Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
 
The Ring programming language version 1.9 book - Part 101 of 210
The Ring programming language version 1.9 book - Part 101 of 210The Ring programming language version 1.9 book - Part 101 of 210
The Ring programming language version 1.9 book - Part 101 of 210
 
From android/java to swift (3)
From android/java to swift (3)From android/java to swift (3)
From android/java to swift (3)
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
Swift Study #7
Swift Study #7Swift Study #7
Swift Study #7
 
外部環境への依存をテストする
外部環境への依存をテストする外部環境への依存をテストする
外部環境への依存をテストする
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
 
ELK stack at weibo.com
ELK stack at weibo.comELK stack at weibo.com
ELK stack at weibo.com
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Writing Docker monitoring agent with Go
Writing Docker monitoring agent with GoWriting Docker monitoring agent with Go
Writing Docker monitoring agent with Go
 
Apache Thrift
Apache ThriftApache Thrift
Apache Thrift
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
Vapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymoreVapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymore
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
 
Pdxpugday2010 pg90
Pdxpugday2010 pg90Pdxpugday2010 pg90
Pdxpugday2010 pg90
 
The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212
 

More from Kwang Woo NAM

메타버스시대의_디지털트윈과_지역성v01.pdf
메타버스시대의_디지털트윈과_지역성v01.pdf메타버스시대의_디지털트윈과_지역성v01.pdf
메타버스시대의_디지털트윈과_지역성v01.pdf
Kwang Woo NAM
 
해양디지털트윈v02.pdf
해양디지털트윈v02.pdf해양디지털트윈v02.pdf
해양디지털트윈v02.pdf
Kwang Woo NAM
 
Moving objects media data computing(2019)
Moving objects media data computing(2019)Moving objects media data computing(2019)
Moving objects media data computing(2019)
Kwang Woo NAM
 
Moving Objects and Spatial Data Computing
Moving Objects and Spatial Data ComputingMoving Objects and Spatial Data Computing
Moving Objects and Spatial Data Computing
Kwang Woo NAM
 
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
Kwang Woo NAM
 
[공간정보시스템 개론] L04 항공사진의 이해
[공간정보시스템 개론] L04 항공사진의 이해[공간정보시스템 개론] L04 항공사진의 이해
[공간정보시스템 개론] L04 항공사진의 이해
Kwang Woo NAM
 
[공간정보시스템 개론] L07 원격탐사의 개념과 활용
[공간정보시스템 개론] L07 원격탐사의 개념과 활용[공간정보시스템 개론] L07 원격탐사의 개념과 활용
[공간정보시스템 개론] L07 원격탐사의 개념과 활용
Kwang Woo NAM
 
Swift 3 Programming for iOS : Closure
Swift 3 Programming for iOS  : ClosureSwift 3 Programming for iOS  : Closure
Swift 3 Programming for iOS : Closure
Kwang Woo NAM
 
Swift 3 Programming for iOS: Function
Swift 3 Programming for iOS: FunctionSwift 3 Programming for iOS: Function
Swift 3 Programming for iOS: Function
Kwang Woo NAM
 
Swift 3 Programming for iOS : Collection
Swift 3 Programming for iOS : CollectionSwift 3 Programming for iOS : Collection
Swift 3 Programming for iOS : Collection
Kwang Woo NAM
 
Swift 3 Programming for iOS : Control flow
Swift 3 Programming for iOS : Control flowSwift 3 Programming for iOS : Control flow
Swift 3 Programming for iOS : Control flow
Kwang Woo NAM
 
Swift 3 Programming for iOS : data type
Swift 3 Programming for iOS : data typeSwift 3 Programming for iOS : data type
Swift 3 Programming for iOS : data type
Kwang Woo NAM
 
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
Kwang Woo NAM
 

More from Kwang Woo NAM (13)

메타버스시대의_디지털트윈과_지역성v01.pdf
메타버스시대의_디지털트윈과_지역성v01.pdf메타버스시대의_디지털트윈과_지역성v01.pdf
메타버스시대의_디지털트윈과_지역성v01.pdf
 
해양디지털트윈v02.pdf
해양디지털트윈v02.pdf해양디지털트윈v02.pdf
해양디지털트윈v02.pdf
 
Moving objects media data computing(2019)
Moving objects media data computing(2019)Moving objects media data computing(2019)
Moving objects media data computing(2019)
 
Moving Objects and Spatial Data Computing
Moving Objects and Spatial Data ComputingMoving Objects and Spatial Data Computing
Moving Objects and Spatial Data Computing
 
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
 
[공간정보시스템 개론] L04 항공사진의 이해
[공간정보시스템 개론] L04 항공사진의 이해[공간정보시스템 개론] L04 항공사진의 이해
[공간정보시스템 개론] L04 항공사진의 이해
 
[공간정보시스템 개론] L07 원격탐사의 개념과 활용
[공간정보시스템 개론] L07 원격탐사의 개념과 활용[공간정보시스템 개론] L07 원격탐사의 개념과 활용
[공간정보시스템 개론] L07 원격탐사의 개념과 활용
 
Swift 3 Programming for iOS : Closure
Swift 3 Programming for iOS  : ClosureSwift 3 Programming for iOS  : Closure
Swift 3 Programming for iOS : Closure
 
Swift 3 Programming for iOS: Function
Swift 3 Programming for iOS: FunctionSwift 3 Programming for iOS: Function
Swift 3 Programming for iOS: Function
 
Swift 3 Programming for iOS : Collection
Swift 3 Programming for iOS : CollectionSwift 3 Programming for iOS : Collection
Swift 3 Programming for iOS : Collection
 
Swift 3 Programming for iOS : Control flow
Swift 3 Programming for iOS : Control flowSwift 3 Programming for iOS : Control flow
Swift 3 Programming for iOS : Control flow
 
Swift 3 Programming for iOS : data type
Swift 3 Programming for iOS : data typeSwift 3 Programming for iOS : data type
Swift 3 Programming for iOS : data type
 
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
 

Recently uploaded

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 

Recently uploaded (20)

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 

Swift 3 Programming for iOS : Protocol

  • 1. Swift 3 : Protocols 군산대학교 컴퓨터정보통신공학부 컴퓨터정보공학전공 남 광 우 kwnam@kunsan.ac.kr Swift 3 Tour and Language Guide by Apple
  • 2. Protocol • 정의 • 특정 태스크나 기능들에 대한 메소드, 속성, 또는 요 구사항들의 기본 사항들을 정의 • Java 등의 인터페이스(interface) • 사용 • interface와 동일하게 다중 구현이 가능 • 객체 상속은 1개만 protocol 프로토콜이름 { // protocol definition goes here }
  • 3. Protocol • 사용 • protocol의 다중 구현 • class와 potocol의 복합 사용 struct SomeStructure: FirstProtocol, AnotherProtocol { // structure definition goes here } class SomeClass: SomeSuperclass, FirstProtocol, AnotherProtocol { // class definition goes here }
  • 4. Protocol : Property • Property 구현 요구사항 정의 • static 키워드 protocol SomeProtocol { var mustBeSettable: Int { get set } var doesNotNeedToBeSettable: Int { get } } protocol AnotherProtocol { static var someTypeProperty: Int { get set } }
  • 5. Protocol : Property • protocol 사용의 예 • FullyNamed protocol • Person struct protocol FullyNamed { var fullName: String { get } } struct Person: FullyNamed { var fullName: String } let john = Person(fullName: "John Appleseed") // john.fullName is "John Appleseed"
  • 6. Protocol : Property • protocol 사용의 예 • Starship class class Starship: FullyNamed { var prefix: String? var name: String init(name: String, prefix: String? = nil) { self.name = name self.prefix = prefix } var fullName: String { return (prefix != nil ? prefix! + " " : "") + name } } var ncc1701 = Starship(name: "Enterprise", prefix: "USS") // ncc1701.fullName is "USS Enterprise"
  • 7. Protocol : Method • method protocol • method protocol의 예 protocol SomeProtocol { static func someTypeMethod() } protocol RandomNumberGenerator { func random() -> Double }
  • 8. Protocol : Method • method protocol의 예 class LinearCongruentialGenerator: RandomNumberGenerator { var lastRandom = 42.0 let m = 139968.0 let a = 3877.0 let c = 29573.0 func random() -> Double { lastRandom = ((lastRandom * a +).truncatingRemainder(dividingBy:m)) return lastRandom / m } } let generator = LinearCongruentialGenerator() print("Here's a random number: (generator.random())") // Prints "Here's a random number: 0.37464991998171“ print("And another one: (generator.random())") // Prints "And another one: 0.729023776863283"
  • 9. Protocol : Mutating Method • mutating method protocol • 예 protocol Togglable { mutating func toggle() } enum OnOffSwitch: Togglable { case off, on mutating func toggle() { switch self { case .off: self = .on case .on: self = .off } } } var lightSwitch = OnOffSwitch.off lightSwitch.toggle() // lightSwitch is now equal to .on
  • 10. Protocol : Initializer • init protocol • initializer 프로토콜을 구현 할 경우 required 명시 protocol SomeProtocol { init(someParameter: Int) } class SomeClass: SomeProtocol { required init(someParameter: Int) { // initializer implementation goes here } }
  • 11. Protocol : Initializer • init protocol의 예  • 복합 상속에서의 사용 protocol SomeProtocol { init() } class SomeSuperClass { init() { // initializer implementation goes here } } class SomeSubClass: SomeSuperClass, SomeProtocol { required override init() { // initializer implementation goes here } }
  • 12. Type으로서의 protocol • Type으로 protocol 사용 예  • RandomNumberGenerator • 사용 class Dice { let sides: Int let generator: RandomNumberGenerator init(sides: Int, generator: RandomNumberGenerator) { self.sides = sides self.generator = generator } func roll() -> Int { return Int( generator.random() * Double(sides)) + 1 } } var d6 = Dice(sides: 6, generator: LinearCongruentialGenerator()) for _ in 1...5 { print("Random dice roll is (d6.roll())") }
  • 13. Delegation 패턴에서의 사용 • Delegation(위임) 패턴이란? • 특정 클래스의 구현 중 일부를 다른 클래스에서 구현 할 수 있도록 하는 패턴 참고 : http://seorenn.blogspot.kr/2015/01/swift‐delegation‐pattern.html class  A protocol  P { pmethod } var delegate: P amethod(){ //다른 클래스에 서 구현할 메소드 dp.pmethod()  } class  B : P var da : A a = A(); b = B(); a.delegate = b; pmethod(){ } da.amethod(); class  C : P var da : A pmethod(){ } da.amethod(); a = A(); c = C(); a.delegate = c;
  • 14. Delegation 패턴에서의 사용 • DiceGame에서의 Delegation protocol DiceGame { var dice: Dice { get } func play() } protocol DiceGameDelegate { func gameDidStart(_ game: DiceGame) func game(_ game: DiceGame, idStartNewTurnWithDiceRoll diceRoll: Int) func gameDidEnd(_ game: DiceGame) }
  • 15. Delegation 패턴에서의 사용 • DiceGame에서의 Delegation class SnakesAndLadders: DiceGame { let finalSquare = 25 let dice = Dice(sides: 6, generator: LinearCongruentialGenerator()) var square = 0 var board: [Int] init() { board = Array(repeating: 0, count: finalSquare + 1) board[03] = +08; board[06] = +11; board[09] = +09; board[10] = +02 board[14] = -10; board[19] = -11; board[22] = -02; board[24] = -08 } var delegate: DiceGameDelegate? func play() { square = 0 delegate?.gameDidStart(self) gameLoop: while square != finalSquare { let diceRoll = dice.roll() delegate?.game(self, didStartNewTurnWithDiceRoll: diceRoll) switch square + diceRoll { case finalSquare: break gameLoop case let newSquare where newSquare > finalSquare: continue gameLoop default: square += diceRoll square += board[square] } } delegate?.gameDidEnd(self) } }
  • 16. Delegation 패턴에서의 사용 • DiceGameTracker의 구현 class DiceGameTracker: DiceGameDelegate { var numberOfTurns = 0 func gameDidStart(_ game: DiceGame) { numberOfTurns = 0 if game is SnakesAndLadders { print("Started a new game of Snakes and Ladders") } print("The game is using a (game.dice.sides)-sided dice") } func game(_ game: DiceGame, didStartNewTurnWithDiceRoll diceRoll: Int) { numberOfTurns += 1 print("Rolled a (diceRoll)") } func gameDidEnd(_ game: DiceGame) { print("The game lasted for (numberOfTurns) turns") } }
  • 17. Delegation 패턴에서의 사용 • DiceGame과 DiceGameTracker의 연결 let tracker = DiceGameTracker() let game = SnakesAndLadders() game.delegate = tracker game.play() // Started a new game of Snakes and Ladders // The game is using a 6-sided dice // Rolled a 3 // Rolled a 5 // Rolled a 4 // Rolled a 5 // The game lasted for 4 turn
  • 18. Extension과 Protocol protocol TextRepresentable { var textualDescription: String { get } } extension Dice: TextRepresentable { var textualDescription: String { return "A (sides)-sided dice" } } let d12 = Dice(sides: 12, generator: LinearCongruentialGenerator()) print(d12.textualDescription) // Prints "A 12-sided dice" class Dice { let sides: Int let generator: RandomNumberGenerator init(sides: Int, generator: RandomNumberGenerator) { self.sides = sides self.generator = generator } func roll() -> Int { return Int( generator.random() * Double(sides)) + 1 } }
  • 19. extension SnakesAndLadders: TextRepresentable { var textualDescription: String { return "A game of Snakes and Ladders with (finalSquare) squares" } } print( game.textualDescription ) // Prints "A game of Snakes and Ladders with 25 squares" Extension과 Protocol let tracker = DiceGameTracker() let game = SnakesAndLadders() game.delegate = tracker game.play()
  • 20. Protocol Adoption struct Hamster { var name: String var textualDescription: String { return "A hamster named (name)" } } extension Hamster: TextRepresentable {} let simonTheHamster = Hamster(name: "Simon") let somethingTextRepresentable: TextRepresentable = simonTheHamster print( somethingTextRepresentable.textualDescription ) // Prints "A hamster named Simon"
  • 21. Protocol Type의 Collection let things: [TextRepresentable] = [game, d12, simonTheHamster] for thing in things { print(thing.textualDescription) } // A game of Snakes and Ladders with 25 squares // A 12-sided dice // A hamster named Simon
  • 22. Protocol 상속 protocol InheritingProtocol: SomeProtocol, AnotherProtocol { // protocol definition goes here } protocol PrettyTextRepresentable: TextRepresentable { var prettyTextualDescription: String { get } } • Protocol의 상속 정의 • protocol 상속의 예
  • 23. extension SnakesAndLadders: PrettyTextRepresentable { var prettyTextualDescription: String { var output = textualDescription + ":n" for index in 1...finalSquare { switch board[index] { case let ladder where ladder > 0: output += "▲ " case let snake where snake < 0: output += "▼ " default: output += "○ " } } return output } } • 상속된 protocol의 사용 Protocol 상속 print(game.prettyTextualDescription) // A game of Snakes and Ladders with 25 squares: // ○ ○ ▲ ○ ○ ▲ ○ ○ ▲ ▲ ○ ○ ○ ▼ ○ ○ ○ ○ ▼ ○ ○ ▼ ○ ▼
  • 24. Class-Only Protocol protocol SomeClassOnlyProtocol: class, SomeInheritedProtocol { // class-only protocol definition goes here } • class 프로토콜
  • 25. & protocol composition protocol Named { var name: String { get } } protocol Aged { var age: Int { get } } struct Person: Named, Aged { var name: String var age: Int } func wishHappyBirthday(to celebrator: Named & Aged) { print("Happy birthday, (celebrator.name), you're (celebrator.age)!") } let birthdayPerson = Person(name: "Malcolm", age: 21) wishHappyBirthday(to: birthdayPerson) // Prints "Happy birthday, Malcolm, you're 21!"
  • 26. Protocol 체크 • protocol의 타입 체크 • is :  상속 체크 • as?  :  특정 프로토콜로 downcast 함 특정 프로토콜을 구현하지 않은 경우 nil 반환 • as!  : 특정 프로토콜로 downcast 함 특정 프로토콜을 구현하지 않은 경우 error
  • 27. Protocol 체크 protocol HasArea { var area: Double { get } } class Circle: HasArea { let pi = 3.1415927 var radius: Double var area: Double { return pi * radius * radius } init(radius: Double) { self.radius = radius } } class Country: HasArea { var area: Double init(area: Double) { self.area = area } }
  • 28. Protocol 체크 class Animal { var legs: Int init(legs: Int) { self.legs = legs } } let objects: [AnyObject] = [ Circle(radius: 2.0), Country(area: 243_610), Animal(legs: 4) ] for object in objects { if let objectWithArea = object as? HasArea { print("Area is (objectWithArea.area)") } else { print("Something that doesn't have an area") } } // Area is 12.5663708 // Area is 243610.0 // Something that doesn't have an area
  • 29. optional protocol 구현 @objc protocol CounterDataSource { @objc optional func increment(forCount count: Int) -> Int @objc optional var fixedIncrement: Int { get } } class Counter { var count = 0 var dataSource: CounterDataSource? func increment() { if let amount = dataSource?.increment?(forCount: count) { count += amount } else if let amount = dataSource?.fixedIncrement { count += amount } } } • @objc
  • 30. optional protocol 구현 • @objc 의 예 class ThreeSource: NSObject, CounterDataSource { let fixedIncrement = 3 } var counter = Counter() counter.dataSource = ThreeSource() for _ in 1...4 { counter.increment() print(counter.count) } // 3 // 6 // 9 // 12
  • 31. optional protocol 구현 • @objc 의 예 class ThreeSource: NSObject, CounterDataSource { let fixedIncrement = 3 } @objc class TowardsZeroSource: NSObject, CounterDataSource { func increment(forCount count: Int) -> Int { if count == 0 { return 0 } else if count < 0 { return 1 } else { return -1 } } } counter.count = -4 counter.dataSource = TowardsZeroSource() for _ in 1...5 { counter.increment() print(counter.count) }