How to set target settings for different builds - objective-c

In xcode 4.5 how do I select different target settings for different builds for example one target setting for debug, one target setting for release etc, so I can define different icons depending on the build etc.

You have two options, neither perfect. I'm going to focus on the concrete example of using different icons depending on your build configuration, as you suggest, though both techniques can be applied more broadly.
Redirect in your Info.plist
This is the simplest way. Specify your "Icon file" property in your target's Info.plist as e.g. "Icon-${CONFIGURATION}". Then, create two ICNS icons, "Icon-Release.icns" and "Icon-Debug.icns", and add them to your project. That's it. The downside with this approach is that both icons will be copied into your built app every time, rather than just the one it needs.
Use a "Run Script" build phase
This is a little more involved but it gives you a better result. Add a Run Script build phase to your target, with the following script:
cp "$(dirname "${PRODUCT_SETTINGS_PATH}")/Icon-${CONFIGURATION}.icns" "${SCRIPT_OUTPUT_FILE_0}"
Specify its output file as:
$(TARGET_BUILD_DIR)/$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/Icon.icns
And make sure your "Icon file" property in your Info.plist is set to just "Icon".
This relies on your icons sitting in the same folder as your Info.plist within your source tree (though you can edit the script however you like to suit your project's configuration).
Note also that with this approach Xcode won't be able to see that you have the icon set correctly, so for example in the "Summary" tab of your target's settings it'll still show the question mark placeholder for the icon. You'll need to do an actual build to verify it's working.

My solution is pretty close from Wade's first point, you can also add an dynamic suffix using a user-defined settings in you project configuration.
I use this solution to dynamize the icon, the bundle display name and also the bundle identifier of my build to be able to use the version from the app store beside my development version.

Related

JavaFX exe wont run

I have recently finished building a mini-app using IntelliJ IDEA in javaFx. It is my first time using this ide and language, so I am having difficulties manufacturing an exe file. I watched all sorts of youtube videos and different methods.
It does generate an exe file but when I click it, nothing happens.
Any idea?
I do know that with IntelliJ Ultimate edition you can build down with an EXE file.
There are a couple things you need to double check.
First, is that in your project structure under artifacts, you have the "Type:" set to JavaFx Application(which is on the top right of the window).
Secondly, switch to the Java FX tab and make sure Application class is set to your main class.
Thirdly, Select "all" under Native bundle: which is located towards the bottom of the window.
Lastly, Select the Output Layout tab and move all your available elements to output root then click on the module of your application and look at the settings that appear at the bottom. "Make sure that main class setting is in fact the main class to your application.
Side note: make sure you delete your artifacts build folder just to start from a clean slate. Also make sure your Environment variables are set to the system path correctly.

Making localization work

I have an app that needs to be localized.
After fiddling with the settings for a while, I managed to get the project to the state where it builds a nl.lproj (amongst others) directory in the Resources directory of the app bundle, which contains a MainMenu.strings file that contains all my translations; they seem correct at first glance.
The XIB file is marked as translatable, and seems to be part of the right target:
However, if I run the app in a dutch environment, the localized strings are not shown in the UI. I added
NSLocale *loc = [NSLocale autoupdatingCurrentLocale];
NSString *lang = [loc languageCode];
NSLog(#"Current language: %#",lang);
to verify that the Dutch language is active, and it is.
This question suggests that doing a clean followed by a rebuild of the app should fix such issues. I've tried that, but it did not resolve the issue.
How can I figure out why my app isn't being translated? What else could go wrong? Are there any diagnostics I could be checking?
The application in question is open source, and can be found at https://github.com/Fedict/eid-mw. Select the "eID Viewer" target, and build that, to see what's happening.
There are two different things with the localization. One is localization the UI. This is done by checking those boxes and then editing the string files in the dialog underneath the xib file.
The second is the localization of the Userfacing strings in code. This is done by the Macro NSLocalizedString(#"*key*", *comment*); where key is the key and comment is a provided comment for localization purpose.
These strings are the to edit in the File Localizable.strings.
Here a link with a Beginner Tutorial. And the Apple Docs
To activate the debug function in Xcode for localized strings: pass in -NSShowNonLocalizedStrings YES as launch argument in Xcode. You find it under Product/Scheme/Edit Scheme -Arguments
Hope this helps
You need called .strings file with name "Localizable.strings".
And add language target ( in inspector ) and fill target language file.
Have you tried a check with pseudolocalozations?
Are you setting properly the language and region on your mac?
Are you also trying launching it specifically in Dutch from XCode:
To launch your app in a specific language and region
Click the target in the Run destination menu and choose Edit Scheme.
On the right, select Options.
Optionally, choose a language from the Application Language pop-up menu.
Optionally, choose a region from the Application Region pop-up menu.
Click the Close button.
Click Run to launch your app in the language and region you specified.
It turns out that localisation is supported with OSX 10.8 and above. My app had selected 10.7 as deployment target (we do need to support a few older versions of OSX). Switching the deployment target to 10.8 makes the translations appear.

Add a custom command (with a custom icon)

Is it possible in IntelliJ/WebStorm to add a custom icon somewhere in a toolbar that runs a custom command, e.g. CLI?
If yes, is it also possible to add this in the projects .idea so that my team members also have this icon without any configuration?
My goal is to add some custom Git commands.
I'm not sure about icons (never used them myself) .. but as far as I'm aware this would not be easily to copy it over (custom toolbar actions) as it would be an IDE-wide setting which you cannot copy as separate file (it will be a part of actual IDE customisation config -- hence uniqueness for each user). Therefore tool buttons are rather user-specific and not recommended way if you want to share this stuff or update it in a future with not much hassle (at very least to have such possibility).
Instead you could just use External Tools functionality for executing your custom CLI commands -- this will also be an IDE-wide setting but each group is stored in separate file.. so others will have to copy such file into IDE config folder. Each such tool can then be accesses via context menus (it has 4 places where such commands can be placed: Tools menu and 3 context menus).
Another alternative (that could be shared as part of the actual project) is to code all your custom CLI commands as Gulp/Grunt/NPM script tasks and execute them that way. Since such files are usually placed in project root (or subfolder) .. they can be easily shared via VCS.
All tasks/scripts are loaded from actual task definition files (package.json/gulpfile.js/etc) .. so they are not stored inside .idea subfolder. But you can create Run/Debug Configurations (to quickly run specific task with possible custom parameters etc) .. and such stuff is placed inside .idea (make sure to mark them as "Shared" .. otherwise they will be stored inside user-specific and not-VCS-shareable workspace.xml file rather than individual files).

Why does dragging an objective-C header or code file from one folder to another make it turn red in Xcode 4.6?

I have an Xcode 4 objective-C project which contains about 150 .m and .h files in it.
The code underlying the project does not always correspond in underlying disk structure to the folders shown in the Xcode project. I get that part.
What I don't get is why Xcode won't tell me anything about why I can create new project groups and move items to them, with no problems, but certain existing project folders will cause the project to become broken, and the code will no longer build once I move certain .m files or .h files into a different group. When its broken it just shows the file in red. This is frustrating and confusing.
In the screenshot below, the left side of image before shows state before, when all is good, right side shows red (missing) file after moving into a group. Given that groups don't represent a folder on disk, I would not expect moving from one group to another to break things. Sometimes it does, and sometimes it does not. This particular XCode issue upsets me a lot.
In the good old days of Friendly Mac User-Interfaces, you could hit ⌘+I and get some information about the properties of objects, or right click and get to the properties of something via its context menu. Groups (folder icons) in XCode projects have no properties item in their context (right click menu) and yet these groups all clearly NOT all alike. What's up with these identical looking groups?
Secondly, how does a person learn how to reorganize both the on-disk-folder-organization and the visual group organization, in a way that does not leave you bloodied and beaten? (XCode 4 is the most difficult IDE version I have ever used, for this, I'm sure I've missed some important documentation on dealing with folders and files and so on.)
Update: The File Inspector (Identity Inspector in Utilities menu) is the key to this mystery, but exactly how a new user is to discover this (other than by painful experience) is still unknown to me. I also don't really understand what all this is about, with various choices available in the Path drop-down, and the blank or non blank value that has no description or help, just a cryptic icon and either a name of some real on-disk-folder or else a gray text field saying None:
This sort of thing doesn't just happen out of the blue. In this case, what has happened is that a user has opened an .xcodeproj and is unaware of the difference between the various relative or absolute Path options that a Group can be a part of. A Group in XCode is always shown with exactly the same manilla color folder-icon inside your XCode project, no matter what modes or properties it has defined inside of it.
By default the simplest case is that you create a new folder Group object in XCode and it's purely a cosmetic organizational tool that has no disk location information stored in it.
This is not the ONLY thing that these groups do, and not the only "mode" that these groups can be used in. These groups can also be used to point at some folder and say "things that are in this virtual folder are really somewhere else, either underneath this project's main folder in a subdirectory, or even up somewhere else on your hard-drive, either stored in relative path, or absolute path format". When used like this, these things remind me of a Windows "Shortcut" object on the desktop, or a Mac "Alias" object in the finder.
Dragging a file from one group to another does not move it to a different folder on the disk. It simply moves a reference to a file with a certain name, to another group, which might mean that after you drag a file, you haven't really moved it, or copied, or relocated it in any way, you've just moved an alias from a place where it could resolve properly to a real file, to a place where it can't. Thus XCode helpfully turns it red for you, without any helpful error message about what happened.
How do you fix it? In this case, go to the Identity inspector pane in the Utilities menu, and either decide to clear out the bogus value in the place where I have shown in the picture in the original question where I had "Classes". Clearing out a value that is invalid is not exactly easy to do because XCode requires that you basically find the root folder of your project and select that, and that will 'clear" the relative or absolute path property on your folder-group.
Alternatively, you can leave the folder alone, and just don't drag files from group A to group B without first checking what relative or absolute path they reference.
What still seems horrible to me is that XCode tutorials tell you to "use XCode to manage your project's contents, don't just drag files around in the finder inside an XCode project directory", and that's good advice, but it leads me to assume that XCode provides full and intuitive physical (and virtual) group-folder organization tools. It does not. As an example, imagine you inherit a project that has .m and .h files scattered through four physical folders underneath the main XCode project folder and you want to move those files around. You have to do a combination of tricky things inside XCode, and either in Terminal or in the Finder, in order to reorganize your folder. With the complications involved in moving items around in your version control tool of choice added upon the top of that, and XCode's very limited support for only Git and Subversion, you have a really tricky mess.

libxml/tree.h no such file or directory

I am getting following errors.
libxml/tree.h no such file or directory
I have already added libxml2.dylib to my project, however I am getting this type of trouble.
Please help me.
Follow the directions here, under "Setting up your project file."
Setting up your project file
You need to add libxml2.dylib to your project (don't put it in the Frameworks section). On the Mac,
you'll find it at /usr/lib/libxml2.dylib and for the iPhone, you'll
want the
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/usr/lib/libxml2.dylib
version.
Since libxml2 is a .dylib (not a nice friendly .framework) we still
have one more thing to do. Go to the Project build settings
(Project->Edit Project Settings->Build) and find the "Search Paths".
In "Header Search Paths" add the following path:
$(SDKROOT)/usr/include/libxml2
Also see the OP's answer.
Adding libxml2 in Xcode 4.3 / 5 / 6
Adding libxml2 is a big, fat, finicky pain in the ass. If you're going to do it, do it before you get too far in building your project.
You need to add it in two ways:
1. Target settings
Click on your target (not your project) and select Build Phases.
Click on the reveal triangle titled Link Binary With Libraries. Click on the + to add a library.
Scroll to the bottom of the list and select libxml2.dylib. That adds the libxml2 library to your project.
2. Project settings
Now you have to tell your project where to look for it three more times.
Select the Build Settings tab.
Scroll down to the Linking section.
Under your projects columns double click on the Other Linker Flags row.
Click the + and add -lxml2 to the list.
Still more.
In the same tab, scroll down to the Search Paths section.
Under your projects column in the Framework Search Paths row add /usr/lib/libxml2.dylib.
In the Header Search Paths and the User Header Search Paths row add $(SDKROOT)/usr/include/libxml2.
In those last two cases make sure that path is entered in Debug and Release.
3. Clean
Under the Product Menu select Clean.
Then, if I were you (and lets face it, I probably am) I'd quit Xcode and walk away. When you come back and launch you should be good to go.
For Xcode 6, I had to do the following:
1) add the "libxml2.dylib" library to my project's TARGET (Build Phases -> Link Binary With Libraries)
2) add "$(SDKROOT)/usr/include/libxml2" to the Header Search Paths on the TARGET (Build Settings -> Header Search Paths)
After this, the target should build successfully.
You also need to add /usr/include/libxml2 to your include path.
Form the link of #Matt Ball,
I found following helpful to me.
You need to add libxml2.dylib to your project (don't put it in the Frameworks section). On the Mac, you'll find it at /usr/lib/libxml2.dylib and for the iPhone, you'll want the /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/lib/libxml2.dylib version.
Since libxml2 is a .dylib (not a nice friendly .framework) we still have one more thing to do. Go to the Project build settings (Project->Edit Project Settings->Build) and find the "Search Paths". In "Header Search Paths" add the following path on the Mac:
/usr/include/libxml2
Ray Wenderlich has a blog post about using gdata that solves this problem. Basically these simple steps:
In XCode, click Project\Edit Project Settings and make sure “All Configurations” are checked.
Find the Search Paths\Header Search Paths setting and add /usr/include/libxml2 to the list.
Finally, find the Linking\Other Linker Flags section and add -lxml2 to the list.
original post: read and write xml documents with gdataxml
I found the same, I had to add $(SDKROOT)/usr/include/libxml2 for the latest Xcode (4.3.x). ALSO, what kept me circling around for hours is the fact that I was modifying the "TARGET" and not the "PROJECT" (the new UI of Xcode is so intricate that its easy to overlook this). You need to modify the PROJECT!
Another solution. do all the steps in header search path etc. and make sure your selected configuration in project in Project settings is the correct one. When you double click on project build settings ,you may be changing in Distribution settings, But you are trying to add header search path in "Debug" settings. So make sure you are in correct settings. or choose all settings
I found that with xCode 4.3.2 I had to enter
$(SDKROOT)/usr/include/libxml2
into the Header Search field rather than simply
/usr/include/libxml2
As of Mavericks (OS X 10.9) the /usr/include directory is gone. Half of the answers here are obsolete, as the application will not compile until you sort out the include directory.
I solved the problem creating a symbolic link to MacOSX SDK in terminal, using the following command:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include
The application now compiles again.
I'm not sure what the difference is but add the include path to the project as well as the target.
On Mountain Lion I was facing same issue, which was resolved by adding /usr/include/libxml2 to include paths with flag "recursive", use this if all above is not fruitful.
I had this problem when I reopened a project (which was developed on XCode 3.something on Leopard) after upgrading to Snow Leopard and XCode 3.2. Curious enough, it only affected some kinds of builds (emulator builds went fine, device ones gave me the error). And I have libxml2 at /usr/include, and it indeed contains libxml/tree.h.
Even the magic "Clean" did not work, but "Empty Caches..." under the "XCode" menu (between the Apple logo and File) did the trick (was that menu there in previous versions?). Beats me the reason, but after a clean there were no more complaints regarding libxml/tree.h
Also select "Always Search User Paths" to YES. In XCode 4.3.3 its by default NO
Please follow the following steps
Adding libxml2
libxml2.dylib can be found on your mac machin at /usr/lib/libxml2.dylib
Change "Header Search Paths"
Click on [Project Name] (in left panel) -> Project -> Build Settings -> Select All (default is Basic)
Type Header Search Paths in search box
Double click on Header Search Paths -> + -> "$(SDKROOT)/usr/include/libxml2"
Add -lxml2 to "Other linker flag"
Search for "Other Linker Flags" as search in step 2
click on the "Other Linker Flags" row. Click the "+" and add "-lxml2" to the list.
Change your project type to ARC -> No i.e Automatic Reference Counting to No
You can search ARC as per in step 2
Xcode 4.5
I have used The CW's solution entirely.
The only exception is that $(SDKROOT)/usr/include/libxml2 didn't work for me, and I had to add "$(SDK_DIR)"/usr/include/libxml2 to my Projects Header Search Paths and User Header Search Paths.
After that project builds successfully.
EDIT: I have Google GData project inside my project (called MyProject) (my project uses). GData requires libxml. To build project MyProject successfully, I add "$(SDK_DIR)"/usr/include/libxml2 to Header Search Paths of MyProject and no to Header Search Paths of GData . If I didnt add it to MyProject, project did not build).
I found this visual tutorial useful.
Blockquote
Adding libxml2 in Xcode 4.3.x
Adding libxml2 is a big, fat, finicky pain in the ass. If you're going to do it do it before you get too far in building your project.
Here's how.
Target settings
Click on your target (not your project) and select "Build Phases". Click on the reveal triangle titled "Link Binary With Libraries". Click on the "+" to add a library. Scroll to the bottom of the list and select "libxml2.dylib". That adds the libxml2 library 2 your project… but wait.
Project settings
Now you have to tell your project where to look for it three more times.
Select the "Build Settings tab". Scroll down to the "Linking" section. Under your project's columns double click on the "Other Linker Flags" row. Click the "+" and add "-lxml2" to the list.
Still more.
In the same tab, scroll down to the "Search Paths" section. Under your project's column in the "Framework Search Paths" row add "/usr/lib/libxml2.dylib".
In the "Header Search Paths" AND the "User Header Search Paths" row add "$(SDKROOT)/usr/include/libxml2". In those last two cases make sure that path is entered in Debug AND Release.
Then. Under the "Product" Menu select "Clean".
This is working and for Xcode5 too! Thank you!
Don't put libxml2.dylib under frameworks folder put it under root just below the root(Top left blue icon )
Then Click on the Project (TOP Left blue icon) ,GO to Build Settings,in the search box type "Header Search Paths" and then add the this "$(SDKROOT)/usr/include/libxml2"
This code resolve my issue hope it will help you fix this
#Aqib Mumtaz - I got it working by following the instructions in Parris' note above entitled "Adding libxml2 in Xcode 4.3 / 5 / 6". The step in using a Framework Search Path does not work and the compiler complains. Big kudos to that fella anyway!
I am using Xcode 6.2b3
Regardless of the version of Xcode you are using, it is buggy. Don't always assume that compile errors are real. There are many times when it does not follow header search paths and includes clearly listed are not found. Worse, the errors that result tend to point you in different directions so you waste a lot of time dinking around with distractions. With that said...
Recommend baby steps by starting with this exactly...:
create a single window Mac OS X Cocoa project called "Bench Test"
add XpathQuery into your project source directory directly in the Finder
click on the tiny folder icon under the project window's red close button
drag XpathQuery (folder if you contained it) into the project assets on the left of the project window's display
drag /Applications/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libxml2.2.dylib into your project assets, at the bottom. This will add it into your "Build Phases" -> "Link Binary With Libraries" the easy way
click on the "Bench Test" project icon in the project assets column, top of the left
search for "Other Linker Flags" under "Build Settings"
add "-lxml2" (sans "") to "Other Linker Flags" under the "Bench Test" project icon column
search for "header search" under "Build Settings"
add "$(SDKROOT)/usr/include/libxml2" (sans "") to "Header Search Paths" under the "Bench Test" project icon column
add "$(SDKROOT)/usr/include/libxml2" (sans "") to "User Header Search Paths" under the "Bench Test" project icon column
Notes:
Mine would not work until I added that search path to both "Header Search Paths" and "User Header Search Paths".
To get to the libxml2.2.dylib in the finder, you will need to right click your Xcode icon and select "Show Package Contacts" (editorial: what a hack.. cramming all that garbage into the app)
Be prepared to change the linked libxml2.2.dylib. The one inside Xcode is intentionally used to ensure that Xcode gets something it knows about and in theory was tested. You may want to use the dylib in the system later (read up in this thread)
As I am using Xcode 6.2b3, I may have a newer libxml2.2.dylib. Yours could be named slightly different. Just search the folder for something that starts with "libxml" and ends with ".dylib" and that should be it. There may also be an alias like "libxml2.dylib". Don't use that right away as resolving an alias adds another variable into the Xcode "what could have bugs" equation.
For sanity sake, I make aliases of the external libraries, rename them to indicate which one they are, and keep them at the same level as the project file in the Finder. If they change location, change name, etc, the alias will have in it's Get Info, the original file's full path for later detective work to get the project compiling and linking again. (symlinks break too easy and are not natural to the Mac)
Last thing, and very important, see http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html where you can download XpathQuery and get some more goodness.
hope this helps.
If you happen to be developing something for Veterans, oh say an iPhone / iPad or Mac app, and are working against something called "MDWS" or "VIA" which are SOAP based interfaces to the medical record system... please contact me
I solved in three steps inXcode 8.0 + Unit Test Project
1) I added libxml file to the Build Phases.follow this link
2) I added Other Linker Flags as -ObjC (For both project and test project targets)
3) I setup Header Search Path as "${SDKROOT}/usr/include/libxml2" (Don't forget double quote in either side) (For both project and test project targets)
One of them will solve the issue. If not you have to apply all three of the above.
i tought i added wrongly, then i realize the problem is it not support arc, so check the support one here, life saver -> http://www.michaelbabiy.com/arc-compliant-gdataxml-library/