Xcode add too many pictures - xcode

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")

Related

Archive recovery in xcode?

I recently used a system tool which removes 'junk' files to free space up. It deleted every single photo on my hard drive... My xcode code is present for an application I have but can I recover the lost app photos from an xcode archive which still exists? Many thanks, as I can't update my app anymore because of it.
If you can get the ipa that is a zip file, change the extension from .ipa to .zip and double-click to unzip.
That will produce a folder named Payload and in that folder is the app.
The app is a is a package, right click on it and "Show Package Contents".
All your images in the app will be there.
Additionally, if the images were added as Assets there will be an additional step to extract the images form the Assets.car file. See this SO Answer for extraction information.

Two file with the same name by cocosbuilder

I would like to use cocosbuilder and cocos2d-x to develop my game for old and new iPhones. I would like to create one file for two resolutions. I created one ccb file and then I published it to retina and normal resolution. Everything works great but now I have two png files with the same name:
Published-iOS/resources-iphone/star.png
Published-iOS/resources-iphonehd/star.png
There is an issue. I am using Xcode and it doesn't like 2 files with the same name in the project. I can add these files to projects in separated groups but in final application bundle there could be only one star.png file. It is selected randomly. When I launch my app on iphone 4s I have picture from old iphone display. How to use cocosbuilder for multiple resolutions ?
You should import the resources-iphone, and resources-iphonehd directories in your XCode project as folder references instead of groups. You can do that by drag and dropping the folders onto your XCode project. When you do that you will see the directories appearing in your applications bundle. You can check that by selecting your application's target and going to Build Phases->Copy Bundle Resources.
After that, on you ApplicationDelegate.cpp file you should add those folders in the search paths list of CCFileUtils.
std::vector<std::string> resDirOrders;
if (resolution is iphone)
{
resDirOrders.push_back("resources-iphone");
}
else if (resolution is iphone retina)
{
resDirOrders.push_back("resources-iphonehd");
resDirOrders.push_back("resources-iphone");
}
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);
This is the recommended way of handling multiple resolutions according to the cocos2d-x devs (check out this article). You can use the window size from the CCDirector to determine the current resolution. In the iphonehd case I'm including the non-retina folders as well as a fallback.
Xcode and iOS app bundles aren't organized in folders, but rather flat bundles. You'll need to rename your files for it to work. I suggest something like this:
// iOS Standard
Published-iOS/resources-iphonehd/star#2x.png
or this
// cocos-2d Standard
Published-iOS/resources-iphonehd/star-hd.png

How do I add an icon to my Xcode project?

I have an Xcode project for Mac OSX, and I'd like to add an icon file (.icns) to my project and set it as the App Icon. How would I do this?
The key here is that you need an ICNS (icon set) file.
The right way to create this is described in the Human Interface Guidelines, and the details are covered in various user's guides and reference guides in Apple's maze of twisty little documentation, but I'll summarize it here.
There are third-party tools that can do this, as well as plugins for Photoshop, GIMP, Illustrator, etc., that can output a correct .icns file. But make sure, if you use such a thing, it's up to date, because Apple changes the rules all the time.
If you need to do it manually, here's what you do:
First, create a set of PNG files at different sizes. The exact list of what you need changes over time. See Provide the Correct Resources and Let OS X Do the Work if that link lasts longer than the current list; otherwise, search for it at http://developer.apple.com yourself. But, as of early 2013, it's 512x512, 256x256, 128x128, 32x32, 16x16, and #2x versions of each. All of them should have the sRGB color profile embedded in them. They should be named either icon_512x512#2x.png, icon_512x512.png, etc., or MyApp_512x512#2x.png, MyApp_512x512.png, etc. Put them all in a directory together named, e.g., MyApp.iconset.
"But wait! I just want an icon, I don't want all those sizes!" Well, you really do want all those sizes. Your 512x512 icon will look horrible when scaled down to 32x32. And on a Retina Mac, when your icon gets scaled up to double resolution, instead of getting sharper it'll just get jagged. Also, if you want to get into the App Store, Apple will reject you if you don't have them. But, if you insist, you can get away with just putting icon-512x512.png in the folder, and follow the rest of the steps, and it will work.
From the Terminal, cd into the parent directory, and type iconutil -c icns MyApp.iconset. You will get a file called MyApp.icns.
Now you can do the steps suggested by Douglas, and it will actually work. In Xcode, select your project in the Project Navigator, select your app target in the project sidebar, select the Summary tab, and drag MyApp.icns from Finder to the App Icon box.
This may not have any visible effect in the GUI, except to add MyApp.icns to the Project Navigator. In other words, you may still see the "?" icon. This seems to be a bug in Xcode 4.5. If you follow the out-of-date recommendations from the HIG two versions ago, Xcode always shows the icon, but if you follow the current HIG, it doesn't. Go figure. Hopefully Apple will fix that some day.
But for now, it doesn't matter. Build the project, and then look at MyApp.app, and it will have your icon in the Finder, on the Dock, etc.
Now, I know you don't want to draw the same picture in 10 different variations, you just want something simple. As long as you don't want to get into the App Store, you can get away with cheating, in two ways:
Scale the 512x512 (1024x1024 pixel "512x512#2x" if supporting hi res) image to all of the other sizes, using your favorite tool.
Create a .icns with nothing but the 512x512 image in the iconset.
The second one is simpler, and less cheat-y, and ultimately Finder is probably going to scale your 512x512 image as well as you would have anyway.
Finally, if you've manually edited your Info.plist or changed build settings (or you're using a project imported from a much easier version of Xcode), just dragging the image may not be enough. If you need to do the same steps manually, here they are:
MyApp.icns has to be in the Project Navigator as a file in your project. (You can drag it here from Finder.)
In Build Phases, the Copy Bundle Resources should include MyApp.icns. (You can drag it here from the Project Navigator.) (If you're not using the normal Build Phases for some reason, you need some other way to get it copied to Contents/Resources/MyApp.icns at build time.)
Your Info.plist should have an Icon file (raw name CFBundleIconFile) named MyApp, with no extension.
That's all there is to it.
In the project navigator, select an asset catalog.
Choose Editor > Add Assets > App Icons & Launch Images > New OS X Icon.
An empty OS X icon set is created, with an image well for each image representation in the set.
Drag icon file from the Finder to the appropriate image well in the set viewer.
Alternatively, you can add images by selecting an asset catalog, and choosing Editor > Add Assets > Import.
I am pretty sure you will have to put your icons into the project and then recompile. Let us know how it goes.

Save image in a folder and directly use 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"];

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).

Resources