Xcode ignores Texture Atlas inside a subfolder - ios

I have a case where I need to keep the folders hierarchy in my iOS app bundle, which contains some texture atlases. However, unlike the case with group referencing, Xcode seems to ignore any texture atlas under directory that's referenced as a folder not a group. Any workaround for this?

Have you tried renaming and adding the ".atlas" at the end of the folder's name, dragging it to your project again and keeping the following option ticked? copy items into des... Create groups for any ... add to targets (your project selected)

In Xcode it's not enough move your folder to the Assets.xcassets. You must go inside Assets and select AR and SceneKit > Sprite Atlas , rename the folder and move all your sprites inside it.
P.S. remember to remove your app from the simulator/device before to launch the corrected Assets.

Related

Assets cannot be found

Before xCode 9, when I wanted to create a UIImageView with an image, I would drag an image into the project side bar and create a UIImage with the name of that file. This worked and all was well.
However, with Xcode 9 this will not work. It won't be able to find that file, even though it's there in the main bundle. What I needed to do was to put the image into the Assets folder, and then it was able to find the image and show it in the UIImageView.
Likewise, when working with Sprite Kit, I would create a folder in my desktop with a .atlas extension, drag all my images into that, and then drag the .atlas folder in the project. Then I'd create a SKTextureAtlas with the name of the .atlas folder, and it worked. With Xcode 9 however, this again did not work. I would get a 'Texture Atlas 'foo' cannot be found' message in the console. So I went to the Assets folder, clicked the add icon and choose New Sprite Atlas, renamed that folder, and dragged my images into it. Now creating the texture atlas with that name worked.
What I'm now trying to do, and having trouble with, is creating an SKVideoNode using init(filedNamed: "foo.mov"), and as you guessed, this no longer works if you dragged the file into the project's side bar. So I thought maybe I again need to somehow do this through the Assets folder. I found that when I add my .mov file to the Assets folder, it gets created as a 'Data' type ('Data' shows in the top right corner of its box in the Assets folder). What I can do now is this:
let d = NSDataAsset(name: "foo") // 'foo' is the .mov file in Assets
d.data // the underlying content
Turns out d is not nil, which was good news, but the only way to access the underlying content is just by way of .data, and you cannot create an SKVideoNode with data. I also wanted to load a sound file, which I used to do like this:
let a = SKAction.playSoundFileNamed("bar.mp3", waitForCompletion: false)
But I get the message 'Error loading sound resource: "bar.mp3"'.
Check to see if your resources are being bundled.
Go into your project settings and click on the Build Phases tab, make sure your resources are in the copy bundle resources section
I had the same problem but my issue was I did not select "Create groups" when dragging a folder of sounds into XCode. That plus the "Copy items if needed" worked for me.

Images living inside an imported pod .xcasset are selectable (and viewable) inside Interface Builder storyboard, but won't show in the simulator

