Save image in a folder and directly use XCode - xcode

I was wondering whether it is possible to save an image you just edited in Photoshop, and immediately it is useable in XCode, instead of dragging the image into XCode all the time.

You could create a folder reference to the location you are saving your images.
To do this, use the "Add Files to 'NameOfProject'" menu command, then select your folder. Ensure that the options are set as follows:
Then the images should appear in Xcode when you view the contents of that folder. When referencing them, you must use the name of the folder. E.g. [UIImage imageNamed:#"MyImages/image.png"];

Related

Xcode add too many pictures

There are 1500 pics, each 64x64 pixels, that I need to use within my Xcode Project. I will use these pictures in the TableView, but Xcode crashes when I put it directly into the Assets.xcassets directory. What is the best way to use these pictures?
Adding your images into the Xcode project - either in an asset catalog, or directly as an images subdirectory - will pollute interface builder - fill up every combo box where you could choose images, e.g. as a background image (normally, "pollute" would normaly not include "crash", but we all know Xcode all too well...)
If I understand you correctly, you only want use those images "per index", or at least only programatically, like in your table view. But you do not want to manually assign them in Xcode Interface builder.
I would suggest to
create a container file (like .zip, without compression) with all your images
add the .zip to your project
at program startup, uncompress the .zip file into the cache directory of your app (first check if you already did this the program start before :-)
access the image files via the path to the cache directory
If the image files are too large (so your application footprint on the device would get too high), just don't decompress them and take them directly from the .zip archive
There are several (sample) projects available to use .zip in Swift, like https://github.com/marmelroy/Zip
I want to suggest another alternative to zip method. In this method, Xcode does not know anything about the files, so it cannot crash or freeze trying to index them. Also this method does not have overhead of zip method.
Place your assets to your project form finder. Such as './assets'.
Create a new run script phase on Build Phases
Paste this script
SOURCE="$SRCROOT/assets"
TARGET="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app"
rsync -r --delete "$SOURCE" "$TARGET"
Use the images with UIImage(named: "assets/filename.png")

Replacing an existing image in an Xcode Project

I am trying to update an Xcode project. The update is to replace an image that is displayed in a static window. I replaced the image being called, the new image has the same name and size, but when I open the window, the image does not fill the entire window like the original image did. I a new developer in general, but a total newbie when it comes to XCode. Any help would be appreciated.
Replacing an image file in a Xcode project can be done as:
Go to File in Xcode using the Project Navigator.
Right click the file and pick "Show in Finder"
Drag new file into as same folder as the old file. (make sure the old file and the file have the same name)
Say yes, you want to replace the file.
And your done.
Compile and run will show the new image. I've done this hundreds of times, usually updating placeholder images and never had any trouble.
As for your particular problem, you didn't describe the steps you used to replace the image, so I can't testify on that, but if you do the above and don't get the results you want it's going to be from a bad image file (different size, etc).

How can I set the icon for a Mac Application in Xcode?

I have been learning a lot about writing Objective-C code and designing in Interface Builder and I wanted to set icons for my simple programs.
I added the same JPG to all the size fields in Icon Composer and got an ICNS, but I couldn't figure out how to add it to the project.
Thank you in advance.
Since Xcode 4.4 Icon Composer is no longer the recommended way to create icons and is no longer included in the standard install of Xcode.
Due to the introduction of Macs with retina display, it is now recommended to provide high resolution versions of all graphics including app icons.
To give your app an icon under Xcode > 4.4 do the following:
Create a folder [IconName].iconset in Finder
In this folder place your icon as png files. You'll need the icon in
sizes of 16px, 32px, 64px (retina only), 128px, 256px, 512px and
1024px (retina only)
These icons must be named with the pattern icon_16x16.png,
icon_32x32.png, icon_128x128.png and so on
To support retina displays you must also add icon files with double
resolution, named icon_16x16#2x.png (with size 32x32),
icon_32x32#2x.png (size 64x64) and so on up to icon_512x512#2x.png (size 1024x1024).
drag this [IconName].iconset folder to Xcode (copy if necessary)
in the info.plist file set the "CFBundleIconFile" (Icon File as Key) value to
[IconName] but without the .iconset extension
Annotations:
it is (currently) not required to provide the #2x icons
it will (usually) also work if you don't provide every icon file
the iconset folder should not contain a icon_64x64.png file. the 64px icon is only for the retina version of the icon_32x32
Update:
In the end your .iconset folder has the following 10 items:
icon_16x16.png
icon_16x16#2x.png
icon_32x32.png
icon_32x32#2x.png
icon_128x128.png
icon_128x128#2x.png
icon_256x256.png
icon_256x256#2x.png
icon_512x512.png
icon_512x512#2x.png
Official guide:
https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html
Additional information:
To convert the iconset folder to an icns file, run the following command on the terminal:
iconutil -c icns [IconName].iconset
where [IconName] should be replaced with the prefix of the iconset folder. You now have a file called [IconName].icns. In Xcode 4.4, in the Target Summary, right click the question mark for the icon, then select the icns file. You should then see the question mark get replaced with the icon.
As of Xcode 7 (not sure when this was originally introduced), you can use the Assets.xcassets file for app icons. This file is included by default for new projects.
Simply:
Go to your target's settings and ensure that under General, App Icons the Source is set to AppIcon.
Add all 10 png icons to your Assets.xcassets's AppIcon image.
Delete derived data if you have launched the app before, otherwise it will continue to show the default icon.
Run the app; it should now show your icon in the Dock, Application Switcher, and anywhere else it should appear.
Follow these steps to add an application icon to your project. This is the icon that will be show by the MacOS in the doc bar and alt-tab display.
Create an icon .icns resource file
Place it in the "resources/macos" folder
Add it to the resources group in the xcode project
Edit the Info.plist file and change the "CFBundleIconFile" value string to "icon"
Also, img2icns tool can come handy to convert images to an icon.
It's easy
Use automatic tool (Such as IconFly) for create correct ICNS or iconset with all necessary size.
Then drag and drop created ICNS or iconset to Xcode.
in the info.plist file set the "CFBundleIconFile" value to [IconName]
Steps to add an application icon to your cocoa project.
Find 'Icon Composer' from spotlight.
Drag and drop the icon(name should be like imagename.icns) in the given boxes.
Select one box and save it.
Drag and drop the saved image in the Resources folder of your application.
Select target-->right click on project name-->Select GetInfo.
In Properties enter the name of 'Icon File'.
Now Clean Build and run your application.
Xcode 8.2.1
Convert .png 👉.icns via IconMaker
Add the AwesomeApp.icns file in the same folder as info.plist
Drag AwesomeApp.icns file into xcode in the same folder as info.plist
In info.plist set icon: to AwesomeApp.icns
Step 1: Get iconfile name from info.plist and place icns(icon file) folder in SourceCode/resources folder
Step 2: And same thing goes for xcode,you have to copy all images from xcode using copyallframeworks or copyall resource file in your xcode and build the app again.

Cannot add an icon to Resources

Have been inputting and testing some sample code and everything seems to be ok. Just that suddenly I am running into this very frustrating problem of trying to add an icon to the project. Have downloaded an icon file (extension : icns) to my desktop and dragged it to the "Resources" group in xCode. Then a dialogue comes up from xCode where I checked the 2 options : "Copy items into destination group's folder (if needed)" and "Recursively create groups for any added folders". But when I press the "Add" button, an "Alert" message box would come up. It says "Could not copy the icon to ...". Hope that someone knowledgable in this area would give me some hints...
This failure message usually results from attempting to add a file (that is outside the project folder), when a file with that name already exists in the target location within the project folder.
For example, let's say your project folder is ~/Developer/CoolProject/, and the Xcode project is at ~/Developer/CoolProject/CoolProject.xcodeproj. If you drag an image, coolImage.png, from your Desktop to Xcode with the options set as you described, Xcode will copy the image file to ~/Developer/CoolProject/coolImage.png. If you then repeat this same procedure, it will fail the second time with that error message.
What I would do is, in the Finder, check inside your project folder to see if the icns file has already been copied into the project folder. If there's a copy of the icns file already in the project folder, and that icns file isn't listed in the Groups & Files list in Xcode, you can resolve the problem by dragging the existing copy (that's inside the project folder) into the Xcode project window to bring up the Add File dialog. You can keep the same options as before, and this time, Xcode won't need to copy the image and so you'll avoid the error.
[UPDATED] OK, so what you'll want to do, based on the comment above, is go in the Finder and remove the existing .icns file from your project (in other words, move it to the Trash). Then you can re-add an icon with the same name (from a location outside your project folder) without getting the error. Also, in the future, remember that you might want to consider using the Also Move to Trash option when deleting files from within Xcode, if you no longer want the unused items inside your project folder.
Also, you may want to double-check to make sure the file in question is included as part of the Active Target. For example, if you add a file to your project, but the "include in active target" checkbox for the file is unchecked (like the ReadMe.rtfd file in the image below), then the file won't be copied into your application bundle at build time or be available at runtime.
(To add that Active Target checkbox column to the Groups & Files list, Control-click on the table column header view and choose Target Membership from the menu).

How to quickly add back missing file in xcode

I zipped up my project folder in xcode and moved it to a new computer. When I open up the project it has missing files (file appears red).
How can I add all these files back or re-link them. It is like 20+ files?
Why didnt xcode store the relative path?
Xcode may not update location for some files of your project when you copy/move it from one environment to another. The easiest way I found is something like this:
1-Select your files like this, if they are in different groups, then repeat the flow on each group separately:
2- Show the file inspector:
3- You may notice Xcode has an absolute path for them, which is something not useful, so click on the little icon near Multiple Values. navigate to the folder where your selected files are stored in the finder and click "Choose".
Also, don't forget to change the Location to Relative to Project. Now you will get something like this:
• Select all the missing files that are in one folder in Finder.
• Change Location to Relative to Group ( that's in the File Inspector View -> Utilities -> Show File Inspector )
• Click the choose file button; it is under the Location drop down menu; it is an image that looks like a very small window with a document inside it.
A Choose folder containing the selected references sheet should appear.
• find and select the folder containing the missing files in the finder, then click Choose
(Tested in In xCode v4.3.2)
I normally keep all my files related to the project inside one folder (nested where necessary) and yeah I frequently exchange project files (zip and move) with my peers and nothing like that has ever happened to me.
You can always just drag the files en masse back onto the XCode window, and they'll get re-added. If you have file-system folders that match your Xcode internal organization that makes it even easier.
The UI has changed. In Xcode 10, there's a tiny dot with an arrow in it next to the file path. This does nothing as far as I can tell.
There's an obscure folder icon offset up and to the right of that non-functional arrow... this actually is a button, and it DOES allow you to relink the file.

Resources