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

41 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
119
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
122
1w
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
120
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>
12
5
3.9k
1w
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
573
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
416
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
666
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
378
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
529
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
574
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
450
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
663
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
884
Oct ’23
NSImages blurred-out in Sonoma
My app uses various PNG images for parts of its UI. In Sonoma these images are rendered all blurred. It looks like I'm putting a 10 or 20px gaussian blur on it, which of course I am not. In prior macOS versions they have rendered just fine. Occasionally some user action in the app will cause a part of one or two images to render sharply, but then it quickly reverts to the blur. I have added the PNGs to the app as image set assets, providing 1x and 2x versions for light and dark modes respectively (so four images each). I'm loading them using NSImage(named: ), and in most cases putting them into an NSImageView. I also use one of them as a patternImage: if let image = NSImage(named: "RackFrame") { let color = NSColor.init(patternImage: image) color.setFill() dirtyRect.fill() } Both methods result in the same issue. Any thoughts on what's going on would be gratefully received!
0
0
598
Sep ’23
Assets.car increased in size significantly in Xcode 15
The Assets.car file in Archive and thus in exported .ipa file has significantly increased when archived in Xcode 15 compared to Xcode 14.3.1. For example, the Assets.car file size in the archive made in Xcode 14.3.1 is 125 MB, but in the archive made in Xcode 15 from completely the same project size is 200 MB. Assets have many images as PNG and PDF. What has changed in Xcode 15 for building Assets.car file and how the size can be reduced? Use SVG instead of PDF (and PNG?)? Thanks
0
0
759
Sep ’23