SlideShare a Scribd company logo
1 of 11
Download to read offline
Swift 3 :
Extensions
군산대학교 컴퓨터정보통신공학부 컴퓨터정보공학전공
남 광 우
kwnam@kunsan.ac.kr
Swift 3 Tour and Language Guide by Apple
Extension
• 정의
• 이미 존재하는 클래스나 구조체, 열거형 등의 객체에
새로운 기능을 확장
• 사용 목적
• Add computed instance properties / computed type properties
• Define instance methods and type methods
• Provide new initializers
• Define subscripts
• Define and use new nested types
• Make an existing type conform to a protocol
Extension 확장할 객체 {
// enumeration definition goes here
}
Extension
• 확장 구문의 정의
• Extension의 예
Extension 확장할 객체 {
// enumeration definition goes here
}
extension SomeType: SomeProtocol, AnotherProtocol {
// implementation of protocol requirements goes here
}
extension Double {
var km: Double { return self * 1_000.0 }
var m: Double { return self }
var cm: Double { return self / 100.0 }
var mm: Double { return self / 1_000.0 }
var ft: Double { return self / 3.28084 }
}
• Extension의 사용 예
• Extension의 연산 예
let oneInch = 25.4.mm
print("One inch is (oneInch) meters")
// Prints "One inch is 0.0254 meters“
let threeFeet = 3.ft
print("Three feet is (threeFeet) meters")
// Prints "Three feet is 0.914399970739201 meters"
let aMarathon = 42.km + 195.m
print("A marathon is (aMarathon) meters long")
// Prints "A marathon is 42195.0 meters long"
extension Double {
var km: Double { return self * 1_000.0 }
var m: Double { return self }
var cm: Double { return self / 100.0 }
var mm: Double { return self / 1_000.0 }
var ft: Double { return self / 3.28084 }
}
Extension
Extension : Initializer
• Initializer의 확장
• Before extension
struct Size {
var width = 0.0, height = 0.0
}
struct Point {
var x = 0.0, y = 0.0
}
struct Rect {
var origin = Point()
var size = Size()
}
let defaultRect = Rect()
let memberwiseRect =
Rect(origin: Point(x: 2.0, y: 2.0), size: Size(width: 5.0, height: 5.0))
Extension : Initializer
• Initializer의 확장
• After init extension
extension Rect {
init(center: Point, size: Size) {
let originX = center.x - (size.width / 2)
let originY = center.y - (size.height / 2)
self.init(origin: Point(x: originX, y: originY), size: size)
}
}
let centerRect = Rect(center: Point(x: 4.0, y: 4.0),
size: Size(width: 3.0, height: 3.0))
// centerRect's origin is (2.5, 2.5) and its size is (3.0, 3.0)
Extension : Method
• Method의 확장 예
• 사용 예
extension Int {
func repetitions (task: () -> Void) {
for _ in 0..<self {
task()
}
}
}
3.repetitions {
print("Hello!")
}
// Hello!
// Hello!
// Hello!
Extension : Method
• Mutating Method의 확장 예
• 사용 예
extension Int {
mutating func square() {
self = self * self
}
}
var someInt = 3
someInt.square()
// someInt is now 9
extension Int {
subscript(digitIndex: Int) -> Int {
var decimalBase = 1
for _ in 0..<digitIndex {
decimalBase *= 10
}
return (self / decimalBase) % 10
}
}
Extension : Subscript
• Subscript의 확장 예
• 사용 예
746381295[0]
// returns 5
746381295[1]
// returns 9
746381295[2]
// returns 2
746381295[8]
// returns 7
Extension : nested type
• Nested type의 확장 예
extension Int {
enum Kind {
case negative, zero, positive
}
var kind: Kind {
switch self {
case 0:
return .zero
case let x where x > 0:
return .positive
default:
return .negative
}
}
}
Extension : nested type
• Nested type의 사용 예
func printIntegerKinds(_ numbers: [Int]) {
for number in numbers {
switch number.kind {
case .negative:
print("- ", terminator: "")
case .zero:
print("0 ", terminator: "")
case .positive:
print("+ ", terminator: "")
}
}
print("")
}
printIntegerKinds([3, 19, -27, 0, -6, 0, 7])
// Prints "+ + - 0 - 0 + "

More Related Content

What's hot

Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc csKALAISELVI P
 
The Ring programming language version 1.3 book - Part 56 of 88
The Ring programming language version 1.3 book - Part 56 of 88The Ring programming language version 1.3 book - Part 56 of 88
The Ring programming language version 1.3 book - Part 56 of 88Mahmoud Samir Fayed
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4mohamedsamyali
 
