Resource files not updating with Xcode 5 - ios

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

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)

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.

well a simpler way would be to just touch the folder from your shell or term.
e.g. on your terminal just run
touch -cm PATH_TO_FOLDER_UNDER_RESOURCES
PATH_TO_FOLDER_UNDER_RESOURCES is actual path to the folder under resource folders which contains the files.
Since changing your files do not necessarily change the timestamp of the folder and Xcode looks into the timestamp of the containing folder.

I had the same issue with xcode5, I need to update javascript frequently. I had to clean and then build, it took long time because my project had many source files. Later I tried to delete the app (choose "move to trash" rather than "delete reference") and then build, it was quite fast, but I had to restart xcode so that app can appear in the project again.

Related

When to check "Copy items if needed" for embedded binaries?

When I tried to put a third-party framework(installed by carthage) in the embedded binaries, I got such an option. I got confused, since "Embedded binaries are binary files that are copied to your application bundle when you build the project", It is already a copy instead of a link, why do I want a copy of a copy?
"Copy items if needed" has nothing to do with the building of your app. It means copied into the project folder, right now (if it isn't in the project folder already). I suggest you always say yes, because otherwise your project might end up depending upon stuff that isn't in the project folder, and which you might therefore throw away or rename by accident, thus causing your project to break.
Like matt has said, I recommend you always leave it selected as well. I have had troubles uploading the app, even though I know I have not moved or renamed the file. Also an extra benefit of leaving it enabled is that it makes it easier to share the project with others without having to track down the files not in the project folder.
I can see two cases why leaving it off might be convenient:
You have multiple projects which share the same file and want to reduce space,
You desperately need to save the space on your computer, in which case I would buy extra storage for your computer.
Edit: Even though you copied the file in, XCode treats it as a link to the file, this is why you are seeing this message.
Xcode Copy items if needed
Copy items if needed usually (but not always, e.g. the project already contains this item) copies files into your project directory as a result you can use relative path(instead of absolute) safely. For example when you use some version control(Git, SVN...) your team members will not have some troubles with solving issues with paths
In case of third-party framework you can use $(PROJECT_DIR) in Build Settings -> Framework Search Paths
*Also do not forget additionally set dependency if not dyld: Library not loaded[About]
[Create groups vs Create folder reference]

Is there any better way to rename an XCode project than the given one?

The given version is described here: How do I rename a project in Xcode 5?
But, as you can see from the following screenshot^, not everything gets renamed, and if one opens package contents, directory names etc. to try to manually change all the references, the project is broken afterwards, so you have to keep the old project name for sub directories etc., which granted is not a massive problem, but is intensely irritating, and I'm not enjoying being intensely irritated at work.
^ apologies for a screenshot, but there's too much information in it to transcribe to written text. Top two-thirds of screenshot is XCode project, bottom third a Finder window.
Renaming projects in xcode in one of the most annoying things in iOS development. I assume you want to rename your app. I faced this problem once and figured out a simple, clean way to do it.
Go back to the point where everything worked.
Open project in xcode and click on the project icon in the project structure( first file)
Go to the info tab
Search for Bundle Name. Most probably it will automatically be set to $(PRODUCT_NAME) which is a shell variable that will set your app name the same as the project name.
Set it to whatever you want your app name to be
Done
Notes :
If you use custom URL Schemes this might produce an error when redirecting.
ALWAYS git or some other SVN in your projects. This will come in handy in this kind of situations

Xcode keep using old framework version

From the beginning of my project, I use a custom framework, let's call it "custom.framework". But there was a bug in this framework and now I want to use another version of the "custom.framework".
At first, I simply removed the "custom.framework" file from my project and added the new one. But nothing changed, the bug was still there.
After multiple tries and hours, I understood that Xcode add the old version in memory and used this one instead of the new version. I know it because in the new version I added a method and when I cmd+click the class I've add the method into, it's not there and the file's path is unavailable.
Searching through the web, I tried to change some version parameters to my framework projects: Compatibility version, Curent Library version, Framework version. But this didn't change anything to Xcode which keeps using the old version.
I also tried to make the framework's project as a sub-project and add resulting framework as a dependency to my target. It worked well, but as the framework's project is on a separated remote git repository, I don't think this is an acceptable solution.
So my last try was to build a "custom2.framework", to force Xcode to use the real file and not some cached version. But again, it doesn't work and when building I get errors telling me that all my classes in custom2.framework are duplicated symbols of its cached version of "custom.framework".
So my question is simple: how can I finally tell Xcode to deleted its cached old version and let me use the file I gave him? I already tried to delete my project's derivedData but it seems cached frameworks aren't there.... I'm so desperate :(
Edit: Here are 2 screenshots to illustrate the issue
First screenshot is the path as shown by Xcode when I opened the file from the .framework object in the project navigator.
Second screenshot is the path as shown by Xcode when I opened the file from a cmd+click to a "DCEquipmentManager" in code.
As you can see, the framework linked with the code is not the framework in the project.
it seems problem with binding in new framework, your project still linked with old framework files.
try to remove all files and folder related to your "custom.framework and also remove path for that framework from project setting--> build setting --> search Path
Then after Drag and Drop Your "custom.framework" files in project.
it works for me.hope it resolve your problem.
Please try to clear derrived data:
Window -> Organizer
at the right side you will see projects list. Find your project and tap on it. I the top part of window you will see button delete in front of Derrived data, tap on it.
I guess it will solve your problem.
It might sound silly, but sometimes restarting XCode or the whole machine fix things.
Did you remove the old framework from Build Phases --> Link Binary With Libraries?
Use Clean Build Folder: option-shift-command-K, or select it from the Product menu when holding down the alt/option key.
First lets say something upfront. The build stage is a(are) command line tool(s) that is managed by Xcode according to your Build Settings.
So when Xcode doesn't find your Framework - the Build System will usually also not find it. This forces you to act but may end up in confused Xcode to catch an older reference.
Yes it may happen that the Header Xcode is pointing to is correct but the build system still uses an old copy somewhere. An outdated copy can dangle around literally anywhere depending on the steps you took before.
It (Xcode) assumes where it is located but the Build System still uses another version or the Search Paths just pointing in the wrong Locations even if they are visible to you and even your Framework icons are visible in the lists. So when you erase the last build you actually only force Xcode to rebuild from the known arguments, the settings stay the same, the lists stay the same. Even restarting Xcode does not change anything, the problem persists.
Ergo: Compiler Instructions, Xcode settings and Build System settings don't match what the code tells with #import <NAME/Name.h>
So you will check at least those 6 stages again:
Is your Framework Header File published in your Framework project?
are Build Settings really pointing to the right Framework Search Paths or System Framework Search Paths?
Is your Framework in linking list?
Is your Framework in Embed Framework list?
Does your framework appear in the Framework Group Folder in Workspace/Project Browser? (usually the very last Group Folder in the Browser below all your other files)
Is my Folder Structure correct?
At least 1 to 4 must be right otherwise it will fail.
Here a random list of common causes
Framework is located outside your Source Paths structure
Structure got changed after you added it to the project
You use Workspace's where Framework development and Final Application can appear side by side but you assume Xcode uses this to change its Search Paths
The contained build settings are misleading from former drag and drop operations, ending up tricking Xcode in the "wrong" corner. In this case recreating a project is just one of the possible ways to fix it but not the solution.
Also dragging a Framework into your Project > General or separated in Build Phases > Link Binary list or Embed Framework lists does not make Xcode aware of the wrong Build Settings.
The Linking works, embedding works, but compiling does not. The Header information is still missing.
The solution must be to correct your Build Settings.
As mentioned above Build System and Xcode are two different things. In particular only setting the right Framework Search Paths will solve those issues, even if you managed to kick your derived data manually.
Erasing Derived data?
Derived data is the place where precompiler collects data to compile. So it can be seen as expression of what all the settings are told to do. Erasing it does of course not change the settings but may fix inconsistencies related to former Build Settings. It would erase the derived data and rebuild from the Build System Settings you gave.
Correcting Linking?
Also Linking is not the same as making Xcode aware of the desired Headers. Linking is for your final Product to know where Symbols are to call on them at runtime, it does not change Framework Search Paths and System Framework Search Paths, they stay the same as given.
But it is not wrong to start fixing first with
Product > Clean Build Folder, it forces your build to parse all and compile all again on the next Build.
When the troubles come up because of folder structure in parallel or Frameworks are simply placed outside the Source Directory then you must point to them directly or relative.
Most likely you should place one extra entry in your Framework Search Paths like $(SRCROOT)/../Yourframeworksource/build/Debug. expression to point to relative higher folder structure.
Needless to say that a Release Build likely needs another entry ending in "/Release".Hint: Well you can have different Search Paths for different Compile Schemes..
This works particular good after you cleaned Linking List, Embed Frameworks List and then also check the very last Group Folder "Frameworks" for double entries to drag and drop a fresh Framework reference in there.
How to know if leading /../ will fix it?
Click on the dropped Framework Icon inside the workspace Framework Group Folder (lower most) while your Project is the active selected to work on, now watch for the relative Path information on the very upper right side of Xcode, if there is some /../ you know you need it as well.
Sorting of Framework Search Paths
play a role of course, just the same as #import/#include rule sorting matters.
Remember the first found, first wins rule because often we use #import that works different then #include but ignores second attempts to declare. This leads to once wrongfully declared headers to hide corrected declarations later on in parsing that share the same filename or define rules
#ifndef xyz
#define xyz
// all your code here.
// a second read attempt would be ignored
// a second read is hidden also when you use #include then.
#endif
So you can sort those entries either by code and/or in the build settings if needed because of course it matters what is declared before other declarations depend on it.

XCode Copy Files build phase skips files sometimes

I followed this excellent tutorial to set up to build a framework I'm building for an iOS app.
http://spin.atomicobject.com/2011/12/13/building-a-universal-framework-for-ios/
I have everything working pretty well except for one little detail. Sometimes, it can take several attempts at building the project before all the header files are copied into the final framework.
Occasionally I'll hit "Build" and the Headers folder for the framework is completely empty at the end. Sometimes it will have 90% of the headers, but not all. Once in a while I get lucky and they all seem to be there.
What would cause this and how do I correct it?
Update:
So far my only solution is to just keep rebuilding the framework and eventually it copies all the headers the way I expect it to. Still looking for a better answer though.
One of the workaround I use to get around this problem is dirty (i.e. double-click open file, press spacebar & delete key on keyboard and save/Cmd+s) all the 'add copy files' before I build (Cmd+B).
Another workaround - Build the project twice and on second build, the files get copied.
Anyone have real cause/solution of this issue?

How can I avoid having to clean the project after replacing files?

Xcode 4.5.2, using cocos2d-iphone 1.0.1 for game development.
Recently, I have realized that every time I replace an image file with one of the same name, the project in my device will continue using the old one when I create a CCSprite with such file.
This can be fixed by simply cleaning the project.
However, now the project is rather large, and compiling after cleaning takes quite an annoying amount of time.
Is it possible to replace files and make Xcode use the correct files instead of having to clean the project?
Another simple fix is to give a different name to the new file and delete the old, then change the CCSprite to use the new file name. Of course, this is ridiculous so I'd like to avoid doing it.
I believe that it also happens even when I just delete the app from the device - it seems I do have to clean the project.
Open Organizer in your Xcode. Goto the Projects tab.
you can see Derived data options. Click Delete near to that option, to clean your project

Resources