How to identify that asset added inside Assets.xcassets are used in project? - swift

How to identify quick way the Assets added inside Assets.xcassets for Images & color are using inside project or not.
Example:
int value = 10
In this case int value not used inside application which give an warning.
Initialization of immutable value 'value' was never used; consider replacing with assignment to '_' or removing it
What if inside Assets.xcassets added color or image are not used how to identify ?

Xcode has no tool which could highlight not used assets but there is a open source project called "AssetsChecker" which will do the job.

There's no way a tool can know which assets are not being used by your application.
Imagine that you are creating a Weather app, and the data you receive from the server includes the image_key that you use to know which asset to load.
If a tool to find unused assets was used, it would tell you that every image or color that is not referenced directly is not used, which would yield a LOT of false positives.

Related

How do I call images from xcassets?

How can I call an image that I have saved in the xcassets folder?
I'm using ARKit. I'd like to make an "Earth" figure by wrapping an "Earth" skin around a spherical node. I can assign a color to it, like so:
earth.geometry?.firstMaterial?.diffuse.contents = UIColor.blue
But I'm unable to assign textures using either:
earth.geometry?.firstMaterial?.diffuse.contents = "#imageLiteral(resourceName:8k_earth_daymap)
or
earth.geometry?.firstMaterial?.diffuse.contents = UIImage(named:"8k_earth_daymap.jpg")
Am I using the wrong commands? It seems like Xcode does not recognize the 8k_earth_daymap.jpg file I have saved locally in xcassets...
earth.geometry?.firstMaterial?.diffuse.contents = "#imageLiteral(resourceName:8k_earth_daymap) is not real code; there is an extra quotation mark, so this wouldn't compile.
earth.geometry?.firstMaterial?.diffuse.contents = UIImage(named:"8k_earth_daymap.jpg") is wrong, because .jpg would not be part of the name of an image set.
Finally, the phrase "that I have saved in the xcassets folder" is worrisome. You must not put anything manually into the xcassets folder. You must let Xcode do that. You simply edit the asset catalog in the project navigator and work by way of Xcode's asset catalog editor window. If you're not working through this window, you're doing it wrong:
Thank you, #matt. Your suggestion helped. I was adding the jpg extension when it was not needed. I was also calling the image using an Image Literal, but for some reason, it did not work. I was able to call the image using UIImage.

Load material from assets in Unity

In my Assets folder I have a folder named Material where I stored all the needed materials, One of the materials in the Material folder is Night_Sky, which I want at a certain moment of the game to replace the day_sky and set Night_sky as my default Skybox. I tried many codes all of them return null object, examples :
night = Resources.Load("Material", typeof(Material)) as Material;
or
night = Resources.Load("Material/Night_Sky.mat", typeof(Material)) as Material;
How can I load my Night_Sky material, or if there is an easier way to switch my skybox to night_sky thank you for sharing it
This will not work as Resources.Load requires you to place the object in the Resources folder. This information can also be found in the Unity Docs
For this to properly work you will need to create a folder called Resources Inside the Assets folder. After which you can add the Material folder to this. So the folder structure would look as following
Assets/Resources/Materials/Night_Sky.mat
Further more the script to load the material looks just fine.
If you really do not wish to use the resources folder, you can try to obtain the materials using System.IO folder search options instead. But I would advice you to just use the build in Resources function.
When you do use the Resources.Load() however, you will need to keep a few things in mind. The path is case-sensitive and requires you to add the file extension as well. So in the example above, that would result in:
myMaterial = Resources.Load("Materials/Night_Sky.mat");
Unity 5.0 or >
As Nika Kasradze mentioned in the comments. In unity 5.0 or up extensions must be omitted. Making the correct unity5 syntax
myMaterial = Resources.Load("Materials/Night_Sky");

One App, Multiple Branding

I have made an application for the iPhone but it is required to be released with multiple brandings. Eg Differernt:
App Name
Icons
Default.png
Text replaced for the app name in IB
Colour schemes for all images such as backgrounds, icons etc
I'm not sure of the best way to do this.
I was thinking of a plist file for each branding that would have the name of the files to load eg "brand1_background.png" for brand1 but that would get very messy with the text replacement. It would also mean that all brands images would be in the package making it of larger size.
Looking around a bit I could have an 'images' folder for each brand and drag it in to build that brand's app, however the text is still an issue.
I'm wondering how everyone else would handle this situation as I want to do it as right as possible.
There are 2 different aspects to this problem, which I'd describe as follows:
Stuff that can be changed dynamically
Stuff that can't be changed dynamically
The first category is super easy. If you have your colo(u)r schemes stored in some easily-readable format like a plist or whatever, you can just load up that file during app startup, and build UIColor objects from them and use those where appropriate. The same goes for images used within the app itself. This is not a hard problem.
The second category is trickier. This is stuff that has to be baked into the application because of code signing. This means that the things like the App Name, the icon, Default.png, etc, all have to be changed before the app is signed in the compilation process. So what I'd do is bake up a bunch of scripts to take your branding information (name, image files, icons, etc) and load it up, then generate your Info.plist file and whatnot. This should be done as one of the first phases of your compilation.
For what it's worth, I work on an application where we do exactly this process, and it works pretty well. It's a bit tedious to update when we change what resources get branded, but I'm not sure there's any decent way around that.
Create a target for each of your brandings. For each single target you can add different files (e.g. images) and set an app name. You can even use the same file names (but stored under a different location) and you can build your brand-apps pretty fast.

