Welcome to Colour Me Cocoa.
Looks like you're new here. If you like what you see, you may want to subscribe to my RSS feed, or if you prefer sign up to receive email updates.
Thanks for visiting!
Doesn’t it just annoy you that every time you create a new file in Xcode you have to change the company name? I don’t work for __MyCompanyName__, do you? Today I got sick of replacing that block of text and went in search of a solution.
The answer can be found in the Xcode 2.4 Expert Preferences Notes. PBXCustomTemplateMacroDefinitions is a dictionary that allows you to setup macros for use in the default templates. ORGANIZATIONNAME is the macro that defaults to __MyCompanyName__ and we can set that using the terminal.
Open up the terminal (found in Applications/Utilities/) and run the following command to set ORGANIZATIONNAME to whatever is appropriate for you. I’ve used my name. Please note, you should run this all on one line, I’ve only added line breaks to make it fit nicely on the page.
defaults write com.apple.xcode
PBXCustomTemplateMacroDefinitions
'{ ORGANIZATIONNAME = "Gareth Townsend"; }'
Now whenever Xcode creates a new file my name will be placed in the automatic copyright comments. Hooray!
There are a lot of other expert preferences listing in the documentation, so have a look through it and see if there’s something else of interest to you. If you do find something interesting then be sure to let us know in the comments.
Posted in Development Tools | 2 Comments »
I just found out about this operator while working through Brian Christensen’s excellent Write a Screen Saver tutorial.
radius = rect.size.width <= rect.size.height ?
rect.size.width / 2 : rect.size.height / 2;
Weird looking isn’t it? Here’s the simplified version:
(CONDITION) ? EXPRESSION1 : EXPRESSION2;
How Does It Work?
If the CONDITION statement evaluates to true then EXPRESSION1 is run, if the CONDITION statement evaluates to false then EXPRESSION2 is run. You can think of it as a compressed if-else statement.
How Has Brian Used It?
Brian has used the question mark operator to assign a value to radius based on the evaluation of rect.size.width <= rect.size.height.
radius = CONDITION ?
EXPRESSION1 : EXPRESSION2;
We could re-write Brian’s code with an if-else statement.
if (rect.size.width <= rect.size.height)
{
radius = rect.size.width / 2;
}
else
{
radius = rect.size.height / 2;
}
It does the same thing, but uses more lines of code. Whether it is easier to read or not is a matter of personal opinion, but knowing about its existence can only be a good thing.
You never know when you will have to maintain someone else’s code.
Posted in C Programming, Code Samples | 6 Comments »
Today I’m going to take you on a journey through building your first cocoa application. We’re going to start by defining a simple problem, then build a user interface and through the wonders of cocoa bindings connect it all up to a controller object.
I am going to use the challenge from Chapter 4 of Cocoa Programming For Mac OS X
by Aaron Hillegass as our problem. The solution requires the user to be able to enter a string into a text field, press a button, and have the application display another string indicating the length of the original string.
For example if I type in “Colour Me Cocoa rules!” and click the button the application will respond with
“Colour Me Cocoa Rules!” is 22 characters long
Sounds simple enough… So if you have just under an hour or so to spare then follow me!
Read the rest of this entry »
Posted in Objective-C Programming, Code Samples, Cocoa | 10 Comments »
Apple have just updated the ADC section of iTunes with a whole lot more developer love. log in and treat yourself to a total of 16 Leopard Sessions From WWDC 06 along with 18 Scientific Poster Session Podcasts.
If you’re not an ADC member then sign up now, the free online membership is all that is required to access the iTunes section.
Posted in News, Resources | No Comments »
Iron Coder V has been announced and will be running from March 30th to April 1st.
What is Iron Coder?
Straight from the horse’s mouth…
The #macsb Iron Coder contest gives Mac programmers an API, a theme, and 48 hours to make something cool.
That sounds very cool. If you’re not a complete beginner you might want to consider putting aside a weekend to work on something different. Even if you don’t create a working solution to the problem you will definitely learn something more about an API.
If you are a complete beginner you might want to pay attention anyway to see what kind of applications are born from the Iron Coder event. There’s nothing like a set of constraints and a deadline to bring out the creativity monsters.
House Keeping
As an aside, for those of you wondering, the next tutorial should be up by Friday. We’re going to build our first cocoa application, hooray!
Posted in News, House Keeping | No Comments »