Asset Catalog

RSS for tag

An asset catalog is a type of file used to organize and manage different assets and image resolutions used by your app’s user interface.

Posts under Asset Catalog tag

40 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Images retain memory usage
This is a very simple code in which there is only one button to start with. After you click the button, a list of images appear. The issue I have is that when I click on the new button to hide the images, the memory stays the same as when all the images appeared for the first time. As you can see from the images below, when I start the app, it starts with 18.5 mb, when I show the images it jumps to 38.5 mb and remains like that forever. I have tried various way to try and reduce the memory usage but I just can't find a solution that works. Does anyone know how to solve this? Thank you! import SwiftUI struct ContentView: View { @State private var imagesBeingShown = false @State var listOfImages = ["ImageOne", "ImageTwo", "ImageThree", "ImageFour", "ImageFive", "ImageSix", "ImageSeven", "ImageEight", "ImageNine", "ImageTen", "ImageEleven", "ImageTwelve", "ImageThirteen", "ImageFourteen", "ImageFifteen", "ImageSixteen", "ImageSeventeen", "ImageEighteen"] var body: some View { if !imagesBeingShown { VStack{ Button(action: { imagesBeingShown = true }, label: { Text("Turn True") }) } .padding() } else { VStack { Button(action: { imagesBeingShown = false }, label: { Text("Turn false") }) ScrollView { LazyVStack { ForEach(0..<listOfImages.count, id: \.self) { many in Image(listOfImages[many]) } } } } } } }
1
0
130
1w
XCode asset catalog causes NSImage to be unclickable
I'm having an issue where when my asset catalog have more than 2 images (all have @1x @2x and @3x and PNG format), my NSImage in my NSImageView cannot be clicked. Does anyone know why this happens? Thanks in advance! import SwiftUI struct ContentView: View { @State private var window: NSWindow? var body: some View { VStack { Button("Open Window") { // Create and show the NSWindow self.window = NSWindow( contentRect: NSScreen.main?.frame ?? NSRect.zero, styleMask: [.borderless], backing: .buffered, defer: false ) // Set up window properties self.window?.isOpaque = false self.window?.hasShadow = false self.window?.backgroundColor = .clear self.window?.level = .screenSaver self.window?.collectionBehavior = [.canJoinAllSpaces] self.window?.makeKeyAndOrderFront(nil) // Create an NSImageView let petView = PetView() // Add the NSImageView to the window's content view if let contentView = self.window?.contentView { contentView.addSubview(petView) // Center the petView petView.centerXAnchor.constraint(equalTo: contentView.centerXAnchor).isActive = true petView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true } } } } } class PetView: NSImageView { override init(frame frameRect: NSRect = .zero) { super.init(frame: frameRect) self.image = NSImage(named: "dog_idle-1") self.translatesAutoresizingMaskIntoConstraints = false } required init?(coder: NSCoder) { super.init(coder: coder) } override func mouseDown(with event: NSEvent) { print("woof!") } } I've tried changing the amount of images in my asset catalog and found that 2 is the maximum amount for my NSImage to be clickable. It suppose to print "woof!" when i click on it.
0
0
133
2w
XCode 15.3 Command CompileAssetCatalog failed with a nonzero exit code
I just upgraded to XCode15.3 and now all my projects with Assets are getting this compile error. I have tried removing DerivedData caches and rebooting but still get this error. Anyone else hit this problem with XCode 15.3? I was only Building for IOS 16.4 and 17.0.1 and Xcode 14.0 and 15.0 Build Error: Command CompileAssetCatalog failed with a nonzero exit code *** Terminating app due to uncaught exception 'IBPlatformToolFailureException', reason: 'The tool closed the connection (AssetCatalogSimulatorAgent) Execution Context: <IBSimulatorToolCoreSimulatorCLIExecutionContext: 0x600003d5d260 busyCount=0, Idle for 0.0 secs, lifeTime=26.3 secs>, device=IBSimDeviceTypeiPad3x (865E7291-E467-4E8D-B535-D64F43A57F15, iOS 17.4, Shutdown), idiom=<IBIPhoneIdiom: 0x6000028b8000>
15
5
4k
2w
Xcode assets name conventions.
Hi community: I'm trying to replace it with drag-and-drop images in assets. I know for example that by adding a suffix @2 and @3, you can drag and drop and Xcode knows where they must be. Also, I remember that it could be possible to add a suffix like ~dark or ~light. There's no official documentation about it but I'm looking a way to drag and drop and autodetect assets per language. I've tried: image_es@fr.png image_fr@2x.png image_fr@3x.png But doesn't work. Any ideas where I can find the docs? Or can someone provide documentation about it? Thanks in advance.
0
0
131
2w
Incorrect image alpha rendering on Xcode 15b3 and iOS 17
I'm not sure if I'm changed an unknown-to-me setting somewhere, but since this morning, after profiling an app (metal, allocations, etc), every project I run/build on Xcode 15b3, either on simulator or on device, displays partially-alpha images blended to black, as if there was some problem in the process of compiling the PNGs (lack of premultiplying, color space, etc). If I open those same projects on Xcode 14, they are displayed everything as they should. Also, If I open them on other computers with Xcode 15b3 other than mine, it also works fine. And it was working fine for me this morning as well, but not anymore. I've tried uninstalling Xcode beta and the simulator a few times, cleaning folders and preferences, hoping it was some setting I changed by mistake with some hotkey, but no luck so far. I'll attach two pictures, one from Xcode 14, and the other one from Xcode 15b3, hoping it's some silly thing I'm missing. xc15b3: xc14:
20
5
3.7k
Mar ’24
Error loading ReferenceImage
Currently, I try to test the ImageTrackingProvider with the Apple Vision Pro. I started with some basic code: import RealityKit import ARKit @MainActor class ARKitViewModel: ObservableObject{ private let session = ARKitSession() private let imageTracking = ImageTrackingProvider(referenceImages: ReferenceImage.loadReferenceImages(inGroupNamed: "AR")) func runSession() async { do{ try await session.run([imageTracking]) } catch{ print(error) } } func processUpdates() async { for await _ in imageTracking.anchorUpdates{ print("test") } } } I only have one picture in the AR folder. I added the size an I have no error messages in the AR folder. As I am trying to run the application with the vision Pro, I receive following error: ar_image_tracking_provider_t <0x28398f1e0>: Failed to load reference image <ARReferenceImage: 0x28368f120 name="IMG_1640" physicalSize=(1.350, 2.149)> with error: Failed to add reference image. It finds the image, but there seems to be a problem with the loading. I tried the jpeg and the png format. I do not understand why it fails to load the ReferenceImage. I use Xcode Version 15.3 beta 3
2
0
580
Feb ’24
how to read a file under project directory for both development and runtime?
For example I created a project aaa. aaa source folder is called aaa. that is aaa aaa/aaa then I put a data file in aaa/aaa/some.data now i want to test data in aaa/aaaTests/aaaTests.swift How can i access aaa/aaa/some.data in aaaTests.swift? If I want to access some.data inside aaa/aaa/ContentView.swift, how to write the code? I have been searching google and bing for days, but find no example answering my questions. Can anyone help me out? Thanks in advance.
1
0
423
Feb ’24
tvOS icon missing layers
I have an AppleTV app which I released in 2016. I've updated it and released a new version every year without much hassle. This year, with tvOS 17.2, the layered app icon isn't working right. This is a two-layer image made with PNGs. When it's selected, it looks right and the layers move correctly: But when it's not selected, the background layer disappears: Screenshots are from the simulator but it also happens on the device. It's inconsistent; sometimes it's the front layer that disappears. Occasionally both layers work, but I can't tell why. I've spent a day trying everything. Very frustrated. The icon previews correctly in Xcode and in Parallax Viewer. The image sizes are correct: 400 x 240 for Small, 800 x 480 for Small@2x, 1280 x 768 for Large. The back layer is a non-transparent PNG. I tried adding a Large@2x set. Didn't help. Originally I had a three-layer image with no middle layer PNG. I deleted the empty middle layer, but that didn't help. All the PNG files are from GnuIMP. Same color space, even. I was using the filenames tvicon-back-s.png and tvicon-back-s@2x.png. I tried taking out the @ sign in case that was confusing Xcode. (It never has before, but I am flailing here.) Anybody have any clues? If it's an Apple bug and there's nothing I can do, I'm going to just push the release button and hope it fixes itself someday.
3
0
668
Jan ’24
About .svg file, If 'x' inside 'text' represents multiple values, it will result in a rendering error.
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill-rule="evenodd" height="48" preserveAspectRatio="none" stroke-linecap="round" viewBox="0 0 2240 480" width="224"> <style type="text/css"> .brush0 { fill: rgb(255,255,255); } .pen0 { stroke: rgb(0,0,0); stroke-width: 1; stroke-linejoin: round; } .font0 { font-size: 303px; font-family: "Times New Roman", serif; } .font1 { font-style: italic; font-size: 303px; font-family: "Times New Roman", serif; } .font2 { font-size: 274px; font-family: Symbol, serif; } .font3 { font-weight: bold; font-size: 16px; font-family: System, sans-serif; } </style> <g> <text class="font0" fill="rgb(0,0,0)" stroke="none" style="dominant-baseline: alphabetic;" x="154 264 836 1473 1925" xml:lang="en" xml:space="preserve" y="320">(3)13</text> <text class="font1" fill="rgb(0,0,0)" stroke="none" style="dominant-baseline: alphabetic;" x="49 731 2077" xml:lang="en" xml:space="preserve" y="320">iii</text> <text class="font2" fill="rgb(0,0,0)" stroke="none" style="dominant-baseline: alphabetic;" x="484 1026 1290 1678" xml:space="preserve" y="320">+=-+</text> </g> </svg> Review the specific issue
0
0
380
Jan ’24
Alternate app icons and AppStore test treatments
We want to provide an alternate app icon in our bundle specifically for testing with an App Store test treatment (A/B test). What I'm unclear about is whether we then need to enable users to choose from the available app icons, since there are now multiple. I have seen reports of apps being rejected because they didn't offer this feature when multiple alternate icon sets were bundled. We do NOT want to allow users to select an app icon. Also, is it permissible to have a different icon for the App Store than what is used for the device app-launcher? I believe the guidance here is that all sizes of the icon should have the same content (just resized), but our marketing people want to test a different icon for the app-store specifically. Is there guidance on this somewhere that I haven't found?
0
0
532
Jan ’24
App crashed on reading image in bundle when there is only a color with the same name.
Related APIs: +[UIImage imageNamed:] +[UIImage imageNamed:inBundle:compatibleWithTraitCollection:] When there is only a color set with the name (no image set provided), reading the image with the above-mentioned APIs throws an exception: 2023-12-19 19:30:34.008701+0800 ***[57410:578064] *** Assertion failure in -[_UIImageCGImageContent initWithCGImageSource:CGImage:scale:], _UIImageContent.m:666 2023-12-19 19:30:34.031207+0800 ***[57410:578064] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Need an imageRef' Even when wrapped in a try/catch block, it still crashes due to a lock issue after calling the related API twice. Here is an example code snippet: UIImage *image; for (NSInteger i=0; i<10; i++) { @try { image = [UIImage imageNamed:@"sample"]; //image = [UIImage imageNamed:@"sample" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; } @catch (NSException *exception) { } } The crash backtrace is as follows: #0 0x0000000102b12214 in _os_unfair_lock_recursive_abort () #1 0x0000000102b0da50 in _os_unfair_lock_lock_slow () #2 0x000000010ab07624 in -[UIImageAsset imageWithConfiguration:] () #3 0x000000010b2f4634 in -[_UIAssetManager imageNamed:configuration:] () #4 0x000000010aaf2394 in +[UIImage imageNamed:inBundle:withConfiguration:] () #5 0x000000010aaf2200 in +[UIImage imageNamed:inBundle:compatibleWithTraitCollection:] () #6 0x0000000105442154 in +[UIImageAccessibility imageNamed:inBundle:compatibleWithTraitCollection:] () It seems that the color set is being treated as an imageRef in this image reading process. It's a bug of UIKit?
1
0
580
Dec ’23
GenerateAssetSymbols wrongly renaming image assets
Xcode generates symbols for image and color assets now (which is super nice!). We noticed an issue when generating code symbols for our image assets. We have an image named inputContour and one named inputContourColor. Xcode was not able to generate a symbol for inputContourColor and instead produced the following warning: #warning("The \"inputContourColor\" image asset name resolves to the symbol \"inputContour\" which already exists. Try renaming the asset.") It turns out that the generator automatically removes the color suffix when creating the code symbol. For color assets, this probably make sense (so tealColor would become just teal), but this should not be applied to image resources.
10
1
3.3k
Dec ’23
Avator Creator, null image issue
"I am developing a project called 'Avatar Creator.' In the HeadSelectionView, BodySelectionView, and LegSelectionView screens, the user will choose one of the images available there. In the final FinalSelectionView screen, I want to display the images the user selected, but I'm facing a problem. In the FinalSelectionView screen, only the last selected 'Leg' image is visible; the 'Head' and 'Body' images return 'nil' (null). I'm leaving the code I wrote below. Can you help?" import SwiftUI enum ImageHead: String, CaseIterable, Identifiable { case smile = "head-0" case smileWithEyebrow = "head-1" case happy = "head-2" case sad = "head-3" case verySad = "head-4" case shocked = "head-5" var id: ImageHead { self } } enum ImageBody: String, CaseIterable, Identifiable { case black = "body-0" case brown = "body-1" case red = "body-2" var id: ImageBody { self } } enum ImageLeg: String, CaseIterable, Identifiable { case blue = "leg-0" case grey = "leg-1" case black = "leg-2" var id: ImageLeg { self } } struct SelectionImageView: View { var image: String var body: some View { Image(image) .resizable() .aspectRatio(contentMode: .fit) .frame(width: 150, height: 150) } } struct ContentView: View { @State private var userSelectedHead: ImageHead? @State private var userSelectedBody: ImageBody? @State private var userSelectedLeg: ImageLeg? var body: some View { NavigationView { ScrollView(.horizontal) { LazyHGrid(rows: [GridItem(.flexible())]) { ForEach(ImageHead.allCases, id: \.self) { head in NavigationLink(destination: BodySelectionView(userSelectedHead: $userSelectedHead, userSelectedBody: $userSelectedBody, userSelectedLeg: $userSelectedLeg)) { VStack { SelectionImageView(image: head.rawValue) Text("Selected Head: \(userSelectedHead?.rawValue ?? "None")") } } .padding() } } } .navigationTitle("Select Head") } } } struct BodySelectionView: View { @Binding var userSelectedHead: ImageHead? @Binding var userSelectedBody: ImageBody? @Binding var userSelectedLeg: ImageLeg? var body: some View { ScrollView(.horizontal) { LazyHGrid(rows: [GridItem(.flexible())]) { ForEach(ImageBody.allCases, id: \.self) { body in NavigationLink(destination: LegSelectionView(userSelectedHead: $userSelectedHead, userSelectedBody: $userSelectedBody, userSelectedLeg: $userSelectedLeg)) { VStack { SelectionImageView(image: body.rawValue) Text("Selected Head: \(userSelectedHead?.rawValue ?? "None")") Text("Selected Body: \(userSelectedBody?.rawValue ?? "None")") } } .padding() } } } .navigationTitle("Select Body") } } struct LegSelectionView: View { @Binding var userSelectedHead: ImageHead? @Binding var userSelectedBody: ImageBody? @Binding var userSelectedLeg: ImageLeg? var body: some View { ScrollView(.horizontal) { LazyHGrid(rows: [GridItem(.flexible())]) { ForEach(ImageLeg.allCases, id: \.self) { leg in NavigationLink(destination: FinalSelectionView(userSelectedHead: $userSelectedHead, userSelectedBody: $userSelectedBody, userSelectedLeg: $userSelectedLeg, selectedLeg: leg)) { VStack { SelectionImageView(image: leg.rawValue) Text("Selected Head: \(userSelectedHead?.rawValue ?? "None")") Text("Selected Body: \(userSelectedBody?.rawValue ?? "None")") Text("Selected Leg: \(leg.rawValue)") } } .padding() } } } .navigationTitle("Select Leg") } } struct FinalSelectionView: View { @Binding var userSelectedHead: ImageHead? @Binding var userSelectedBody: ImageBody? @Binding var userSelectedLeg: ImageLeg? var selectedLeg: ImageLeg var body: some View { VStack { if let head = userSelectedHead { SelectionImageView(image: head.rawValue) Text("Selected Head: \(head.rawValue)") } else { Text("Default Head Image") } if let body = userSelectedBody { SelectionImageView(image: body.rawValue) Text("Selected Body: \(body.rawValue)") } else { Text("Default Body Image") } SelectionImageView(image: selectedLeg.rawValue) Text("Selected Leg: \(selectedLeg.rawValue)") Spacer() } .navigationTitle("Final Selection") .padding(.horizontal) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
0
0
453
Dec ’23
In-App purchase review screenshots for data assets
My In-App purchases are actually JSON files which provide metadata for my app. I am required to provide a "screenshot" for each of these IAPs before they can be accepted. What is the common practice for screenshots when it is just a JSON file of structured data to be used within the app. Surely someone else has run into this issue by now. What are we supposed to do?
4
0
668
Nov ’23
WebP image in Asset Catalog?
It appears I can't add a WebP image as an Image Set in an Asset Catalog. Is that correct? As a workaround, I added the WebP image as a Data Set. I'm then loading it as a CGImage with the following code: guard let asset = NSDataAsset(name: imageName), let imageSource = CGImageSourceCreateWithData(asset.data as CFData, nil), let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) else { return nil } // Use image Is it fine to store and load WebP images in this way? If not, then what's best practice?
0
0
894
Oct ’23
Xcode console output is full of CoreUI warnings about image subtype mismatches when running on Mac Catalyst
CoreUI is sending warning messages to the Xcode console when creating a UIImage from an image file with Mac idiom from the asset catalog, while running on Catalyst. My target is set to support running on Mac Catalyst with Optimize for Mac enabled (the latter seems to be the most important part). Loading the image into a UIImage with the designated initializer and presenting it in a UIImageView produces the following console messages: 2023-02-15 10:53:18.014394+0100 CatalystImageConsoleMessage[64253:8834791] [framework] CoreUI: _Bool CUIValidateIdiomSubtypes(NSInteger, NSUInteger *) got a device subtype '32401' that it match with idiom '7':mac. Assuming subtype should be 0 instead. 2023-02-15 10:53:18.014446+0100 CatalystImageConsoleMessage[64253:8834791] [framework] CoreUI: _Bool CUIValidateIdiomSubtypes(NSInteger, NSUInteger *) got a device subtype '32401' that it match with idiom '7':mac. Assuming subtype should be 0 instead. 2023-02-15 10:53:18.014503+0100 CatalystImageConsoleMessage[64253:8834791] [framework] CoreUI: _Bool CUIValidateIdiomSubtypes(NSInteger, NSUInteger *) got a device subtype '32401' that it match with idiom '7':mac. Assuming subtype should be 0 instead. 2023-02-15 10:53:18.014533+0100 CatalystImageConsoleMessage[64253:8834791] [framework] CoreUI: _Bool CUIValidateIdiomSubtypes(NSInteger, NSUInteger *) got a device subtype '32401' that it match with idiom '7':mac. Assuming subtype should be 0 instead. Working with more than a handful of images from the catalog makes the Xcode console output borderline unreadable because of these messages. The console doesn't have an option to filter out messages (and in general we consider it bad practice to ignore messages on the console). Tested on Xcode 14.2 with macOS 13.2. You can find a sample project at https://github.com/tamasjager/CatalystImageConsoleMessage.
4
5
2k
Oct ’23
macOS app icon not updating. Cached?
Hi, If I change the AppIcon in Xcode's Assets.xcassets, and rerun my app, the image used in the dock and app switcher does not update. If I "Clean Build Folder", and re-run, then it updates. This is annoying when I keep tweaking the colors in the icon and want to see how they look. A full rebuild takes a while, because I have a few Swift Package dependencies. Anyone know a trick to get the AppIcon to stop caching (or whatever it's doing)? I tried killall Dock and killall Finder, but that didn't help. (macOS 11.2.3) Rob
4
0
3.1k
Oct ’23