Files removed from Xcode project, but still available in game - objective-c

My cocos2d-iphone project has tiled maps (.tmx files along with .png textures).
Recently, I deleted all the .png textures in my project (in Xcode, you hit the delete key and then choose to send to trash).
Then, I ran the project, and it tried to load up the CCTMXTiledMap. I was expected it to crash (there shouldn't be any textures in the project, anyway), but it didn't. In fact, it ran just fine, and the maps did load. No idea why - is Xcode keeping some kind of reference to such files somehow?
I checked the .tmx file, and this is the line that defines the source image:
<image source="myMap-hd.png" width="973" height="1024"/>
There definitely is no myMap-hd.png nor myMap.png file in my project folder. Not even Xcode's search toolbar shows it!
Oh, and I also cleaned the project.

As I wrote in question's comment. Problem was not in your Xcode project. Deleted resource files will most likely be still available on device/simulator if you had run application with these resources previously. The reason is that Xcode doesn't track files that are in application bundle, they're just simply copied. That's why they land in Copy Bundle Resources build phase.
You should delete application from device/simulator and run it again. Or if you have precious data already in application, you could navigate to application bundle and delete file manually. Files won't appear again.

In the simulator, iOS Simulator (menu item) > Reset Content and Settings. Clean your project, then run again. Same thing happens without cocos2D.

I've found this to be an issue when nib files are automagically loaded, and while not in the referenced files seem to still be loaded (or attempted). Can cause some brain pain bc the files don't appear in the Xcode IDE though they do exist in the file system.

Related

Moving Project file in Xcode Interface Builder

I have somehow managed to get the Xcode project file for "My System" in a different folder from all the other project files. Everything works but is there an easy way to get the files together in one folder (ie. either by moving "My System.xcodeproj" into the lower folder or moving all the other files up with it in the higher folder.
If I made this change, what parameters I would need to change inside Xcode.
I'm using Xcode 11.3.1 on Mojave and Objective-C (no storyboard).
I'm not sure if it is worth moving these or whether I should just leave it.
File and Folder Structure:
The arrangement shown in your screen shot of the Finder is correct: a project folder, containing the project file (xcodeproj) along with a single folder that contains the actual code files. That is the standard. Don't mess with it.
Actually you shouldn't even look at it. Look at your project through Xcode, and let Xcode worry about where the files "really" are. Under no circumstances should you touch any of these files in the Finder or you will risk breaking the project entirely.

XCode copies only changed xib files to the target binary

In my project I have almost 30 xib files located in an en.lproj folder and henced listed as english localization in XCode. When I compile my project, however, these xib files are not copied to the target folder (Resources/en.lproj) unless I modify them. All other resources are always copied, regardless of their change state. Of course all the xib files are in the "Copy Bundle Resources" build phase (along with a lot of other resources like images).
This behavior gives me some trouble, e.g. when I manually remove the .app from the DerivedData folder. The app is rebuilt completely on next build in XCode, only the xibs are all missing until I touch all of them.
How can I solve this problem and make XCode always copy my xib files too?
Seems to have been fixed with one of the latest XCode versions. I just checked with XCode 7.1.1 and the nibs are copied regardless of their change status, if they don't exist in the target folder already.

Moving .lproj file inside Resources

I'm trying to begin localization on a project, and I've already got an English version of Localizable.strings going. I'm now trying to add French to that file, which is creating an fr.lproj folder, as I'd expect. However, it's putting it in my project root, and I'd like it inside my project's Resources directory.
Xcode seems to have no interest in letting me move the file, and if I move it in Finder, it goes red in Xcode as expected, but doesn't let me click to locate the file.
I've tried moving it in Finder, then editing project.pbxproj in a text editor to add Resources/ in front of the only line in there that mentions fr.lproj/Localizable.strings, and that has worked, but after doing that, the project's targets also turned red in Xcode, and building the app doesn't change that fact. Very odd.. any idea what could be going on, or how to get this going?
This can be a real pain. I even had XCode crash on me when trying to correct unwanted file locations. I found that the best way is to create the localized file (be it .strings or .xib) as a copy of the source language version outside of XCode, then drag and drop it into XCode. If you do this then XCode will display it correctly and your targets' Build Phases > Copy Bundle Resources settings will include it with its correct location. I don't know why your targets are displayed in red, perhaps you could look under Copy Bundle Resources in case anything is wrong there, or also select your project and click Validate Settings in case you haven't already done so.
Also, if you have been testing in the simulator beware of how XCode does not clean up the files in your app bundle--you may want to delete the app and run it again to make sure it's working with your new location.

Using a System Plug-in (.saver bundle) inside a Cocoa Application as a Resource

I'm new with Cocoa / Objective-C development and I have a question.
Last week I had to create a SWF based Screensaver for Mac, and as I didn't find a free-compatible solution for Mac OS X Snow Leopard / Lion, I created a .saver bundle with Xcode 4. It creates inside a webview and loads inside the SWF file.
You must place the SWF file inside the Resources folder inside the bundle to make it work with different SWFs.
And now, I'm trying to code a Cocoa Application to do it automatically.
It has a simple user interface so as the user can select a SWF file. Then the code makes a copy of my previously build .saver file (I have the path hardcoded), places inside it a copy of the SWF file, and saves it where the user indicates in a save panel.
And here comes my question. Now I have the path of the .saver file hardcoded, but I need to have it as a Resource inside my app. Would it be possible? How could I use/access it?
Thanks for your help and time!
Your application already has at least one resource, assuming you didn't delete the MainMenu nib. Add your .saver bundle to that build phase. In the app's code, get the URL to the screen-saver bundle the usual way.

data file location on iPad

I've been teaching myself over the last couple of weeks by typing in programs from the iPad books I bought (Backlin's, SAM's, Apps for Dummies, etc.) and YouTube tutorials. Still, there are a couple of things I haven't grasped intuitively. Do you mind helping me out?
I got a program working that saves and retrieves names and phone numbers from pList files. I looked on the Mac's HD and couldn't find the file (Contacts.plist), even though the program was working. I finally discovered it at
~/Library/Application Support/iPhone Simulator
I'm not sure why Finder didn't locate it. My own app needs to load a data file when it starts (questions and answers, for example). Do I write a program to create the Q & A file, (I could modify that phone program to do that) then copy the file into the simulator's virtual directory for my own app? Or do I copy that file into the XCODE Resources folder? Would the data files then travel with the finished executable program?
Sorry to sound so clueless. Thanks for any info. -Rob
If you want to deliver a file with your finished application, you must add it to your Xcode project. It doesn't matter whether you place it under Resources or in another group in Xcode as Xcode will by default copy all non-code files that are in your project into your finished app bundle.
To access this file from your code, you need to retrieve its path:
NSString *fullPathToContactsFile = [[NSBundle mainBundle] pathForResource:#"Contacts" ofType:#"plist"];
Note that unlike on the iOS Simulator, your app bundle on the device is read only, so if you want your app to make changes to the file, you cannot save it in the bundle itself. In that case, your app should copy the file from your bundle to your app's Documents or Library directory on first launch and then open/save it from/to that location.