SlideShare a Scribd company logo
1 of 30
한국카카오은행안정민
StringInterpolation과 SwiftUI
• 現 카카오뱅크 iOS 개발자 (16.10 ~ )
• 블로그 운영 : minsone.github.io
소개
• StringInterpolation 소개
• StringInterpolation를 이용한 RichString 만들기
• SwiftUI를 이용한 RichString 만들기
• 번외 - FunctionBuilder를 이용한 RichString 만들
기
• QnA
목차
StringInterpolation
String Interpolation
하나 이상의 placeholders("(variable)")를 포함하는 문자열 리
터럴을 실행하여 placeholders를 해당 값으로 대체한 결과를
산출
let txt1 = "Hello"
let txt2 = "World"
"(txt1), (txt2)" // Output: "Hello, World"
1: ""
2: (txt1) -> "Hello"
3: ", "
4: (txt2) -> "World"
5: ""
결과: "Hello, World"
let txt1 = "Hello"
let txt2 = "World"
"(txt1), (txt2)" // Output: "Hello, World"
DefaultStringInterpolation
- Apple/Swift의 StringInterpolation.swift 공개
let txt1 = "Hello"
let txt2 = "World"
"(txt1), (txt2)" // Output: "Hello, World"
Extend StringInterpolation
기존의 StringInterpolation에 확장.
let amount = 10000
print("(amount, style: .원)")
// Output: 10000원
enum Style { case 원 }
extension String.StringInterpolation {
mutating func appendInterpolation
(_ amount: Int, style: Style) {
switch style {
case .원: appendLiteral("(amount)원")
}
}
}
let amount = 10000
print("(amount, style: .원)")
// Output: 10000원
let amount = 10000
"(amount, currency: .원화)"
"(amount, currency: .유로)"
"(amount, currency: .달러)"
"(amount, currency: .위안)"
"(amount.toCurrency(.원화))"
"(amount.toCurrency(.유로))"
"(amount.toCurrency(.달러))"
"(amount.toCurrency(.위안))"
StringInterpolationProtocol
StringInterpolation을 구현하기 위한 프로토콜.
public protocol StringInterpolationProtocol {
associatedtype StringLiteralType : _ExpressibleByBuiltinStringLiteral
init(literalCapacity: Int, interpolationCount: Int)
mutating func appendLiteral(_ literal: Self.StringLiteralType)
}
struct CustomInterpolation: StringInterpolationProtocol {
var str: String
초기화
Parameters
literalCapacity 문자열 길이
interpolationCount 문자열 placeholder 개수
init(literalCapacity: Int, interpolationCount: Int) {
self.str = ""
}
mutating func appendLiteral(_ literal: String) {
str += literal
}
mutating func appendInterpolation(_ amount: Int,
style: Style) {
switch style {
case .원: appendLiteral("(amount)원")
}
}
}
literalCapacity 문자열 길이
interpolationCount 문자열 placeholder 개수
init(literalCapacity: Int, interpolationCount: Int) {
self.str = ""
}
let txt1 = "Hello"
let txt2 = "World"
"(txt1), (txt2)" // Output: "Hello, World"
literalCapacity = 2
interpolationCount = 2
struct CustomInterpolation: StringInterpolationProtocol {
var str: String
초기화
Parameters
literalCapacity 문자열 길이
interpolationCount 문자열 placeholder 개수
init(literalCapacity: Int, interpolationCount: Int) {
self.str = ""
}
mutating func appendLiteral(_ literal: String) {
str += literal
}
mutating func appendInterpolation(_ amount: Int,
style: Style) {
switch style {
case .원: appendLiteral("(amount)원")
}
}
}
public protocol ExpressibleByStringInterpolation :
ExpressibleByStringLiteral {
associatedtype StringInterpolation : StringInterpolationProtocol =
DefaultStringInterpolation where Self.StringLiteralType ==
Self.StringInterpolation.StringLiteralType
init(stringInterpolation: Self.StringInterpolation)
}
struct WonStyleString: ExpressibleByStringInterpolation {
var str = ""
init(stringLiteral: String) {
self.str = stringLiteral
}
init(stringInterpolation: CustomInterpolation) {
self.str = stringInterpolation.str
}
}
///////////////////////////////////////////////////////
let styleStr: WonStyleString =
"(10000, style: .원), (20000, style: .원)"
styleStr.str // Output: "10000원, 20000원"
StringInterpolation을
이용한 RichString 만들
기
NSAttributedString Library
SwiftRichString, BonMot, Atributika 와 같은 라이브러리를 통
해 좀 더 손쉽게 NSAttributedString을 만들어줌.
let style = Style {
$0.font = UIFont.systemFont(ofSize: 25)
$0.color = UIColor.blue
$0.alignment = .center
}
let attributedText = "Hello World!".set(style: style)
let style1 = Style {
$0.font = UIFont.systemFont(ofSize: 25)
$0.color = UIColor.blue
$0.alignment = .center
}
let style2 = Style {
$0.font = UIFont.systemFont(ofSize: 25)
$0.color = UIColor.green
$0.alignment = .center
}
let attr = NSMutableAttributedString(string: "")
attr.append("Hello ".set(style: style1))
attr.append("World".set(style: style2))
struct RichStringInterpolation: StringInterpolationProtocol {
var attr: NSMutableAttributedString
init(literalCapacity: Int, interpolationCount: Int) {
self.attr = NSMutableAttributedString()
}
mutating func appendLiteral(_ literal: String) {
attr.append(NSAttributedString(string: literal))
}
func appendInterpolation(_ string: String,
style: Style) {
let attr: NSAttributedString = string.set(style: style)
self.attr.append(attr)
}
}
struct AttrString: ExpressibleByStringInterpolation {
let attributedString: NSAttributedString
init(stringLiteral: String) {
let attr = NSAttributedString(string: stringLiteral)
self.attributedString = attr
}
init(stringInterpolation: RichStringInterpolation) {
self.attributedString = stringInterpolation.attr
}
}
///////////////////////////////////////////////////////
let attr: AttrString = """
("Hello", style: style1), ("World", style: style2))
"""
let attrString: NSAttributedString = attr.attributedString
let attr = NSMutableAttributedString(string: "")
attr.append("Hello ".set(style: style1))
attr.append("World".set(style: style2))
let attr: AttrString = """
("Hello", style: style1), ("World", style: style2))
"""
let attrString: NSAttributedString = attr.attributedString
SwiftUI을 이용한
RichString 만들기
FunctionBuilder을 이용
한 RichString 만들기
FunctionBuilder(Beta)
빌더 패턴을 좀 더 보기 쉽게 해주는 Annotation
struct ContentView : View {
var body: some View {
VStack {
Text("Hello").bold().color(.blue)
Text("World").bold().color(.red)
}
}
}
@_functionBuilder
struct NSAttributedStringBuilder {
static func buildBlock(_ components: NSAttributedString...)
-> NSAttributedString {
let attr = NSMutableAttributedString(string: "")
for component in components {
attr.append(component)
}
return attr
}
}
extension NSAttributedString {
convenience init(@NSAttributedStringBuilder
_ builder: () -> NSAttributedString) {
self.init(attributedString: builder())
}
NSAttributedString {
"Hello ".set(style: style1)
"World".set(style: style2)
}
NSAttributedString {
"Hello ".set(style: style1); "World".set(style: style2)
}
QnA
• Apple : SE-0228 -
Fix ExpressibleByStringInterpolation
• MSDN - Interpolation
• Wikipedia - String interpolation
• HackingWithSwift - What’s new in Swift 5.0
Reference

More Related Content

What's hot

An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architectureJung Kim
 
Javascript the New Parts v2
Javascript the New Parts v2Javascript the New Parts v2
Javascript the New Parts v2Federico Galassi
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Jung Kim
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
Checking Oracle VM VirtualBox. Part 2
Checking Oracle VM VirtualBox. Part 2Checking Oracle VM VirtualBox. Part 2
Checking Oracle VM VirtualBox. Part 2Andrey Karpov
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
Introduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in KotlinIntroduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in Kotlinvriddhigupta
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Jung Kim
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in goYusuke Kita
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival GuideGiordano Scalzo
 
From OCaml To Javascript At Skydeck
From OCaml To Javascript At SkydeckFrom OCaml To Javascript At Skydeck
From OCaml To Javascript At SkydeckJake Donham
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
 

What's hot (20)

An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
 
Javascript the New Parts v2
Javascript the New Parts v2Javascript the New Parts v2
Javascript the New Parts v2
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
 
ES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript SkillsES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript Skills
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Checking Oracle VM VirtualBox. Part 2
Checking Oracle VM VirtualBox. Part 2Checking Oracle VM VirtualBox. Part 2
Checking Oracle VM VirtualBox. Part 2
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
Introduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in KotlinIntroduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in Kotlin
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
 
From OCaml To Javascript At Skydeck
From OCaml To Javascript At SkydeckFrom OCaml To Javascript At Skydeck
From OCaml To Javascript At Skydeck
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
Go memory
Go memoryGo memory
Go memory
 

Similar to Letusgo 2019 Summer - StringInterpolation and SwiftUI

外部環境への依存をテストする
外部環境への依存をテストする外部環境への依存をテストする
外部環境への依存をテストするShunsuke Maeda
 
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
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesJamund Ferguson
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtextmeysholdt
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Cody Engel
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationJoni
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 
Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web AppsMark
 
How do you create a programming language for the JVM?
How do you create a programming language for the JVM?How do you create a programming language for the JVM?
How do you create a programming language for the JVM?Federico Tomassetti
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programmingtechmonkey4u
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015Charles Nutter
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기Arawn Park
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based TestingC4Media
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackGaryCoady
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopSages
 

Similar to Letusgo 2019 Summer - StringInterpolation and SwiftUI (20)

外部環境への依存をテストする
外部環境への依存をテストする外部環境への依存をテストする
外部環境への依存をテストする
 
From android/java to swift (3)
From android/java to swift (3)From android/java to swift (3)
From android/java to swift (3)
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
Taking User Input in Java
Taking User Input in JavaTaking User Input in Java
Taking User Input in Java
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web Apps
 
How do you create a programming language for the JVM?
How do you create a programming language for the JVM?How do you create a programming language for the JVM?
How do you create a programming language for the JVM?
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programming
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based Testing
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
 

More from 정민 안

20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁
20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁
20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁정민 안
 
Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가?
Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가? Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가?
Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가? 정민 안
 
20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf
20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf
20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf정민 안
 
InjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdf
InjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdfInjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdf
InjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdf정민 안
 
iOS Modular Architecture with Tuist
iOS Modular Architecture with TuistiOS Modular Architecture with Tuist
iOS Modular Architecture with Tuist정민 안
 
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기DI Container를 이용하여 레거시와 모듈화를 동시에 잡기
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기정민 안
 
MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기
MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기
MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기정민 안
 
A Framework Driven Development
A Framework Driven DevelopmentA Framework Driven Development
A Framework Driven Development정민 안
 
Debugging with xcode, lldb and chisel
Debugging with xcode, lldb and chiselDebugging with xcode, lldb and chisel
Debugging with xcode, lldb and chisel정민 안
 
fastlane을 이용하여 iOS/Mac 앱 관리하기
fastlane을 이용하여 iOS/Mac 앱 관리하기fastlane을 이용하여 iOS/Mac 앱 관리하기
fastlane을 이용하여 iOS/Mac 앱 관리하기정민 안
 
Introduce fastlane
Introduce fastlaneIntroduce fastlane
Introduce fastlane정민 안
 
형상관리 발표자료 안정민
형상관리 발표자료 안정민형상관리 발표자료 안정민
형상관리 발표자료 안정민정민 안
 

More from 정민 안 (13)

20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁
20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁
20240325 TuistNight 모듈로 나누면 알아두면 좋을 3가지 팁
 
Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가?
Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가? Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가?
Let'Swift 2023 iOS 애플리케이션 개발 생산성 고찰
- 정시 퇴근을 위해 우리는 어떻게 해야할 것인가?
 
20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf
20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf
20221131_레츠스위프트_2022_iOS개발에서_알아두면_좋은것들.pdf
 
InjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdf
InjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdfInjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdf
InjectionIII의 Hot Reload를 이용하여 앱 개발을 좀 더 편하게 하기.pdf
 
iOS Modular Architecture with Tuist
iOS Modular Architecture with TuistiOS Modular Architecture with Tuist
iOS Modular Architecture with Tuist
 
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기DI Container를 이용하여 레거시와 모듈화를 동시에 잡기
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기
 
MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기
MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기
MVC, MVVM, ReactorKit, VIPER를 거쳐 RIB 정착기
 
A Framework Driven Development
A Framework Driven DevelopmentA Framework Driven Development
A Framework Driven Development
 
Debugging with xcode, lldb and chisel
Debugging with xcode, lldb and chiselDebugging with xcode, lldb and chisel
Debugging with xcode, lldb and chisel
 
fastlane을 이용하여 iOS/Mac 앱 관리하기
fastlane을 이용하여 iOS/Mac 앱 관리하기fastlane을 이용하여 iOS/Mac 앱 관리하기
fastlane을 이용하여 iOS/Mac 앱 관리하기
 
Introduce fastlane
Introduce fastlaneIntroduce fastlane
Introduce fastlane
 
Git lecture
Git lectureGit lecture
Git lecture
 
형상관리 발표자료 안정민
형상관리 발표자료 안정민형상관리 발표자료 안정민
형상관리 발표자료 안정민
 

Recently uploaded

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Recently uploaded (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

Letusgo 2019 Summer - StringInterpolation and SwiftUI

  • 2. • 現 카카오뱅크 iOS 개발자 (16.10 ~ ) • 블로그 운영 : minsone.github.io 소개
  • 3. • StringInterpolation 소개 • StringInterpolation를 이용한 RichString 만들기 • SwiftUI를 이용한 RichString 만들기 • 번외 - FunctionBuilder를 이용한 RichString 만들 기 • QnA 목차
  • 5. String Interpolation 하나 이상의 placeholders("(variable)")를 포함하는 문자열 리 터럴을 실행하여 placeholders를 해당 값으로 대체한 결과를 산출 let txt1 = "Hello" let txt2 = "World" "(txt1), (txt2)" // Output: "Hello, World"
  • 6. 1: "" 2: (txt1) -> "Hello" 3: ", " 4: (txt2) -> "World" 5: "" 결과: "Hello, World" let txt1 = "Hello" let txt2 = "World" "(txt1), (txt2)" // Output: "Hello, World"
  • 7. DefaultStringInterpolation - Apple/Swift의 StringInterpolation.swift 공개 let txt1 = "Hello" let txt2 = "World" "(txt1), (txt2)" // Output: "Hello, World"
  • 8. Extend StringInterpolation 기존의 StringInterpolation에 확장. let amount = 10000 print("(amount, style: .원)") // Output: 10000원
  • 9. enum Style { case 원 } extension String.StringInterpolation { mutating func appendInterpolation (_ amount: Int, style: Style) { switch style { case .원: appendLiteral("(amount)원") } } } let amount = 10000 print("(amount, style: .원)") // Output: 10000원
  • 10. let amount = 10000 "(amount, currency: .원화)" "(amount, currency: .유로)" "(amount, currency: .달러)" "(amount, currency: .위안)" "(amount.toCurrency(.원화))" "(amount.toCurrency(.유로))" "(amount.toCurrency(.달러))" "(amount.toCurrency(.위안))"
  • 11. StringInterpolationProtocol StringInterpolation을 구현하기 위한 프로토콜. public protocol StringInterpolationProtocol { associatedtype StringLiteralType : _ExpressibleByBuiltinStringLiteral init(literalCapacity: Int, interpolationCount: Int) mutating func appendLiteral(_ literal: Self.StringLiteralType) }
  • 12. struct CustomInterpolation: StringInterpolationProtocol { var str: String 초기화 Parameters literalCapacity 문자열 길이 interpolationCount 문자열 placeholder 개수 init(literalCapacity: Int, interpolationCount: Int) { self.str = "" } mutating func appendLiteral(_ literal: String) { str += literal } mutating func appendInterpolation(_ amount: Int, style: Style) { switch style { case .원: appendLiteral("(amount)원") } } }
  • 13. literalCapacity 문자열 길이 interpolationCount 문자열 placeholder 개수 init(literalCapacity: Int, interpolationCount: Int) { self.str = "" } let txt1 = "Hello" let txt2 = "World" "(txt1), (txt2)" // Output: "Hello, World" literalCapacity = 2 interpolationCount = 2
  • 14. struct CustomInterpolation: StringInterpolationProtocol { var str: String 초기화 Parameters literalCapacity 문자열 길이 interpolationCount 문자열 placeholder 개수 init(literalCapacity: Int, interpolationCount: Int) { self.str = "" } mutating func appendLiteral(_ literal: String) { str += literal } mutating func appendInterpolation(_ amount: Int, style: Style) { switch style { case .원: appendLiteral("(amount)원") } } }
  • 15. public protocol ExpressibleByStringInterpolation : ExpressibleByStringLiteral { associatedtype StringInterpolation : StringInterpolationProtocol = DefaultStringInterpolation where Self.StringLiteralType == Self.StringInterpolation.StringLiteralType init(stringInterpolation: Self.StringInterpolation) }
  • 16. struct WonStyleString: ExpressibleByStringInterpolation { var str = "" init(stringLiteral: String) { self.str = stringLiteral } init(stringInterpolation: CustomInterpolation) { self.str = stringInterpolation.str } } /////////////////////////////////////////////////////// let styleStr: WonStyleString = "(10000, style: .원), (20000, style: .원)" styleStr.str // Output: "10000원, 20000원"
  • 18. NSAttributedString Library SwiftRichString, BonMot, Atributika 와 같은 라이브러리를 통 해 좀 더 손쉽게 NSAttributedString을 만들어줌. let style = Style { $0.font = UIFont.systemFont(ofSize: 25) $0.color = UIColor.blue $0.alignment = .center } let attributedText = "Hello World!".set(style: style)
  • 19. let style1 = Style { $0.font = UIFont.systemFont(ofSize: 25) $0.color = UIColor.blue $0.alignment = .center } let style2 = Style { $0.font = UIFont.systemFont(ofSize: 25) $0.color = UIColor.green $0.alignment = .center } let attr = NSMutableAttributedString(string: "") attr.append("Hello ".set(style: style1)) attr.append("World".set(style: style2))
  • 20. struct RichStringInterpolation: StringInterpolationProtocol { var attr: NSMutableAttributedString init(literalCapacity: Int, interpolationCount: Int) { self.attr = NSMutableAttributedString() } mutating func appendLiteral(_ literal: String) { attr.append(NSAttributedString(string: literal)) } func appendInterpolation(_ string: String, style: Style) { let attr: NSAttributedString = string.set(style: style) self.attr.append(attr) } }
  • 21. struct AttrString: ExpressibleByStringInterpolation { let attributedString: NSAttributedString init(stringLiteral: String) { let attr = NSAttributedString(string: stringLiteral) self.attributedString = attr } init(stringInterpolation: RichStringInterpolation) { self.attributedString = stringInterpolation.attr } } /////////////////////////////////////////////////////// let attr: AttrString = """ ("Hello", style: style1), ("World", style: style2)) """ let attrString: NSAttributedString = attr.attributedString
  • 22. let attr = NSMutableAttributedString(string: "") attr.append("Hello ".set(style: style1)) attr.append("World".set(style: style2)) let attr: AttrString = """ ("Hello", style: style1), ("World", style: style2)) """ let attrString: NSAttributedString = attr.attributedString
  • 24.
  • 26. FunctionBuilder(Beta) 빌더 패턴을 좀 더 보기 쉽게 해주는 Annotation struct ContentView : View { var body: some View { VStack { Text("Hello").bold().color(.blue) Text("World").bold().color(.red) } } }
  • 27. @_functionBuilder struct NSAttributedStringBuilder { static func buildBlock(_ components: NSAttributedString...) -> NSAttributedString { let attr = NSMutableAttributedString(string: "") for component in components { attr.append(component) } return attr } } extension NSAttributedString { convenience init(@NSAttributedStringBuilder _ builder: () -> NSAttributedString) { self.init(attributedString: builder()) }
  • 28. NSAttributedString { "Hello ".set(style: style1) "World".set(style: style2) } NSAttributedString { "Hello ".set(style: style1); "World".set(style: style2) }
  • 29. QnA
  • 30. • Apple : SE-0228 - Fix ExpressibleByStringInterpolation • MSDN - Interpolation • Wikipedia - String interpolation • HackingWithSwift - What’s new in Swift 5.0 Reference

Editor's Notes

  1. \ -> back slack
  2. \ -> back slack
  3. \ -> back slack
  4. \ -> back slack