objective c iOS file structure confusion - ios

I'm just new to iOS and am really confused by how files are managed.
In my project, I have set up directories, so I have in xcode:
Supporting Files
. Set 1
..pic0101N.png
..pic0102N.png
. Set 2
..pic0201N.png
..pic0202N.png
etc..
Also in the file structure where my app is (on my Desktop in a folder named FTF), I have a directory named images and a subdirectories for Set 1, Set 2, etc
When I click on an image in Xcode, the full path is listed as: /Users/MyName/Desktop/FTF/FTF/images/Set 1/pic0101N.png
My question is, how do I get a list of all the images in the Set 1 folder?
I've tried the various ways of using:
[NSBundle mainBundle] but, it all boils down to that my path seems to be:
/Users/MyName/Library/Application Support/iPhone Simulator/6.1/Applications/Axxxx1E9-19B3-XXX-XXXX-xxX5xXxX4x9/FTF.app
And that there doesn't seem to be any of my file structure in here, like the files are in there but not in any directories, they all just seem to be a bunch of files in there.
NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:#"png" inDirectory:#""];
yields a list of all the PNGS as such:
/Users/MyName/Library/Application Support/iPhone Simulator/6.1/Applications/Axxx81E9-19B3-4B4D-9FD4-XXXXX4499/FTF.app/pic0101N.png
/Users/MyName/Library/Application Support/iPhone Simulator/6.1/Applications/AXX9-19B3-4B4D-9FD4-8x9xx4499/FTF.app/pic0101P.png
I think I must have a fundamental confusion of what is going on. Could someone please help me out?

That's because Xcode is being unhelpful (and/or it assumes that the developer is dumb or something) and whenever you create a group, it's only reflected in the project structure - no corresponding folders are physically created on the filesystem.
If you want to get yourself real folders, that's also possible - refer this question.

What you are looking at is the difference between the Xcode project structure, the MAC OS X file system structure, the iOS app file system structure and what files are actually copied to the app during build.
For a start, having files in a location on Mac OS X doesn't mean they will be in any kind of similar location in the project or the app.
The iOS app is a bundle of contents (link), some of which is not editable and is set by Xcode when building the app and some of which is able to be written to (like the app documents directory). The files that are copied to the app are controlled by the build phases settings in Xcode.
The way you are using NSBundle is the correct way to find and use resources that were copied to the app during the build.

Related

How to open Xcode Projects on a Different Mac/Hard drive

I recently got a new hard drive and reinstalled Mac OS X on it. I copied my entire folder with all my Xcode projects over. However when I tried booting up one by clicking the project file, Xcode opens up with only the project file present. All of the files with actual code on them are not appearing.
I tried to add files but even that would leave most of the files with code on them greyed out in the finder.
Question, what is the proper way of transferring these projects specifically in Xcode 7? I have not been able to find anything concrete.
So, the only way I know of to do this efficiently is to load up the project file XML in your favorite editor and go manually fixup the paths. I don't recommend this.
Unfortunately, the way to do it through the UI is for each file, you need to open the Utilities Bar on the right, select the file, then update the path via the little folder icon in the Identity and Type section. Here's an illustration:
Then repeat for every file in your project. Sorry.
i had this same issue i mean you could always manually transfer code through word documents or notes, but for me i had copied the entire project folder and the document transferred just fine just make sure you transfer all of the files with it and not just the one file for the project itself
delete the xcode application and reinstall it from the Mac App Store.

File With Same Name From different folder in ios

I am using "xcode 6.1.1" and "cocos2dx-3.2".
I need to access same file name from different folder.
In Resource i have 3 folder "A,B and C" and all this folder contain image with same name "1.png".
If i need to access 1.png of folder "A" ,How i can do this in cocos2dx please help?
following code is working fine in Android but not working in iOS
helpImage->setTexture("A/1.png");
Thanks.
Didn't used cocos for some time now, but it is pretty easy to do.
Do this:
Prepare directory with your game data. Here lets call it "GameData". Pick name you like.
Drag and drop that directory to the xcode, probably best location is Supporting files. Dialog will show up. Select "Create folder references", deselect copy if needed.
And basically you are done. During build process all resources will be copied to bundle with paths as is in that directory "GameData". So you can have files with same name without problems.

Can I access an xcassets directory on the filesystem?