I'm in the middle of some "Proof of Concept" project regarding Cocoapods, .xcassets, Swift 3, "cross-project loading images" (from pod bundles onto the main storyboard), etc...
My main problem right now is "images living inside an imported .xcasset (via pod install/update) are selectable and appear inside Interface Builder main project storyboard, but won't show in the simulator".
In runtime, the simulator running my main app yields something like this:
Could not load the "cx_green_tick" image referenced from a nib in the bundle with identifier "MyCompany.ios-appbase" when it tries to render the selected image. And then nothing appears on the expected placeholder space, just empty space.
MyCompany.ios-appbase is the bundle name of my main app.
cx_green_tick is the logical name of some image resource happily living inside my "Commons" imported project Media.xcasset folder.
This image resource consists of 3 proper .png files with their #1x, #2x, #3x names, etc...
My Commons Pod Project (the one containing the .xcasset files/folders I want to use in my main project) has a .podspec file with the following resources definition (among many other things):
s.resources = [ 'Commons/**/*.{png,jpeg,jpg,storyboard,xib,ttf,otf}' , 'Commons/**/*.{xcassets, imageset, json}' ]
Once I'm in the root folder of my main project, I just type "pod update/install" and I can see how the different pods I defined in my main app Podfile start to download and get perfectly stored into the expected Pods folder of my main project.
Then, inside Xcode, I can see how inside the Pods/Commons/Media.xcassets container there's the expected cx_green_tick image resource, with its 3 proper resolutions.
Then I change onto my main app Main.storyboard and select the cx_green_tick image resource to be used onto a UIImageView placeholder. Whenever I do it, I can see how this green tick image appears inside IB. But if I run the simulator, this image doesn't appear on its placeholder.
I'm using Swift 3.0, XCode 8, deployment target is iOS 9. All my involved Podfiles have the use_frameworks! keyword/line active.
I've REALLY been googling this for many hours (yesterday and today) but I can't see any hint on how to do it without having to do the image load by hand, programmatically. (In case it's something achievable, which I'm not really sure after all this)
BTW: If I load this image programmatically, explicitly selecting the bundle where the image resource lives inside Media.xcassets, the image appears without any problem in the simulator.
That could be a partial solution, but our main goal was not having to perform image loading by hand. Specially when (apparently) IB shows this image onto its image_name resources combo list on the top part of the screen for the UIImageView placeholder.
Any hint?
(If something is unclear, please ask and I'll try to reword it somehow )
Greetings and thanks in advance.

What's really happens when I create a "New Sprite Image" inside my Xcode images.xcassets?

Days ago I asked for How check the .spriteatlas sizes generated by Xcode? but I got no answer so I decided to slightly change my question:
What happens when I choose this option here inside the images.xcassets section?
Does Xcode provide a full atlas manager and I just have to add single images inside this folder or should I put inside a whole atlas (created by my self with the .plist file attached)?

Could not load the "" image referenced from a nib in the bundle with identifier

when I load my application it shows a warning message that
"Could not load the "" image referenced from a nib in the bundle with
identifier "
I searched and confirmed all my images. But it still shows that warning.
Select your image(s) in Project Navigator.
Open the File Inspector.
Make sure you have the target selected.
I had the same issue when I Refactor to Storyboard. Apparently the Asset catalog does not transfer the image reference. To fix, see below:
You would notice that your ImageViews is empty from reference.
1 - Click on the ImageView
2 Go to the Utilities bar where you would see you asset image is unknown
3 - Change it back to you image asset
This should fix your error. Hope this helps!
There might be many reasons of this error. To fix this issue you can just follow below given step:
Go to product menu of the Xcode, select clean.
If still you are getting the error, then remove the images from your project and again add the images to your project.
while adding image into the project, make sure that you have selected the Project name inside the "Add to targets". And also enable the "Copy items if needed".
Please Refer below image for better understanding:
Just select the image in Xcode and in right side, File inspector, under 'Target Membership' make sure your project is selected.
Another thing you can do is delete and re insert your image and make sure 'Copy items if needed' is selected and 'Add to targets' your project is selected.
Click on the image file in your Xcode navigator.
Once selected, go to the right side bar (of XCODE) which is
utilities and under file inspector, scroll to target membership and
select your project target file.
Then build and run the project again.
Xcode9 beta2 release note:
Jpeg assets in asset catalogs are not found on iOS 10 or earlier for apps built with Xcode 9. APIcalls for accessing the image such as UIImage.imageNamed: return nil. (32524123)
Workaround: Use png resources or limit app testing to devices running iOS 11 or later.
Xcode9 beta3 release note:
Jpeg assets in asset catalogs are found on iOS 10 or earlier for apps built with Xcode 9.(32524123)
For those that are getting this error while developing a cocoapod
I was trying to use an image from my pod's bundle, thats inside a .xcassets file, in the storyboard. It would show fine in the storyboard but when i ran the app it would crash saying it cant find the resource.
I changed my podspec to include s.resources as well as s.resource_bundles
s.resource_bundles = {
'SDKRes' => ['SDK/Assets/*']
}
s.resources = ['SDK/Assets/*.{xcassets}']
Then it was able to load the resource properly from the storyboard
You can try opening your storyboard or nib as Source Code and then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
I have just updated to XCode 9 and it started giving me this issue. I created a new Image Set in the Assets section and added the images I wanted to this, then re-added them to my tab bar images with custom names and it worked fine. Hope this helps!
PROBLEM
This happened to me seemingly out of the blue on a tab bar controller with icons for each tab. The storyboard was still showing my image icons and the assets existed with the expected names.
MY FIX
Select the tab bar icons in their respective view controller and reassign the image like you did the first time.
This happened to me as well. I was doing everything right when adding the image but for some reason it was not working. I had to click on the image again once added, and then on the right toolbar under "Target Membership" I noticed my project was not selected even though I was selecting it when adding the image. I selected it here and everything worked fine.
I got the same error message (in XCode 8), even though the app ran fine (in the simulator and on the device).
I found the problem: In my storyboard, using the document outline pane, I clicked through every single UIImage, and looking at the attributes inspector for each UIImage - in the Image View section - found that one UIImage had a blank file name (instead of the .png file name containing the image). Reselecting the .png file name from the dropdown box fixed the error message.
I have fetching same issue in xcode 9.
just tick on target membership
I pulled my hair out over this issue for hours and none of the solutions in this thread worked. The problem, in the end, was that the Xcode project files were stored on a Google Drive file stream. As soon as I moved it to the local drive or iCloud it worked fine.
My case was a bit different. I was using an old IBDesignable element which had some property of setting an image directly from the storyboard. Since that element was old, hidden and unused the images it had were not present in my assets folder.
Now Xcode won't be able to search this image since it is not in the project anymore. But if you search in the finder, inside your project, you'll find the XIB/Storyboard in which it is mentioned. From there you can find it manually by opening that XIB or Storyboard as source code and search. Once found either replace them with a new image or remove the unused element.
Look into storyboard file you'll see a question mark icon on any of the imageView (as shown in screenshot below) or UIButton image.
Just correct it and the warning will be gone.
Hope this helps
My guess is that you have an image in the Project Setting->Build Phases->Copy Bundle Resources which loses its reference and appears in Red text color. Remove this image from there and re-add.
This happens often due to relocate the image file after adding into project where image was added as a reference instead of a copy.
May be this can fix your issue.
Urughhh. I tried to fix this with all the above solutions, but nothing worked. What finally worked was:
Delete image from your project and select Move to Trash
Clean project
Close and restart XCode
Rename your image filename so something other than the previous name
Add new image to your project
I was facing the same problem, I solve it by deleting folder and create again and past all images then add reference again.
Based on what #hstdt posted above, it made me think I should check that my image is a filetype that doesn't have any bugs related to it. (https://stackoverflow.com/a/44558948/6804257)
I was using a .gif. I got rid of that image and instead used a .png. Now it works.
Had the same issue and none of these answers worked for me. Instead I restarted the mac and iPhone I was working with and then everything started to work fine again. 🤷‍♂️
My case is difference. I have more one assets folder. So I added to the wrong one.
Just remove and add to the right.
In my case,removing and adding the assets folder from the target fixed the issue.
Xib sets a wrong name for folder reference images. For example I have the folder like Menu->icon.png. Xib sets the "icon" name for the image. It should be "Menu/icon". So do no set images in xibs if you use a folder reference images.

XCode Has No Option to Enable Texture Atlas Generation

I'm following along with this apple doc, but for some reason when I search for "Sprite" under Build Settings in XCode nothing pops up. I've also tried searching for "Enable Texture Atlas Generation" and nothing comes up.
I have Xcode 5.0.2 if that helps.
The SPRITEKIT_TEXTURE_ATLAS_OUTPUT settings will be there in a new project but the SpriteKit Deployment Options will be created later. Of course you must select SpriteKit Game template when you create the project.
These settings added automatically to your project when you add the first texture atlas resource to it. You need to add a folder named with the .atlas extension. For example you have textures for your hero the atlas should be named as hero.atlas.
I was bedeviled by this exact issue for the past day, when I discovered that if I add an atlas to the project by dragging and dropping, the Sprite Kit Texture Atlas Options were not added to the Build Settings. If I chose File > Add Files to... from the menu bar, however, the Sprite Kit Texture Atlas Options appeared in the Build Settings.
So, apparently, do not drag and drop to add a texture atlas.

Resources