Skip to Content
Course content

155: App Thinning and Bitcode

Click on the "Edit" button in the top corner of the screen to edit your slide content.

You've probably seen the "App Thinning" section in your project settings and assumed it's just a fancy way of saying "compression." I see this all the time: developers think that when they upload a "Universal Binary" to App Store Connect, Apple just zips it up and the iPhone unzips it upon installation. They assume the user's device is downloading everything—every single image resolution, every architecture slice—and just ignoring the parts it doesn't need.

The "One-Size-Fits-All" Binary Myth

If that were true, your app's download size would be catastrophic. Imagine you have a professional photo editing app with 4K textures for the iPad Pro and low-res versions for the iPhone SE. If the iPhone SE had to download the 4K assets just to ignore them, you'd be wasting hundreds of megabytes of the user's data and storage. That's not how it works. The binary you upload to Apple is the "Fat Binary," but that's not what the user ever actually downloads.

Slicing: Serving Only What's Necessary

The magic is actually called Slicing. When a user hits "Get" on the App Store, the store looks at the specific device requesting the app. It then creates a "sliced" version of your app on the fly. If the user is on an iPhone 15, Apple strips out the iPad-specific assets, the 1x resolution images (from the ancient days), and any code architectures that the A17 chip doesn't use.

This happens entirely on Apple's servers. You don't have to write a single line of code to make this happen; you just provide all the assets (1x, 2x, 3x) and the various architectures, and Apple handles the surgical removal of the waste.

On-Demand Resources: Beyond the Initial Download

Slicing handles the hardware differences, but what about content that the user might not even need for weeks? This is where On-Demand Resources (ODR) come in. I once worked on a game where the initial download was 2GB because of the high-res textures for later levels. Users were dropping off during the download process because it took too long.

By implementing ODR, we tagged the assets for Levels 10 through 50 as "On-Demand." The user only downloaded the assets for the first few levels. As they progressed, the app would request the next set of assets from the App Store in the background. Here is the general flow of how you'd handle that in your code:

import GameKit

// Requesting a specific tag of resources
let request = NSBundleResourceRequest(tags: ["Level10Assets"])

request?.beginAccessingResources { error in
    if let error = error {
        print("Error loading assets: \(error)")
        return
    }
    // Now you can safely access the files in the bundle
    print("Level 10 assets are ready to use!")
}

The Bitcode Transition

You might see mentions of Bitcode in older tutorials. For years, Bitcode allowed Apple to re-compile your app's binary on their servers to optimize it for new chips without you having to submit a new build. It was a great safety net.

However, here is a bit of a "pro tip" update: Apple has largely deprecated Bitcode starting with Xcode 14. For the vast majority of modern iOS, iPadOS, and watchOS apps, you no longer need to worry about enabling or disabling it. The industry has moved toward a more streamlined build process where the optimizations happen before the upload or through different mechanisms. If you're working on a legacy project and see a "Bitcode" error, you're likely looking at a build setting that is no longer relevant for current App Store submissions.




📋 Practical Task

Configuring an On-Demand Asset Tag for a Level-Based App

In this exercise, you will simulate the setup of On-Demand Resources for a hypothetical game called "SwiftQuest." You aren't writing the full game, but you are implementing the resource management logic.

  • Create a new Swift project.
  • Create a folder in your project named Level2Assets and add a few large dummy files (like high-res images or sound files) to it.
  • In the Target settings, go to the Build Phases tab.
  • Find the Copy Bundle Resources section.
  • Select your Level2Assets folder and, in the Resource Tags field in the File Inspector (right-hand sidebar), assign the tag "Level2".
  • Set the On-Demand Resource Tag property to "Initial Install: No" (this ensures it isn't downloaded with the app).
  • Write a function loadLevelTwo() that uses NSBundleResourceRequest to fetch the "Level2" tag and prints a success message to the console once the assets are available.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.