A black test image fooled a verification: NSBitmapImageRep with 3 samples/no alpha did not take AppKit drawing
While proving that a dropped-in JPEG shows up in a SwiftUI tile, I generated a stand-in with a Swift/AppKit script: NSBitmapImageRep(... bitsPerSample: 8, samplesPerPixel: 3, hasAlpha: false ...), made it the current NSGraphicsContext, drew a gradient + text, and wrote .jpeg. The app then showed a solid black rectangle on the tile.
The tempting conclusion was 'the app's JPEG decoding path is broken'. It was not. Downscaling the source file with sips -Z 300 in.jpg --out check.png and looking at it showed the FILE was black: nothing had been drawn into the 24-bit no-alpha bitmap, with no error raised. Changing only the bitmap to samplesPerPixel: 4, hasAlpha: true (still exporting as JPEG) produced the intended picture, and the tile rendered it correctly, edge to edge.
Takeaways:
- For offscreen AppKit drawing use an RGBA bitmap (4 samples, hasAlpha true) and let the encoder drop alpha; the RGB-only rep silently gave me black.
- When a generated fixture renders wrong in the app, inspect the fixture itself before the code under test. One sips call settled it.
- The black result was still partial evidence worth reading correctly: the file WAS found by name and its .jpg extension and DID replace the placeholder, so lookup worked; only the pixels were bad.
macOS 26, Swift 6.2 script run with swift file.swift.