Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swift 5.9 と C++ の互換性
Search
h.crane
March 06, 2024
Technology
1
500
Swift 5.9 と C++ の互換性
Event
集まれSwift好き!Swift愛好会 vol.80
Details
Qiita:
https://qiita.com/hcrane/items/081dd77bd593f1ea74af
h.crane
March 06, 2024
Tweet
Share
More Decks by h.crane
See All by h.crane
Getting started with controlling LEGO using Swift
hcrane
1
860
Live on iOSDC2023
hcrane
4
1.2k
自販機で1000円を使い切りたいんじゃ!
hcrane
0
100
Vision.framework - 商品画像からのテキスト検出と並列化実装への試み
hcrane
1
620
DevRel/Japan 2023 - 1つの事業部だけで行う DevRel とは
hcrane
0
890
R2-D2をiOSで動かす
hcrane
2
2.1k
iOSDC2022 - SwiftUI in UIKit で開発する世界
hcrane
6
6.4k
iOSDC2022 - iPadOSDC Japan 2022
hcrane
2
3.6k
iOSDC2021 - Compositional Layoutsで実現する疎結合な実装
hcrane
3
5k
Other Decks in Technology
See All in Technology
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
40k
アプリをリリースできる状態に保ったまま 段階的にリファクタリングするための 戦略と戦術 / Strategies and tactics for incremental refactoring
yanzm
6
1k
2024年のナビゲーション・フォーカス対応:Composeでキーボード・ナビゲーションをサポートしよう
tahia910
0
110
Oracle Exadata Database Service(Dedicated Infrastructure):サービス概要のご紹介
oracle4engineer
PRO
0
9.5k
Fediverse Discovery Providers overview
andypiper
0
160
可視化により内部品質をあげるAIドキュメントリバース/20240910 Hiromitsu Akiba
shift_evolve
0
200
Swift Testingのconfirmationを コードリーディング/Dive into Swift Testing confirmation
laprasdrum
1
240
チームビルディングは"感性"で向き合おう / Team Building with Awareness
kohzas
0
170
Analytics-Backed App Widget Development - Served with Jetpack Glance
miyabigouji
0
390
AI でアップデートする既存テクノロジーと、クラウドエンジニアの生きる道
soracom
PRO
2
530
SAVEPOINT α版
savepoint
0
660
四国クラウドお遍路 2024 in 高知 オープニング
yukataoka
0
200
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
401
65k
Infographics Made Easy
chrislema
239
18k
Web Components: a chance to create the future
zenorocha
308
42k
Scaling GitHub
holman
458
140k
The Mythical Team-Month
searls
218
43k
Why Our Code Smells
bkeepers
PRO
334
56k
Speed Design
sergeychernyshev
22
430
What’s in a name? Adding method to the madness
productmarketing
PRO
21
3k
The Pragmatic Product Professional
lauravandoore
31
6.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
227
52k
A Philosophy of Restraint
colly
202
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
25
3.9k
Transcript
March 7, 2024, ू·ΕSwift͖ʂSwiftѪձ vol.80 Hiromu Tsuruta @ Rakuten Group,
Inc. Swift 5.9 ͱ C++ ͷޓੑ
<Company> ・Rakuten Group, Inc <Application> ・Rakuma
<Role> ・iOS Developer ・Developer Relations <Account> ・Twitter:@hcrane14 Tech Lead
ࠓ·Ͱͷ Swift ͱ C++ ͷޓੑ
ᶃ Objective-C++ ͰϒϦοδ͢Δ ᶄ C ͰϒϦοδ͢ΔʢC++ ͷػೳ extern "C" Λ͏ʣ
ᶅ SPM ͔Β module.modulemap Ͱެ։͢Δ
ํ๏ ᶃ Objective-C++ ͰϒϦοδ͢Δ
Swift Objective-C++ C++
Live on iOSDC2023 Ҿ༻ɿhttps://photos.google.com/share/AF1QipNFYcoT0g9XcxuTm8rsNZp7i4JrBKj10iTzj4abxZfTfwTIEzHPF0OSow6P4ClskA?pli=1&key=VmVfLTU1aWExX1BRX21KMDJhajZqRktmZngzWmt3
iOSDCͷొஃ༰ ͜ͷํ๏Ͱͨ͠
Ҿ༻ɿhttps://speakerdeck.com/hcrane/live-on-iosdc2023?slide=47
Ҿ༻ɿhttps://speakerdeck.com/hcrane/live-on-iosdc2023?slide=48
؆୯ͳ࣮αϯϓϧ
C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ จࣈྻΛग़ྗ͢Δ͚ͩͷ؆୯ͳϝιουΛ࣋ͬͨΫϥε
Objective-C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ C++ͷίʔυΛݺͼग़͢ ϥούʔΫϥε
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ Objective-C++ ͷϔομʔΛՃ͢Δ
Swift ͷ࣮ߦϑΝΠϧ Swift ͔Β Objective-C++ Λݺͼग़ͤΔʂ → ݁Ռͱͯ͠ C++ Λݺͼग़ͤΔ
ํ๏ ᶄ C ͰϒϦοδ͢Δ ʢC++ ͷػೳ extern "C" Λ͏ʣ
Swift C C++
؆୯ͳ࣮αϯϓϧ
Step.1 Swift ͔Β C Λݺͼग़͢؆୯ͳྫ
Swift C ͱޓੑ͕͋Δ
C ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ จࣈྻΛग़ྗ͢Δ͚ͩͷ؆୯ͳϝιου
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ C ͷϔομʔΛՃ͢Δ
Swift ͔Β C Λݺͼग़ͤΔʂ ʢޓੑ͕͋ΔͷͰϔομʔΛՃ͢Δ͚ͩͰ؆୯ʂʣ Swift ͷ࣮ߦϑΝΠϧ
Step. 2 Swift ͔Β C ܦ༝Ͱ C++ Λݺͼग़͢؆୯ͳྫ
C++ ͷػೳ extern "C" Λ͏
extern "C" ʹؔͯ͠ • C++ ͷݴޠػೳ • C++ Λ Cݴޠͱͯ͠ѻ͏Α͏͢Δ
• C++ ͱ CݴޠͷίϯύΠϥͰޓੑ͕ͳ͍࣌ʹ extern "C" Ͱճආ͢Δ → Swift Ͱ͑ C++ Λݺͼग़͢ͷʹ͑Δ
C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ extern "C" ͰғͬͨจࣈྻΛग़ྗ ͢Δ͚ͩͷ؆୯ͳϝιου
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ C++ ͷϔομʔΛՃ͢Δ ʢ#include ͳ͜ͱʹҙʣ
Swift ͔Β C ܦ༝Ͱ C++ Λݺͼग़ͤΔʂ Swift ͷ࣮ߦϑΝΠϧ
͜ͷํ๏ͷ੍ • C++ͷؔΛCݴޠͱͯ͠એݴ͢Δ߹ɺܕCݴޠ͕αϙʔτ͢Δܕ Ͱͳ͚ΕͳΒͳ͍ɻ(C++ ͷಛఆͷܕɾࢀরɾΫϥε NGʣ • C++ͷ໊લम০͕ແޮԽ͞ΕΔɻʢΦʔόʔϩʔυ͞Εͨؔ NGʣ etc.
ํ๏ ᶅ SPM ͔Β module.modulemap Ͱެ։͢Δ
Swift Swift Package Manager C++ module.modulemap
module.modulemap ʹؔͯ͠ • Bridging Header ͷ্Ґޓ • Objective-C / C
ͷγϯϘϧʢؔɺมɺܕɺఆʣʹΞΫηεͰ͖Δ etc.
Swift ͔Β SPM ܦ༝Ͱ؆୯ʹ C++ Λݺͼग़ͤΔʂ module.modulemap ϑΝΠϧ
ઌʹհͨ͠ํ๏ ᶃ, ᶄ Ͱ SPM ͔Β͏͜ͱ͕Ͱ͖Δ
͜Ε͔Βͷ Swift ͱ C++ ͷޓੑ
C++ interoperability
؆୯ͳ࣮αϯϓϧ
C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ จࣈྻΛग़ྗ͢Δ͚ͩͷ؆୯ͳϝιουΛ࣋ͬͨΫϥε
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ C++ ͷϔομʔΛՃ͢Δ ʢ#include ͳ͜ͱʹҙʣ
interoperability ͷઃఆΛ C/Objective-C → C++/Objective-C++ ϓϩδΣΫτͷઃఆ
Swift ͔Β C++ Λݺͼग़ͤΔʂ Swift ͷ࣮ߦϑΝΠϧ
Objective-C / C ͱಉ͡ཁྖͰ C++ Λݺͼग़ͤΔʂ
ҙ ઃఆ͕มΘΔͷͰ C ݴޠϏϧυͰ͖ͳ͘ͳΔ ʢͨͩ͠ɺObjective-C ϏϧυͰ͖Δʣ → C ͱ C++
ͷίʔυΛࠞࡏͰ͖ͳ͘ͳΔ
Swift ͱ C++ Λߟͨ͠هࣄ Ҿ༻ɿhttps://kateinoigakukun.hatenablog.com/entry/2020/12/01/083949