Dive into Python Class
Dive into Python ClassDive into Python Class
Dive into Python ClassJim Yeh
 
The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210Mahmoud Samir Fayed
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationJacopo Mangiavacchi
 
Ios development
Ios developmentIos development
Ios developmentelnaqah
 
Descriptor Protocol
Descriptor ProtocolDescriptor Protocol
Descriptor Protocolrocketcircus
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - CJussi Pohjolainen
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2Vince Vo
 
Lecture 13, 14 & 15 c# cmd let programming and scripting
Lecture 13, 14 & 15   c# cmd let programming and scriptingLecture 13, 14 & 15   c# cmd let programming and scripting
Lecture 13, 14 & 15 c# cmd let programming and scriptingWiliam Ferraciolli
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 

What's hot (19)

Python programming : Abstract classes interfaces
Python programming : Abstract classes interfacesPython programming : Abstract classes interfaces
Python programming : Abstract classes interfaces
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
The Ring programming language version 1.3 book - Part 56 of 88
The Ring programming language version 1.3 book - Part 56 of 88The Ring programming language version 1.3 book - Part 56 of 88
The Ring programming language version 1.3 book - Part 56 of 88
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
 
Dive into Python Class
Dive into Python ClassDive into Python Class
Dive into Python Class
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 
Scala: A brief tutorial
Scala: A brief tutorialScala: A brief tutorial
Scala: A brief tutorial
 
Ios development
Ios developmentIos development
Ios development
 
Descriptor Protocol
Descriptor ProtocolDescriptor Protocol
Descriptor Protocol
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2
 
Lecture 13, 14 & 15 c# cmd let programming and scripting
Lecture 13, 14 & 15   c# cmd let programming and scriptingLecture 13, 14 & 15   c# cmd let programming and scripting
Lecture 13, 14 & 15 c# cmd let programming and scripting
 
Java string handling
Java string handlingJava string handling
Java string handling
 
.NET F# Class constructor
.NET F# Class constructor.NET F# Class constructor
.NET F# Class constructor
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 

Viewers also liked

Swift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : EnumerationSwift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : EnumerationKwang Woo NAM
 
Ieeepro techno solutions ieee dotnet project - privacy-preserving multi-keyw...
Ieeepro techno solutions  ieee dotnet project - privacy-preserving multi-keyw...Ieeepro techno solutions  ieee dotnet project - privacy-preserving multi-keyw...
Ieeepro techno solutions ieee dotnet project - privacy-preserving multi-keyw...ASAITHAMBIRAJAA
 
iOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesiOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesManjula Jonnalagadda
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming languageSwift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming languageHossam Ghareeb
 