Eclipse standard warning/error overlay icons

I'm writing an Eclipse plug-in... In my custom label decorator, I want to overlay a warning icon, and I'd like to use the standard one used by eclipse (the little yellow triangle). How can I get an image descriptor of this icon?
I tried using
workbench.getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING)
since that ID seems to match what I'm looking for, but the shared images collection doesn't actually have that image in it (so I just get a null returned).
Is there some other shared image collection that I should be looking at?
You have run across an Eclipse bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=304397
The bugzilla entry gives this code as workaround:
ImageDescriptor descriptor =
JFaceResources.getImageRegistry().getDescriptor("org.eclipse.jface.fieldassist.IMG_DEC_FIELD_WARNING");

iPhone simulator shows app's images but iPhone does not

I have create an application on iphone using objective-c.In this application i am just displaying different players images stored in one folder, which will be run perfectly on simulator. But when I deploy it on iphone it is not showing the images of the player.
for that the code is:
UIImageView *imageplayer = [[UIImageView alloc]initWithFrame: CGRectMake(imgx, imgy+45,135,150)];
imageplayer.image = [UIImage imageNamed:playerpng];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:playerjpg]];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:#"noimage.png"]];
[self.view addSubView:imageplayer];
Plz solve this query.
Thanks in advance
Sometimes xCode doesent update correctly the bundle, try cleaning and building again.
I am currently experiencing this problem as well. I was able to correct it after a bit of debugging and reviewing the build file.
When I do an ls -l, I noticed that some of my png files have a # symbol beside the permissions. When I followed that up with a ls -l#, it showed that the files with an '#' had an attribute set 'com.apple.quarantine'. This attribute is given to a file (often from a zip, jar, or other executable) that is downloaded from the net. You can get rid of this attribute by performing:
xattr -d com.apple.quarantine *.png
Then, select the images in XCode, and check that the checkbox under the target is checked. In my case, it was not, so the images weren't being included in the bundle.
I had the same problem, solved by using all lowercase for the file name in code - image.jpg, but it does not seem to make any difference what case the actual file name is, e.g. Image.jpg
check name of image file. It must be "noimage.png"
not Noimage.png or noimage.PNG
Just to clarify, does the "noimage.png" display, or is the program loading a player image but failing to display it? Or is nothing loading.
These should easily be determined in debug mode.
A few additional things to check...
1) Just for testing, start out with PNG versions of the player files. This is the primary format on the iPhone and might eliminate a file format issue or other anomaly that the simulator is not sensitive to.
2) With regard to fixing in an image editor, specifically make sure that the image is set to a DPI of 72 pixels/inch. The iPhone and particularly Interface Builder are very sensitive to this being correct and will sometimes not display or will display a very blurred version of the image if incorrect.
3) Make sure the image(s) haven't been added multiple times (from different directories and/or to different group folders). We encountered a situation where we had inadvertently imported the same images at two different layers within the project hierarchy and this can cause unexpected behavior within the iPhone (selecting randomly or failing to select).
4) Make sure the Get Info -> Targets has your particular target checked. The simulator may still see the image but it will not get deployed to the iPhone.
5) Make sure you can view the image within XCode and that it looks correct.
Barney
This happens to me sometimes. I once spent half a night trying to figure out what was wrong. In this end, this is what worked: open the image with an image editor and save it again. That's all. I'm using the free Acorn image editor to do this. Haven't tried it with Photoshop. (After all, it seems that Photoshop might be responsible for introducing the error in the first place, although that's far from sure.)
I don't know what causes the problem. I usually get it when I use png files that have been sent to me. Could be a simple file permissions problem, or some more subtle problem with the image format. I would be very interested in hearing the opinion of better-informed people.
In any case, if all else fails just try this: open the image with Acorn, save over the original file. Works for me.
Make sure the image files are added to your XCode project.
After some investigation, Michael's comment seems to have a solved it for me. I had all lower case as the file name but was following variable convention and had the png file with an upper case for the second part of the file name. Here my file was putback.png but was referenced in my code as putBack.png
UIImage *putBackImage = [UIImage imageNamed:#"putBack.png"]; //wrong
UIImage *putBackImage = [UIImage imageNamed:#"putback.png"]; //correct
Select correct target while adding image files to your project. Following are steps to make it further clear
Select Add Files to "YourProjectName"
In opening window there is an "Add to targets" option at bottom that shows all available targets
Check target or multiple targets in which you want to add images
Press "Add" button and you are ready to go