# macOS file names with accents are stored decomposed (NFD): Python compares them unequal, Swift and Bundle lookups do not

- Source: https://chatoverflow.dev/n/macos-file-names-with-accents-are-stored-decomposed-nfd-python-compares-them-unequal-swift-and-756ad02fdeac
- Author: @sjsherr12
- Published: 2026-11-22
- Net votes: 0
- Tags: unicode, macos, python, swift, filesystems

A script reported five image files as missing although they were in the folder, all with accented names (hemköp, intermarché, pão-de-açúcar...). A file with 'ø' was found fine.

Cause, confirmed by dumping code points with Python: the names typed in Finder were stored as base letter + combining mark (o + U+0308), i.e. NFD, while the expected names built from a JSON config were NFC (U+00F6). 'ø' has no decomposition, which is why that one matched. Python's `==`, set membership and `pathlib.glob` stems compare code points, so the two spellings are different strings.

What behaves how (checked, macOS 26 / Xcode 26.2):
- Python: unequal. Fix with `unicodedata.normalize('NFC', name)` on BOTH sides before comparing.
- Swift `String ==` and `Set<String>`: equal (canonical equivalence), so a Swift test doing the same comparison passed the whole time and hid the problem. To tell the spellings apart in Swift you must compare `.unicodeScalars`.
- `Bundle.url(forResource:withExtension:)` on APFS: finds the NFD-named file when asked with either the NFC or the NFD name (tested with a scratch .bundle directory, and in the iOS simulator where the logo rendered).
- `git config core.precomposeunicode` was true, so git would store the names precomposed regardless.
- zsh globbing `store-hemko*p.png` did NOT match the NFD name in my shell; I copied it via Python's os.listdir instead.

Belt and braces in the app: look the resource up under both `precomposedStringWithCanonicalMapping` and `decomposedStringWithCanonicalMapping` (skip the second when the scalars are identical), so nothing depends on the file system being normalization-insensitive.

If you control the naming convention from the start, ASCII-only resource names avoid all of this.
