Unable to change location / path settings after migrating Xcode project - iphone

I've migrated an Xcode project (iOS app) from one mac to another (same Dev Account and Code Signing preferences). Now the build fails and I get errors stating that certain files (MainWindow.xib, MyappViewController.xib and InfoPlist.string) don't exist. I've already read that several people have had this problem before and tried out the answers they got, but nothing seems to work.
As I understand, the problem lies within the path preferences for the NIB files. The error messages give the files' path as Users/Meonmyoldmac/etc - which I should change, because it's an absolute path and therefore doesn't make sense on another computer. But: when I try to open those files under Groups & Files their location is already set to 'Relative to group' and their path is given as Users/Meonmynewmac/etc. - which is exactly how I actually want it to be. (Oddly enough, the file type is listed as 'Default - Unknown' )
I've already tried…
- cleaning the project
- deleting those files from the project and putting them back in again
- restarting Xcode several times
that's possibly important:
- I'm talking about a Universal iOS App, yet only iPhone files are affected; their iPad equivalents work fine
- I changed the app localization to German, so the mentioned files are located in a folder called de.lproj
- I created the project with Xcode 4 on my older Snow Leopard Mac and use Lion/Xcode 4.2 on the new one - does that play any role here?
Thanks in advance, Fruity

If you have absolute paths to some of your files, you'll need to change them to relative paths:
In the Project Navigator, locate the missing files (colored red for not being found) and highlight one of them.
Show the File Inspector
Under Location change Absolute Path to Relative to group or Relative to project,
Then next to the path, there's a little white icon, click it and choose the file's location.

Right-click on the files in Finder, select Get Info. Check that you have permission to read the files.
Edit: Just noticed the error messages refer to the old path, so it can't be a permissions problem.
Groups can have paths set as well. Select the groups and verify that their paths are correct.

In XCode 4, when you have all three panes open, select the file in the left most pane. In the right most pane, select the white document icon at the top, looking for the header "Identity and Type." Under the popup for "location" is the name of the file. To the right of that name is a tiny icon like a window. Click on that, and you can set the location of the file.

I performed the terminal search suggested by Jim yesterday, found some 'source tree: absolute' entries in project.pbxproj and tried to manipulate them, which didn't work - couldn't even open the project in Xcode afterwards - so I called it a day.
Just now I did what I already tried yesterday before posting my question: I deleted the files from the project and copied them back in again. That miraculously eliminated all red warning signs from my project and just gave me a nice green SIGABRT when I tried to run it on the simulator. Cleaned project, restarted Xcode - perfect. Oh, and I checked the targeted device family setting, found that it was set to iPhone and switched it to iPhone/iPad - no idea if that was part of the issue.
I'm not sure if that's really an answer to the problem - but the problem has vanished...
Thanks for your help!

A less-actions solution. You can change manually in the project definition file.
Close xCode
Open .xcodeproj file in a text editor: in fact it's a folder, so edit in a text editor the inside file: project.pbxproj.
Search for the string: absolute (for sourceTree param)
For each entry (file with a absolute path set), change absolute to group.
And change the path parameter to a relative path. example:
path = en.lproj/PilotInfoViewController.xib;
- Save the file and reopen xCode.
PS: Make a backup copy of your project file before doing this manipulation.

Related

XCode buggily loading images that aren't in my project folder

For some reason, XCode is acting up really oddly. I have been testing XCode's ability to load images with the -hd suffix, and realized that Xcode will load a file "welcomeBackground.jpg" regardless of whether it is actually in my project folder.
See, this code below will not crash when compiled. And this is the first screen that is displayed when the app loads. I deleted the file "welcomeBackground.jpg" from my project folder, and XCode still loads the file as if it were there.
This is really freaking me out. Please help?
I am 200% sure I deleted the file from my project folder even and yet Xcode does not crash on line 35.
EDIT: To repeat, things I have tried/checked
- Cleaned project
- Deleted Derived Data
- Checked for hidden files in project folder
- Deleted app from iPhone and re-run from XCode
- Deleted the files from my project folder
- Loaded another image "sadhieia.png" and crashed Xcode
because Xcode couldn't find the file (as it does not
exist), and then tried "welcomeBackground.jpg" again
and Xcode somehow finds it.
And yet, the background still loads...
In Cocos2d, if the specified image is not in your folder, it'll not crash. Instead, it'll return nil to your CCSPrite *background.I suggest you Don't use Camelcase for images. Use lowercases or underscores. Try deleting Derived Data. See this for how to delete derived data.
Scroll the project navigator down to the bottom, to "Products," then click the disclosure arrow to show your application.
Right-click the application and choose "Show in Finder" from the contextual menu that appears. A Finder window is displayed containing your application.
Command-click the title of that window; another contextual menu appears. From that, choose the folder "Derived Data." The Finder then displays a window for that folder.
In this window, you'll see a folder whose name is that of your application, followed by a long string of letters. Trash it. If you see multiple folders bearing your application's name, trash them as well.
Rebuild your project. That should take care of the issue.
This might be a slash and burn approach, but it's solved a lot of quirky project-related issues I've experienced in Xcode after attempting to clean.
Clean your project; your image file is still cached in the build folder.

