- xib --> xml
- nib --> binary
Sunday, February 01, 2009
nib vs xib
Sunday, January 11, 2009
IBOutlet / IBAction Definition
One of the most important concepts of Cocoa (at least to get us started) is the way that Cocoa combines UI and code.
In a Visual Studio project the code that generates the UI is in the same file as the coding itself.
To get it connected we need to let the code know what interfaces we have and let the UI know what we are working with. We will do this by defining Outlets and Actions in our code, creating an “interface object” in the UI that will be the interface between code and UI and connect the UI elements to that interface.
So what are Outlets and Actions?
- linking the button to an action of an “interface object”
- calling the method of that action in the code
So let’s get started:
First of all we will define the outlets. We will only need to call the window to close it, so we only need an outlet IBOutlet NSWindow *myWindow; The strange thing for me was that we have two definitions for myWindow (IBOutlet and NSWindow)..... but I guess you get used to anything, and that is just the way it goes.
Further we need an action for the time the button gets pressed on the UI.
-(IBAction)closeWindow:(id)sender;
Once we saved the file we can switch to the UI in the Interface Builder. Here we add a NSObject whichs Identity we will set to the class in which we added our outlets and actions. Then we create the UI by opening the Window object and dragging a button from the library (Command Shift L) to our window. Now we will set the link from the button to the action. To get this done we need to right click on the button and drag it on the newly created NSObject item. A new popup will appear listing all available actions. You should select the one that you have created.
Switch to Xcode and go to the source file to create the method that you want to add. Between the @implementation and the @end enter the method:
-(IBAction)closeWindow:(id)sender{[myWindow orderOut:sender];}
This way you can also get/set the text of text fields ([textField stringValue]), enable/disable buttons([myButton setEnabled:YES/NO]) or whatever you want.
Saturday, November 22, 2008
Objective-C
@interface AppController : NSObject {
int x;
}
@end
Now this class definition would not do to much as it does not have any methods, but it would define a class named "AppController" being derived from NSObject with one integer variable called x.
The definition always starts with "@interface" and ends with "@end"
A method definition in Objective-C will be defined like this:
- (int) setX:(int)y;
This defines a method setX with a return value of type int. To call the method you'll need to pass a variable of type int which can be accessed by the name y. The "-" in front of the method declaration is not a typo, but tells you that this is a "regular" instance method. A global class method would be defined with a "+" instead (comparable with the "static" keyword of Java/C#). The method definition will not be inserted into the curly brackets but between their end and the "@end" so the new class definition would look like this:
@interface AppController : NSObject {
int x;
}
- (int) setX:(int)y;
@end
The source file
To finish off our example here we'll have a quick look at the corresponding source file:
#import "AppController.h"
@implementation AppController
-(int) setX:(int)y
{
//Magic happens here.....
x=y;
return x;
}
@end
This should not be to much of a suprise now. Pretty much straight forward besides the "@implementation" and "@end" commands which simply wrap up the class related coding.
Sunday, November 02, 2008
Details on versioning
- Create a project in Xcode somewhere on your disk (you'll delete it later anyways....)
- Click on SCM in the Xcode menu, and then Repositories
- After selecting your Repository (mine is called Local Subversion), select the folder/branch where you want the project to be stored at
- Select Import in the toolbar
- Select the folder where the previously created project is located at and hit Import
- Xcode will tell you that the project got imported
- Now close the project and delete it
- Again go to the Repositores (step 2)
- Now click Checkout in the toolbar (don't click export like I did the first time... this will lead to a non-versioned copy of the project)
- Select the folder where you want the project to be stored at. This will be the working copy of the sources that you will work on.
- Hit Checkout
- Now you should have a copy on your desk. Next step is tell the project that it is a versioned project. Go to the project settings. On the very bottom of the properties page (in the General tab) you can now select the SCM repository. Select the repository that you would like to use.
- If you want to you can change the build output to some other directory.
- Afterwards you will see that the project file was modified as there is a capital "M" next to the project file (as long as you have selected the SCM preference by right clicking on the file listing)
- Now you can commit those changes back to the repository by clicking on "Commit Entire Project" in the SCM menu.
- That's it :-)
Sunday, October 12, 2008
First things first.... versioning
Finally a blog......
Quo vadis?