SlideShare a Scribd company logo
한국카카오은행안정민
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 ES6
FITC
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
Jung Kim
 
Javascript the New Parts v2
Javascript the New Parts v2Javascript the New Parts v2
Javascript the New Parts v2
Federico Galassi
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Jung Kim
 
ES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript SkillsES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript Skills
Stefano Ceschi Berrini
 
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 2
Andrey Karpov
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
Sebastiano 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 Kotlin
vriddhigupta
 
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 2016
Manoj Kumar
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
Yusuke Kita
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
Giordano Scalzo
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
New Generation Applications
 
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
 
Go memory
Go memoryGo memory
Go memory
jgrahamc
 

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 AST
Jarrod 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 Trees
Jamund Ferguson
 
Taking User Input in Java
Taking User Input in JavaTaking User Input in Java
Taking User Input in Java
Eftakhairul Islam
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
meysholdt
 
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 Application
Joni
 
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 Apps
Mark
 
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 2015
Charles Nutter
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
Lars Marius Garshol
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
kaushik_sathupadi
 
#살아있다 #자프링외길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 Testing
C4Media
 
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
GaryCoady
 
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
Sages
 

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 정민 안

20240516_동적_데이터을_대응하는_코드_작성하기.pdf
20240516_동적_데이터을_대응하는_코드_작성하기.pdf20240516_동적_데이터을_대응하는_코드_작성하기.pdf
20240516_동적_데이터을_대응하는_코드_작성하기.pdf
정민 안
 
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
정민 안
 
형상관리 발표자료 안정민
형상관리 발표자료 안정민형상관리 발표자료 안정민
형상관리 발표자료 안정민
정민 안
 

More from 정민 안 (14)

20240516_동적_데이터을_대응하는_코드_작성하기.pdf
20240516_동적_데이터을_대응하는_코드_작성하기.pdf20240516_동적_데이터을_대응하는_코드_작성하기.pdf
20240516_동적_데이터을_대응하는_코드_작성하기.pdf
 
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

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
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
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
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
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
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
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
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
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
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
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
 

Recently uploaded (20)

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
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
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...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
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
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
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
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
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
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
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
 

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