I would like to dynamically load all images in an xcassets directory. The files are named StockPhoto# where # is the number in the list. If I can access my StockPhotos.xcassets at runtime to count all the files in the directory, I won't have to manually load the files each time I add new stock photos.
If there are other solutions to this problem, I'm open to that but I'm also just very curious how xcassets are handled by the file system- whether they're just reference to a set of files, or actually their own directory. Information on this is sparse.
If there are other solutions to this problem, I'm open to that
The problem is that there is no introspection at runtime into an asset catalog: it isn't a "thing" you can "see" as far as Objective-C and Cocoa Touch are concerned.
The usual solution to this kind of problem is to drag a folder full of images into your project at the outset, and when you do, choose "Create folder references for any added folders" in the dialog - not "Create groups for any added folders". The result is that the folder is copied into your app bundle, and now you can use ordinary file system methods to say "every file in this folder".
Upon compilation of your iOS project, xcassets are compiled to produce either image files, or a proprietary .car file. In that latter case images won't be stored in a directory you can browse.
If your "Deployment Target" is less that iOS7 (meaning that your app would still be able to run on iOS6)
It will produces the same set of image files that you would have had to produce without using Assets Catalog, namely <YourImageName>.png, <YourImageName>#2x.png, <YourImageName>~ipad.png, <YourImageName>~ipad#2x.png and so on, for each image set of your xcassets.
If your "Deployment Target" is iOS7 or greater (meaning that your app would only be able to run on iOS7+)
It will produce a single big .car file in the final bundle (I don't really looked up if this file was actually an sqlite3 datatbase or some proprietary format or whatnot, but who cares, you are not supposed to manipulate it anyway). This big .car file contains all the images, with all their provided variants, and even with slicing info (if you did slice some of them for tiling or to use them as 9-patch images using the tool provided for that in the Assets Catalog editor)
Whatever the produced result you shouldn't / are not supposed to dig into internal details of your bundle like that. The format of the .car file may even change from one iOS version to another (who knows? that's internal details after all which we shouldn't have to deal with) so don't base your logic on it.
[EDIT]: If you need to be sure to have a directory with your set of images at the end of the compilation, you could instead use a folder reference (referencing a real folder in the Finder, as opposed to an Xcode "group" as only group files in Xcode's Project Navigator) then use code to browse it. But then you will have to deal with other details, like only browse files that match the current device (iPhone vs. iPad, non-retina vs. retina…), so this would only shift the problem further in your case; you really should use a constant somewhere to declare the number of images (or put this in some PLIST file for example) and iterate thru them.
As the files you provide at compile time will be in your Bundle — which cannot be altered once compiled as it is digitally signed — the number of images will never changed once the app is compiled anyway. (That's not like if you used the Documents directory and enabled iTunes File Sharing or whatever, letting the user add images himself ;-))
If you're targeting iOS 7+ then no. Xcode will package the files into a proprietary format (.car) that you can't access directly.
Either use imageNamed: methods, or don't use Image Catalogs for the files you need to access directly.
as #AliSoftware suggests you can store all assets images to plist and access them later for more details see here

Some files are located outside of "MyApp" directory in my iOS app - why?

I'm now developing my first iOS app, and I found that two of my classes (hence, four files) are located outside of my MyApp/.
So in my filesystem, here's the current situation:
My App
- ClassA.h
- ClassA.m
- ClassB.h
- ClassB.m
MyApp/
MyApp.xcodeproj/
MyAppTests/
Other than the two classes, all of my class files are located in MyApp subdirectory. The other resources, such as Core Data model file or images are saved in the same directory.
However, why are the two classes, and only the two classes, located in the outside of MyApp subdirectory? When I move those files to the supposedly correct location, those files are no more "valid" in Xcode with the color of the file name is converted to red.
So here's my question:
Why are those two files located there?
Do they have any issues if they remain to be located there?
Should I fix this issue and save it correctly? I think I haven't had any issues so far with the Simulator and the actual iPhone...
I use iOS 7 and Xcode 5.
•Why are those two files located there?
A: When you have created these files or imported from external directory, you may have not taken care of the group/folder these files are getting created/imported into. Hence they are inside the main app folder in the file system.
•Do they have any issues if they remain to be located there?
A: No, this is certainly not an issue in the correct functioning of your app, but it is always good to manage your files under groups/folders for better file structure and it is easier to find files when they become large in number.
•Should I fix this issue and save it correctly? I think I haven't had any issues so far with the Simulator and the actual iPhone...
A : This depends on you. If you like to keep your files in folders and like everythin arranged in some pattern, then yes you can divide the app into different folders. When you move the files in a folder, the reference of those in XCODE should change as well, and thats why you see those files in red in XCode. No worries. Just delete the files and add them again. Make sure you uncheck the option "Copy files under detsination group's folder".
Now, you may seem the option of creating New Groups inside XCode. But it is good to be aware that these groups do not create separate folders inside file system. These are just for Xcode refernce. So, a neat way is to create folders outside of XCode, and then import these folders(can be empty) in Xcode. Now when you add any file in these imported folders, even from XCode, it will go inside the correct folder in file system.
I am sorry I am not on my MAC right now, so cannot paste actual images, showing how to do it. Feel free to comment, if I have instead of solving the issue, have rather confused you more:D
You can put your source files wherever you want, as long as Xcode knows where to find them. You can leave them here, or organize it in another way, as you seem to be willing to do.
So, if you want to move these files in your Myapp/ subfolder, just move them there, and when Xcode complains it can't find them, highlight all those files in red in the navigator, and in the "File inspector" pane (right hand side of the window), click on the little Folder icon to browse to the new location. If you selected all files you don't need to do that 4 times, Xcode will find it out by itself.

xcode (ios/objective c) access Supporting files

Please keep in mind this is my first ios app and first experience with xcode. I have researched this but i believe my inexperience is a key factor in not being able to find it.
I am creating an app for iPhone in xcode and need help locating a file. I am currently storing an xml file in the Supporting Files of xcode. I have searched through the directories using NSDirectory trying to locate it with no success.
Any help would be appreciated.
Resources, such as an XML file, are copied into the app bundle during the build phase. You can see the list of copied files by navigating to your Project Settings, then the Build Phases tab and then expanding the Copy Bundle Resources build phase.
To find resources that are copied into the bundle you can use NSBundle to get the path to the file:
[[NSBundle mainBundle] pathForResource:#"myFile" ofType:#"xml"];
You can then use that path to load the XML file into a an NSData or NSString object before parsing it.
The directory structure inside an iOS app is largely flat, since most files are simply copied into the bundle ignoring the group structure that represents them in Xcode. It is possible to add folder references to Xcode that will be copied to the bundle verbatim, preserving their directory structure within the bundle, (look up the differences between Groups and Folder References in Xcode for more information).

Resources