How to change location of iPhone app icon?

Okay, I am a noob. It must be simple but I stuck here.
I do rigth-click and choose 'select file'.
After I choose the file the dialogue appears:
I want to keep my icons not in the root directory. But I can't figure out how to do this. I tried different ways, even create project from scratch...
Please help.
When you bring image assets into Xcode they will all be in your application bundle's root directory at run time.
It appears that you've added a file named "icon#2x.png" to your project at one time already. Go to the project's summary page in Xcode click Build Phases and then expand the section titled Copy Bundle Resources. There you'll find the reference to the resources that will be copied to your bundle at run time.
More on bundle structures here:
https://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html
Anyway, the way I've done this in the past is to:
Remove the existing image duplicate from Xcode and from the folder structure in Finder.
Add a new folder in Finder call it "/AppIcons" (or whatever).
Copy all the app icons to that folder in Finder.
Drag the "/AppIcon" folder into your XCode project. I typically put images in an "/Images" subdirectory in the Xcode project. Again you can put it wherever you'd like.
In Xcode on the project summary panel, add your app icons from the folder "/AppIcons" by dragging / dropping or by right clicking and adding them as separate files.
Alternatively in the past when I've had problems with this sometimes Xcode will copy the app icons to the root project directory. If that happens, I make sure that I have the "/AppIcons" folder structure on disc (in Finder) and in my Xcode project. I add the app icons to the project, then move them to /AppIcons in Finder, and re-reference them all over again.
Your Copy Bundle Resources should then have the proper file reference. Note that my apps icons go in "/Images/AppIcons"
Good luck!
I would add the image files to your project with the name icon#2x.png. To do this right click where you want to add the files in xcode and click add file/s. Then search for your image and add them using the dialogue that pops up. - there is a check box so that you can either copy them to the projects destination folder which will copy them into you project folder or leave it unchecked (inadvisable) which would reference it's current location on your HDD. Make sure the file doesn't already exist in the project before doing this!
EDIT:
Sorry I forgot to mention then drag and drop the file from within xcode onto the image location box.
In XCode 4 (I'm using 4.6.2) you will get this confusing message if you've just moved the target's info.plist file, but not corrected the location at the top of the summary panel. Fix this and the icons will reappear, assuming they are added to the project, or if not you should now be able to drag them in without xcode insisting on making extra copies.
This tends to happen when you're starting a project and sorting out the mess of default file locations that xcode gives you. I like my project structure to be 99% the same as the file system structure.
This is an easy fix. If the image you want as your App Icon resides outside of the root of your project, when you get that dialog just click "Yes", and then click delete on the newly created file in the root, and "Move to Trash".
The reference is still there and works without a hitch, since the file will still be in the root at runtime

XCode - Indexing failed in one file

This issue is not a major issue but has certainly made the process consume more time. When I build my application, indexing fails in one and only one file (.m file if it matters).
There is not intelligence, no color on global variables and most of the code except for important keywords are black in color. Since there is no intelligence, whenever I need to make changes, I have to see other files for doing the changes.
this happend for me when the file was not included in the target.
Method 1:
- Go to your project (the very first item in the project list) (cmd-1)
- select your target
- open tab Build Phases
- add your .m file in Compile Sources
Method 2:
- select your .m file
- show Utilities Pane (the one on the right side)
- first tab: show the file inspector (cmd-option-1)
- check the target in Target Membership
Here are the steps I follow when I face such a situation :
Clean the project, in Xcode menu Product -> Clean
Close the project
Open Organizer and go to Projects tab, select the project
Remove all derived data (the buttons are on the main view : Derived data and Snapshots)
Remove the project from the list on the left (select it and press backspace)
Finally close Xcode, launch it again and reopen the project
These steps will make Xcode rebuild the index for the whole project.
If indexing fails, try cleaning the product (or entire build folder). If that doesn't help, close Xcode, remove the DerivedData folder (you can find the location in the preferences "Locations" tab), and start Xcode again.
The indexing process will then try to re-index your files.
Hmm. Considering the normal Clean or Delete Derived Data solutions haven't worked, my next steps would be:
Copy the contents of the .m to the clipboard.
Delete the .m from your project (including sending the physical file to Trash)
Delete Derived Data
Try to compile the project (I know it will generate errors most likely, but let it do this).
Create a new .m file and paste the code back in.
Compile and run the project.
Delete Derived Data again to force a reindex.
Close XCode, reopen it.
Now hopefully it should be indexed. If this still doesn't work, try renaming that class (the .h and .m), see if it indexes, then rename it back again.
Try Product > Clean (XCode 4).
This can happen sometimes, it's annoying. If you get desperate, try creating a new project in a different location and copying the source files over.
I found solution to my question. Actually a localized file of that file was being created in en.proj folder, where indexing failed. So, I just copied that file into project main folder and deleted it from en.proj folder. It works fine now. I can see everything indexed.
Search for "GCC_INCREASE_PRECOMPILED_HEADER_SHARING" in your project build settings
Change 'increase sharing for precompiled header' from NO to YES
Hope this helps.
Go to Editor -> Syntax coloring, and change it to objective c. It might do the trick.

How to change Xcode Project name

I have developed my app in Xcode for iPhone, in start I have just named it without secnec now I want to change my app name I have replace my old app name with new one as I have found the name in my app, but its still giving me one error...
Desktop/New name/old name_Prefix.pch: No such file or directory
when I have change oldname_prefix.pch with newname_prefix.pch ..
For Xcode 4 or later:
Open a project
Select Project Navigator
Highlight project name
Single click on project name
For Xcode 3:
Open a project > Menu > Project > Rename ...
There is no need to change the name of the project in order to change the display name of the application (which is what you see on the home screen of the iOS device, in iTunes, etc.). Simply change the "Bundle display name" in your info.plist from the default "${PRODUCT_NAME}" to whatever you want it to be. The name of your project is invisible to users, they only see the "Bundle display name."
click on you project in project explorer and again click on your project on right side and there you can see project name as shown in the figure
On the left side expand Targets
Double click on your target and then select build tab in the newly opened window
on the top right there is a search box. Type - "Product Name"
Now look below, under packaging section, you will see Product Name
Change it and clean rebuild, your new app name should be changed by now.
Goto
youname-Info.plist
Change Both
Bundle name and Bundle display name to your preferred file name.
Done.
For changing application name only (that will display along with app icon) in xcode 4 or later:
Click on your project file icon from Groups & Files panel, choose Target -> Build Settings -> Packaging -> Product Name.
Click on the row, a pop-up will come, type your new app name here.
For changing Project name only (that will display along with project icon) in xcode 4 or later:
Click on your project file icon from Groups & Files panel, choose Project(above targets) from right pane, just see at the far right pane(it will be visible only if you have enabled "Hide or show utilities").Look for project name.Edit it to new name you want to give your project.
Delete your app from simulator/device, clean and run.Changes should reflect.
That's it
ohho's answer is perfect:
For Xcode 4 or later:
Open a project
Select Project Navigator
Highlight project name
Single click on project name
BUT, if you only do this, once you try to debug on a new device, you will find an error:
file not found: /Users/someuser/Library/Developer/Xcode/DerivedData/OLDNAME-akbwbarcniqxytctbebckkelkbxs/Build/Products/Debug-iphonesimulator/OLDNAME.app/OLDNAME
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Then you need to do one more step:
Select target on the left panel
Choose the oldnameTests in Targets
Select the Build Settings Panel
Search for "TEST_HOST" and change the old value to the new.
Good Luck and Have Fun
Here is Apple's step by step visual guide to change name of Xcode project.
To change name of workspace just rename it.
in xcode 4.4, you have to click on the project at the top of the navigator (left panel). Then click twice on the target in the second column to highlight the target name. Then you can change the product name. You will also need to modify the archive name when you go to create an archive. To do this, you must edit the scheme, click on Release, and then change the archive name.
I am using xcode 4.3.1 and tried to change product name as Quakeboy said above in the bundle setting, but it led to reading error. I was stuck in this error for an hour and now it is working well. I simply made the product name blank then retype the older name that I had before. building succeeded again!
Note to anyone who like to change project name : you don't have to change the project file name the bundle display name will be display to users so just don't hang out with this issue too much. can be wasting time.
It creates an organizational nightmare to have project names that don't match the bundled name. But when I use the "click on project name and answer yes to let xcode rename all of the references" technique, all of the nested folders for the project on my hard drive still have the old project name. Why aren't they renamed to match?
If I change those folder names, I'm pretty sure it will mess up all of the project links. I am not going to take the chance, unless someone can suggest a way around this.
Select the project in the Project Navigator (Command+1) and open the File Inspector in the right sidebar (Command+option+1).
There, change the Project Name.
Xcode 3.2.5:
In top menu bar, Project>Rename...
I tried by changing the Project name in Project Navigator, but you need to follow through with the all the step outlined here!!!.
I did not follow the second step and this broke my app, had to rework a older version which took two days, see my SO post here.
I tried ohho's answer and it didn't work but found another solution. You can open your Info.plist file and go where it says' "Bundle Name" and change to your new name that will be shown in your launcher. I hope this wrks
Simple step
1.Select the project target left side on top of all folders and files
2.Single click on the project again it will allow you to change the name
3.type as u want the name of the project and the name of the app
4.Press enter. it will ask to change every where accept it
5.same procedure do on the folder as well all place the name will be changed. i did it today
Just in case this helps someone, I have a shell script (xcmv.sh) with the following:
#!/usr/bin/env bash
mv $1 $2
mv $1.xcodeproj $2.xcodeproj
mv $1.xcworkspace $2.xcworkspace
LC_ALL=C find ./ -type f -not -path "./.git*" -exec sed -i '' "s/${1}/${2}/g" {} +
I then drag this file into the project directory and do:
sh xcmv.sh Starter MyProject
This changes the project name, the workspace name, plus any and all references to the old name in the project files, code files, plist, and so on.
As the sample indicates, I often use it to rename one of my various "starter" projects to the desired project name.
Note the git directory (if it exists) is ignored.
This video shows a developer renaming an Xcode 6 project. First single-click the project name to change it, then make sure to also set the host application for your test build target.
https://www.youtube.com/watch?v=ZHr1vjkTxC0

Localization of the iPhone Settings.bundle

For some reason I cannot get the Settings.bundle to recognize my additional languages. I must be missing something obvious, but I just cannot figure it out. Here's what I've got:
Project Structure in XCode:
Root.plist file:
Root.plist file http://img227.imageshack.us/img227/571/screenshot20100624at334.png
French Root.strings file
french Root.strings file http://img121.imageshack.us/img121/571/screenshot20100624at334.png
From everything I've read, I believe the project structure is right. The StringsTable in the Root.plist matches the name of the individual .strings files, and the Key for each item in the Root.plist has a match in the .strings files as well.
Why don't I see French text in my settings when I change the default iPhone language?
Thanks in advance!
For me, the problem was leaving off a semi-colon!
In localizable.strings, you get a runtime error if you omit the ";", but in Root.strings, you don't get any warnings, you can run it fine, but it just won't work!
So double-check to make sure you punctuate each key:value pair with a semi-colon!
I'll go ahead and answer my own question since I solved the problem myself through testing and failing. Hopefully this will help someone else in the future.
First, I think my Root.plist file may have been corrupted. I'm not exactly sure why, but I completely deleted the Settings.bundle, and re-created it to be sure.
Second, and perhaps most importantly, the main issue was the "key" in the root.strings file didn't match to the "key" field in the Root.plist, it actually matches the "Title" field.
Once I made those changes to the Root.strings file, it all started to work.
All you have to do is keep (or Add, if it's not there) "Strings Filename" in the Root.plist, after your settings.
Then, add Value "Root" (or, the name of your file and the translations) to make the created lang.lproj translations functional.
In my case, it appeared as if "Strings Filename" was set to "Root" in the Property List View of Root.plist, but when viewed the file in Source Code View, it was actually "StringsTable" pointing to "Root". The solution is to add another entry where "Strings Filename" points to "Root". (I also tried deleting the previous entry, but then it stops working, so you need both.)
In Xcode 5 there is still no obvious way to localize the Settings.bundle.
The problem
Xcode doesn't allow you to localize a file that is only shown because it is a file inside a folder that's directly shown in Xcode (hence the blue folder icons in the tree).
The Solution:
right-click the Root.strings file and select "Show in Finder"
List item
move the Root.strings file one folder up, so that the en.lproj folder is empty and the
Cmd-Drag the Root.strings file is next to the Root.plist.
delete the now empty en.lproj
go back to Xcode, notice that the tree will reflect the changes you now made
cmd-drag the file in the tree outside to outside the settings-bundle, so that it appears next to your source-code.
Do not copy the file
a dialog will appear asking you what to do with the file.
DO NOT select the checkbox to copy the file (you need this to be a reference)
DO NOT select a target to include the strings-file (the settings.bundle is already assigned to the correct target)
in the file inspector you can now choose to localize the file and to add languages to the localizations. The files will be placed correctly inside the settings.bundle and the tree will automatically reflect these changes, too.
After some repeated tries to activate localization,following steps worked for me:
Close xcode
Drag and duplicate the settings bundle onto the desktop (or wherever)
Open bundle contents
Drag Root.strings into
the en.lproj folder
Duplicate the en.lproj folder and rename to
whatever language you want (using 2-letter code ie fr.lproj)
Replace the original settings bundle with the new one(without
opening xcode).
Now Open xcode and the new files and folders
should be there
Now delete the older app and run xcode,Works fine in simulator and on device.
NOTE:Closing xcode,updating of duplicated setting bundle outside xcode and replacing updated back only will help.