[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축Kwang Woo NAM
 
[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석Kwang Woo NAM
 
[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요Kwang Woo NAM
 
[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축
[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축
[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축Kwang Woo NAM
 
[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계Kwang Woo NAM
 
[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도Kwang Woo NAM
 
[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해Kwang Woo NAM
 
[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델Kwang Woo NAM
 
[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용Kwang Woo NAM
 
[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델Kwang Woo NAM
 
[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보Kwang Woo NAM
 
Swift 3 Programming for iOS : subscript init
Swift 3 Programming for iOS : subscript initSwift 3 Programming for iOS : subscript init
Swift 3 Programming for iOS : subscript initKwang 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 handlingKwang Woo NAM
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageHossam Ghareeb
 

Viewers also liked (20)

Swift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : EnumerationSwift 3 Programming for iOS : Enumeration
Swift 3 Programming for iOS : Enumeration
 
Ieeepro techno solutions ieee dotnet project - privacy-preserving multi-keyw...
Ieeepro techno solutions  ieee dotnet project - privacy-preserving multi-keyw...Ieeepro techno solutions  ieee dotnet project - privacy-preserving multi-keyw...
Ieeepro techno solutions ieee dotnet project - privacy-preserving multi-keyw...
 
iOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesiOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changes
 
What's new in Swift 3
What's new in Swift 3What's new in Swift 3
What's new in Swift 3
 
Swift 3
Swift   3Swift   3
Swift 3
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming languageSwift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming language
 
[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축[공간정보시스템 개론] L11 공간정보의 구축
[공간정보시스템 개론] L11 공간정보의 구축
 
[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석[공간정보시스템 개론] L12 공간정보분석
[공간정보시스템 개론] L12 공간정보분석
 
[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요[공간정보시스템 개론] L01 공간정보시스템개요
[공간정보시스템 개론] L01 공간정보시스템개요
 
[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축
[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축
[FOSS4G KOREA 2014]Hadoop 상에서 MapReduce를 이용한 Spatial Big Data 집계와 시스템 구축
 
[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계[공간정보시스템 개론] L03 지구의형상과좌표체계
[공간정보시스템 개론] L03 지구의형상과좌표체계
 
[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도[공간정보시스템 개론] L05 우리나라의 수치지도
[공간정보시스템 개론] L05 우리나라의 수치지도
 
[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해[공간정보시스템 개론] L06 GIS의 이해
[공간정보시스템 개론] L06 GIS의 이해
 
[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델[공간정보시스템 개론] L09 공간 데이터 모델
[공간정보시스템 개론] L09 공간 데이터 모델
 
[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용[공간정보시스템 개론] L08 gnss의 개념과 활용
[공간정보시스템 개론] L08 gnss의 개념과 활용
 
[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델[공간정보시스템 개론] L10 수치표고모델
[공간정보시스템 개론] L10 수치표고모델
 
[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보[공간정보시스템 개론] L02 공간정보와 지리정보
[공간정보시스템 개론] L02 공간정보와 지리정보
 
Swift 3 Programming for iOS : subscript init
Swift 3 Programming for iOS : subscript initSwift 3 Programming for iOS : subscript init
Swift 3 Programming for iOS : subscript init
 
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 Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
 

Similar to Swift 3 Programming for iOS : extension

Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdfPowerfullBoy1
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
SenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsSenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsMats Bryntse
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
c++ lecture 1
c++ lecture 1c++ lecture 1
c++ lecture 1sai kumar
 
c++ introduction
c++ introductionc++ introduction
c++ introductionsai kumar
 
c++ lecture 1
c++ lecture 1c++ lecture 1
c++ lecture 1sai kumar
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3Sónia
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdfjeeteshmalani1
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cSunny Shaikh
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objectsmcollison
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming NeedsRaja Sekhar
 

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

Object and class
Object and classObject and class
Object and class
 
Bc0037
Bc0037Bc0037
Bc0037
 
Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdf
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Ext oo
Ext ooExt oo
Ext oo
 
SenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsSenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext js
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Unit ii
Unit iiUnit ii
Unit ii
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
c++ lecture 1
c++ lecture 1c++ lecture 1
c++ lecture 1
 
c++ introduction
c++ introductionc++ introduction
c++ introduction
 
c++ lecture 1
c++ lecture 1c++ lecture 1
c++ lecture 1
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 

More from Kwang Woo NAM

메타버스시대의_디지털트윈과_지역성v01.pdf
메타버스시대의_디지털트윈과_지역성v01.pdf메타버스시대의_디지털트윈과_지역성v01.pdf
메타버스시대의_디지털트윈과_지역성v01.pdfKwang Woo NAM
 
해양디지털트윈v02.pdf
해양디지털트윈v02.pdf해양디지털트윈v02.pdf
해양디지털트윈v02.pdfKwang 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 ComputingKwang Woo NAM
 
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석
세월호/ 타이타닉호 사고의 빅 데이터 방법론적 분석Kwang Woo NAM
 
[공간정보시스템 개론] L04 항공사진의 이해
[공간정보시스템 개론] L04 항공사진의 이해[공간정보시스템 개론] L04 항공사진의 이해
[공간정보시스템 개론] L04 항공사진의 이해Kwang Woo NAM
 
[공간정보시스템 개론] L07 원격탐사의 개념과 활용
[공간정보시스템 개론] L07 원격탐사의 개념과 활용[공간정보시스템 개론] L07 원격탐사의 개념과 활용
[공간정보시스템 개론] L07 원격탐사의 개념과 활용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 structureKwang Woo NAM
 
Swift 3 Programming for iOS : Closure
Swift 3 Programming for iOS  : ClosureSwift 3 Programming for iOS  : Closure
Swift 3 Programming for iOS : ClosureKwang Woo NAM
 
Swift 3 Programming for iOS: Function
Swift 3 Programming for iOS: FunctionSwift 3 Programming for iOS: Function
Swift 3 Programming for iOS: FunctionKwang Woo NAM
 
Swift 3 Programming for iOS : Collection
Swift 3 Programming for iOS : CollectionSwift 3 Programming for iOS : Collection
Swift 3 Programming for iOS : CollectionKwang 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 flowKwang 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 typeKwang Woo NAM
 
Swift 3 Programming for iOS
Swift 3 Programming for iOSSwift 3 Programming for iOS
Swift 3 Programming for iOSKwang Woo NAM
 
집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링Kwang Woo NAM
 
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01Kwang Woo NAM
 

More from Kwang Woo NAM (16)

메타버스시대의_디지털트윈과_지역성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 : 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
 
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
 
Swift 3 Programming for iOS
Swift 3 Programming for iOSSwift 3 Programming for iOS
Swift 3 Programming for iOS
 
집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링
 
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
집단지성 프로그래밍 07-고급 분류 기법-커널 기법과 svm-01
 

Recently uploaded

WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2
 

Recently uploaded (20)

WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 

Swift 3 Programming for iOS : extension

  • 1. Swift 3 : Extensions 군산대학교 컴퓨터정보통신공학부 컴퓨터정보공학전공 남 광 우 kwnam@kunsan.ac.kr Swift 3 Tour and Language Guide by Apple
  • 2. Extension • 정의 • 이미 존재하는 클래스나 구조체, 열거형 등의 객체에 새로운 기능을 확장 • 사용 목적 • Add computed instance properties / computed type properties • Define instance methods and type methods • Provide new initializers • Define subscripts • Define and use new nested types • Make an existing type conform to a protocol Extension 확장할 객체 { // enumeration definition goes here }
  • 3. Extension • 확장 구문의 정의 • Extension의 예 Extension 확장할 객체 { // enumeration definition goes here } extension SomeType: SomeProtocol, AnotherProtocol { // implementation of protocol requirements goes here } extension Double { var km: Double { return self * 1_000.0 } var m: Double { return self } var cm: Double { return self / 100.0 } var mm: Double { return self / 1_000.0 } var ft: Double { return self / 3.28084 } }
  • 4. • Extension의 사용 예 • Extension의 연산 예 let oneInch = 25.4.mm print("One inch is (oneInch) meters") // Prints "One inch is 0.0254 meters“ let threeFeet = 3.ft print("Three feet is (threeFeet) meters") // Prints "Three feet is 0.914399970739201 meters" let aMarathon = 42.km + 195.m print("A marathon is (aMarathon) meters long") // Prints "A marathon is 42195.0 meters long" extension Double { var km: Double { return self * 1_000.0 } var m: Double { return self } var cm: Double { return self / 100.0 } var mm: Double { return self / 1_000.0 } var ft: Double { return self / 3.28084 } } Extension
  • 5. Extension : Initializer • Initializer의 확장 • Before extension struct Size { var width = 0.0, height = 0.0 } struct Point { var x = 0.0, y = 0.0 } struct Rect { var origin = Point() var size = Size() } let defaultRect = Rect() let memberwiseRect = Rect(origin: Point(x: 2.0, y: 2.0), size: Size(width: 5.0, height: 5.0))
  • 6. Extension : Initializer • Initializer의 확장 • After init extension extension Rect { init(center: Point, size: Size) { let originX = center.x - (size.width / 2) let originY = center.y - (size.height / 2) self.init(origin: Point(x: originX, y: originY), size: size) } } let centerRect = Rect(center: Point(x: 4.0, y: 4.0), size: Size(width: 3.0, height: 3.0)) // centerRect's origin is (2.5, 2.5) and its size is (3.0, 3.0)
  • 7. Extension : Method • Method의 확장 예 • 사용 예 extension Int { func repetitions (task: () -> Void) { for _ in 0..<self { task() } } } 3.repetitions { print("Hello!") } // Hello! // Hello! // Hello!
  • 8. Extension : Method • Mutating Method의 확장 예 • 사용 예 extension Int { mutating func square() { self = self * self } } var someInt = 3 someInt.square() // someInt is now 9
  • 9. extension Int { subscript(digitIndex: Int) -> Int { var decimalBase = 1 for _ in 0..<digitIndex { decimalBase *= 10 } return (self / decimalBase) % 10 } } Extension : Subscript • Subscript의 확장 예 • 사용 예 746381295[0] // returns 5 746381295[1] // returns 9 746381295[2] // returns 2 746381295[8] // returns 7
  • 10. Extension : nested type • Nested type의 확장 예 extension Int { enum Kind { case negative, zero, positive } var kind: Kind { switch self { case 0: return .zero case let x where x > 0: return .positive default: return .negative } } }
  • 11. Extension : nested type • Nested type의 사용 예 func printIntegerKinds(_ numbers: [Int]) { for number in numbers { switch number.kind { case .negative: print("- ", terminator: "") case .zero: print("0 ", terminator: "") case .positive: print("+ ", terminator: "") } } print("") } printIntegerKinds([3, 19, -27, 0, -6, 0, 7]) // Prints "+ + - 0 - 0 + "