Blankman
Blankman

Reputation: 267180

Best xcode project type to practise objective-c?

Is there a simple console type project where I can hack objective-c and test things out, and simply output to a console?

I want to practise things like class defining, instances, looping, arrays, dictionaries etc.

Upvotes: 4

Views: 2289

Answers (3)

gavinb
gavinb

Reputation: 20048

Sure. From the New Project dialog, choose Application under the Mac OS X heading, then Command Line Tool. A drop-down selection will allow you to choose a particular type of project, which defaults to C++ stdc++. Simply change this to Foundation and you will have a template ready to start exploring all the non-Cocoa (UI) frameworks.

From here you can create instances of NSString, NSDictionary, NSArray, NSDate, and many other useful non-GUI classes. See the full list here:

Upvotes: 5

D.C.
D.C.

Reputation: 15588

Yes

In Xcode, under New Project, choose Application --> Command Line Tool

This will let you play with objective-C classes and output to console, without the clutter of a full blown cocoa GUI application.

Upvotes: 0

user557219
user557219

Reputation:

If you require Xcode, File -> New Project… -> Mac OS X/Application -> Command Line Tool/Foundation.

If you’d like not to use Xcode, this is what I do: use favourite text editor and type

#import <Foundation/Foundation.h>

int main() {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // whatever code you want to test
    NSLog(@"hello, world!");

    [pool release];
    return 0;
}

compile on a shell (e.g. using Terminal.app) with

clang yourSourceFileName.m -o executableName -framework Foundation

or

gcc yourSourceFileName.m -o executableName -framework Foundation

and then run

./executableName

Upvotes: 10

Related Questions