Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource files not updating with Xcode 5

Tags:

xcode

ios

iphone

I have some binary files with a proprietary extension that don't get updated in a build when I compile. In previous versions of Xcode with this same project, it would detect the file was changed, and rarely would I have to perform a 'Clean' as I have to do with this version. Of course this is consuming a lot more time -- I would appreciate it if someone could let me know what's changed with Xcode 5 and/or what I could do about this.

I didn't include any project specifics because it's really just a proprietary binary file with a custom extension in a resource folder, which, used to update automatically upon it being changed since last compile. If you need any specific project settings I would be glad to offer it.

It's using the sort of 'blue' resource folder that is a reference to the folder it's in, and isn't just copied into the project directory. I apologize since I forget what this particular resource folder type is called (I'm guessing Reference).

Version: Xcode 5 (5A1413)

UPDATE:

This only happens when I'm referencing a file that I modify programmatically with fopen,fwrite,etc, and upon using a file editor in OSX to resave the file (without really changing it) Xcode will then see it as changed.

I'm now looking into FSEvents to see if this underlying API is something I need to use, although I'm not exactly sure how to set flags with this just yet.

UPDATE:

Well, just as a simple test, I take the same file and resave it via:

NSData* data = [[NSData alloc] initWithContentsOfFile: @"/location/file.dat"];
[data writeToFile:@"/location/file.dat" atomically:YES];

Sure enough, after I call that and then run the app that uses the resource, it is updated via Xcode during the build. So it would seem that Xcode 5 relies on some special flags not set by the standard io functions. At this point I can either patch what I've got with that 2 line thing or figure out what the flagging mechanism is, and how to write to it. (FSEvents? I don't see a writing mechanism there..)

like image 722
Kalen Avatar asked Oct 01 '13 19:10

Kalen


2 Answers

I had the same problem. I set up an Xcode build-phase script to touch the root resource folder, and it works now. I found the instructions here and they are as follows (see link for more detail):

1) Add your single resource directory (named anything but ‘Resources’) to your project in the Resources section as a blue ‘Folder Reference’

2) Right click on your app target, select Add->New Build Phase->New Run Script Build Phase

3) In the resulting ‘Info’ window, change the shell to /bin/tcsh and copy and past the script below into the ‘Script’ text view.

Script:

touch -cm ${SRCROOT}/../../YourResourceFolder

(Also, you may need to know how to find "Build Phases" in Xcode 5)

like image 184
Paul Slocum Avatar answered Sep 27 '22 22:09

Paul Slocum


I was also running into problems. Everything was fine before Xcode 5, and my referenced resources folder would copy pretty dependably. However, after updating, no matter what I did to an individual file (touch it, delete and re-copy it, etc.), nothing triggered Xcode to scoop it up again.

However, I now modify the last write time on the referenced folder during my build step, and now it's contents seem to be copying correctly again. I Hope that helps you too.

I am using custom tools, but I'm sure a build script can do the same. My guess is that Xcode tries to optimize the dependency step, and checks the folder's last access/write times before diving into it.

like image 38
worstoo Avatar answered Sep 27 '22 21:09

worstoo