Slide 1

Slide 1 text

Hi! • giginet (Twitter/GitHub) • LINE Corp Senior Engineer • Developer Experience Team • Tech Adviser for Money Forward • Core Contributor • fastlane/Carthage/XcodeGen and so on • 👾

Slide 2

Slide 2 text

Thank you for this great venue!!!

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

What’s the most impressive topic?

Slide 5

Slide 5 text

Mergeable Library

Slide 6

Slide 6 text

Deep dive into Mergeable Library @giginet Tokyo iOS Meetup 2023/6/26

Slide 7

Slide 7 text

In this talk • Look back on linking type • Learn about Mergeable Library • Meet Mergeable Library • https://developer.apple.com/videos/play/wwdc2023/10268/ • Con f iguring your project to use mergeable libraries • https://developer.apple.com/documentation/Xcode/con f iguring-your-project-to-use- mergeable-libraries • Look further at the behavior

Slide 8

Slide 8 text

Dynamic linking • Application links frameworks dynamically • Link on app launch time • 🟢Pros • Reducing build duration • Work f ine with Xcode Preview • ❌Cons • Overhead of launch time • Increasing app size Application Dynamic Library Link on launch time

Slide 9

Slide 9 text

Static linking • Embed symbols into an application binary • Link on build time • 🟢Pros • No overhead on launch time • Easy to reduce app size • ❌Cons • Build duration is longer • Some IDE features don’t work(Xcode Preview) Application Static Library

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

In the past • The dilemma between Dynamic Linking VS Static Linking • For developers, Dynamic Linking is better • Faster build duration • IDE features work f ine • For end-users, Static Linking is better • Smaller app binary size • Faster launch time

Slide 12

Slide 12 text

Mergeable Library • New build system feature with Xcode 15 • Merge dependencies into one library • Reducing linking overhead • Switch framework types by a build con f iguration automatically • Debug: Dynamic Linking • Release: Static Linking

Slide 13

Slide 13 text

Merged

Slide 14

Slide 14 text

Debug Release Merged Library Merged Library

Slide 15

Slide 15 text

Sample Project • Tried on Xcode 15 beta 2 • Application with three libraries MyApp MyUI MyModel MyUtils

Slide 16

Slide 16 text

Enabling Mergeable Library • Just set “Create Merged Binary” of the application target(MyApp) • Linking > Mergeable Libraries > Create Merged Binary > Automatic

Slide 17

Slide 17 text

Debug Con f iguration • All merged frameworks are re- exported into the app bundle • MyApp.app/ReexportedBinaries/ *.framework • All frameworks are dynamically linked on development

Slide 18

Slide 18 text

Release Con f iguration • All frameworks are embedded into app binary • Binary size is increased than dynamically one

Slide 19

Slide 19 text

import Foundation public protocol Animal { func bark() } public struct Cat: Animal { public init() { } public func bark() { print("meow") } } • Example : A struct in MyModel framework How to embed symbols

Slide 20

Slide 20 text

• Dump all symbols in app binary • Using nm command Dump app binaries nm --format=just-symbols --size-sort Release-iphonesimulator/MyApp.app/MyApp

Slide 21

Slide 21 text

Debug(140KB) Release(244KB)

Slide 22

Slide 22 text

Resource bundle support • Runtime lookup with Mergeable Libraries works f ine • It’s mentioned in the WWDC session • However, Resource bundle with Static Frameworks cause unexpected behavior

Slide 23

Slide 23 text

import Foundation import SwiftUI private let bundle = Bundle(for: ResourceFinder.self) private class ResourceFinder {} public struct MyImage: View { public init() { } public var body: some View { Image("giginet", bundle: bundle) Text(bundle.description) .font(.caption) } } Resources in MyUI framework

Slide 24

Slide 24 text

Debug Con f iguration Loading resources from MyUI’s bundle ✅

Slide 25

Slide 25 text

Release Con f iguration Loading resources from main bundle 💥

Slide 26

Slide 26 text

• Dynamic lookup works f ine with Mergeable Library • But Static Frameworks can’t get their bundles • It causes implicit unexpected behavior • Need to consider best practice using Mergeable Library for frameworks with resources🤔 Resource bundle with Mergeable Library

Slide 27

Slide 27 text

• Mergeable Library is the best feature available on Xcode 15 • It works f ine in most cases. Let’s enable it now!!! • Some runtime features may expect unexpected behavior • runtime behaviors would be changed by build con f igurations Recap

Slide 28

Slide 28 text

• Meet Mergeable Library • https://developer.apple.com/videos/play/wwdc2023/10268/ • Con f iguring your project to use mergeable libraries • https://developer.apple.com/documentation/Xcode/con f iguring-your-project-to-use- mergeable-libraries Resources

Slide 29

Slide 29 text

Thank you for your attention