Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 30, 2007, 05:03 PM   #1
thefil
macrumors newbie
 
Join Date: Jun 2007
Welcome to Xcode 3

As a computer science student, after reading the in-depth analysis of Leopard's retail release, the thing I was most excited about was the prospect of Xcode 3 and working with a unified interface for Mac (as opposed to the Java I've been using till now). Unfortunately, it appears Xcode 3.0 is a dramatic departure from 2.2; having visited multiple tutorial webpages, and Apple's own "Introduction to Xcode" articles given on the splash screen of Xcode 3, I can't manage to find enough that matches up to try anything. In other words, all these old tutorials are seemingly now inapplicable to Xcode 3, especially for someone who has never used the IDE before.

What I'm looking for is the following:
- an introduction to Objective-C 2.0, intended for either new or experienced programs, that includes information on variables, if structures, loops, etcetera. Syntax, basically.
- Using Interface Builder with Xcode 3 and how to interact with the GUI
- Core Animation

Any help would be much appreciated, at least until Apple gets into gear replacing their outdated help files...

*edit* An especially important thing that would help me is Objective-C's print to console command; at least then I could blindly make my way through it :P

Also, could somebody explain to me why classes in Obj-C come in two parts?
thefil is offline   0 Reply With Quote
Old Oct 30, 2007, 06:53 PM   #2
REBELinBLUE
macrumors regular
 
Join Date: Oct 2007
Location: London, UK
I've been reading "Cocoa Programming for Mac OS X" and although Xcode itself isn't much different, Interface Builder is totally different and I keep getting totally stuck.
REBELinBLUE is offline   0 Reply With Quote
Old Oct 30, 2007, 07:05 PM   #3
mduser63
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
Objective-C is a strict superset of C, so you can of course use printf() just like you would in C. However, more commonly you'd use the function NSLog() like so:

NSLog(@"Hello! This is an integer: %i, this is an object: %@", anInteger, anObject);

NSLog() essentially works just like printf (same string format) except that it takes an ObjC string constant (string in quotes with an '@' at the beginning) and you can print arbitrary objects using the %@ placeholder. Objects to be displayed are sent a message calling the "description" method and the return value of this method is what gets inserted in place of the %@". Built in objects generally have a reasonable description method already, and you can (and should) add one to any classes you create in order to make it easy to print information about them using NSLog().

Classes in ObjC come in two parts just because. One is the "interface" or declaration and normally goes in a .h file, the other part is the "implementation" or definition and normally goes in a .m file. That's just how it is.

FWIW, Objective-C 2.0 does not invalidate any Objective-C 1.0 syntax. That is, any Objective-C 1.0 code is valid Objective-C 2.0 code. Objective-C essentially just adds syntactic niceties with the major exception of garbage collection which is probably the biggest new feature. Garbage collection is optional and when turned on will work even for code that is written in strict ObjC 1.0. In this case, release, retain, etc will just be ignored. So in summary, you can start by just learning Objective-C 1.0 as really the changes in Objective-C 2.0 are not that significant, at least not to someone just starting out.

Disclaimer: I haven't actually had the chance to play with Objective-C 2.0 yet as I have to maintain Tiger compatibility in my two current apps, and haven't started on any new, Leopard-only apps yet. So none of this is guaranteed correct, it's just based on what I've read. I am using XCode 3.0 and IB 3, but I'm having to do some feeling around especially in IB 3, because it is quite different from IB 2. So far, I like the changes I see, at least after I figure out how to do things in the new way.
mduser63 is offline   0 Reply With Quote
Old Oct 30, 2007, 09:06 PM   #4
thefil
Thread Starter
macrumors newbie
 
Join Date: Jun 2007
Quote:
Originally Posted by REBELinBLUE View Post
I've been reading "Cocoa Programming for Mac OS X" and although Xcode itself isn't much different, Interface Builder is totally different and I keep getting totally stuck.
Too true, I'm lost in Interface Builder; can't even change a Window title.
thefil is offline   0 Reply With Quote
Old Oct 30, 2007, 09:59 PM   #5
Alloye
macrumors 6502a
 
Join Date: Apr 2007
Location: Rocklin, CA
Quote:
Originally Posted by thefil View Post
Too true, I'm lost in Interface Builder; can't even change a Window title.
HINT: Use the Tools menu to bring up the Inspector (Shift-Command-I), then select the object you wish to modify.
Alloye is offline   0 Reply With Quote
Old Oct 31, 2007, 02:39 AM   #6
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
I like Interface Builder and XCode 3.0, XCode is just nice but Interface Builder is taking some time to get used to, I think its a change for the better though, I'm sure they'll be new books for Xcode 3.0 soon.
__________________
If they have to tell you every day they are fair you can bet they arent, if they tell you they are balanced then you should know they are not - Don't Hurt me
Eraserhead is offline   0 Reply With Quote
Old Oct 31, 2007, 04:05 AM   #7
garethlewis2
macrumors 6502
 
Join Date: Dec 2006
To the OP.

Read either the PDF or HTML version of 'The Objective-C 2 Programming Language.' It's included in the documentation for XCode 3 when you install. They also have the original document for Objective-C if you have not done that.

For IB 3. It is very nice. It isn't difficult to use, but it does have some weird usability issues.

There seems to be two opposing ways of doing the same task and developers seem to be split 50-50. The first is to create a simple class in XCode that will automatically become a descendent of NSObject. The next thing to do is open mainmenu.nib and drag this header into IB 3. From their add an NSObject instance into your interface. Change the custom class to your class, and then use IB to add outlets and actions. From their, write the files into the project, by default IB 3 doesn't seem to know where the project is and you have to physically select it. Next go back into XCode and do your work there. Of course when you save the files into the project IB will complain that they already exist so you need to either merge or replace, in this instance it is safe to replace.

The second way is to create the classes in XCode 3 and add the outlets and actions by hand in XCode 3, then drag the header across, change the custom class of the NSObject to this class and IB 3 automatically loads the outlets.

I just wish from a usability POV that Apple chose one way of doing this. It seems slightly unfinished, as if when they went GM the dev team were still trying to find a way of doing this efficiently.

I suppose it goes with the Next guys mentaility of having to enforce MVC in IB and XCode. It's nice, but when you look at other GUI kits and platforms, no-one else enforces it at a physical level. They let you mix and match code with GUI logic, a crap way of doing things yes, but it makes it very easy to move to a more structured way.

Maybe they will fix in this in XCode 3.1
garethlewis2 is offline   0 Reply With Quote
Old Oct 31, 2007, 07:59 AM   #8
twoodcc
macrumors P6
 
twoodcc's Avatar
 
Join Date: Feb 2005
Location: Right side of wrong
Send a message via AIM to twoodcc Send a message via MSN to twoodcc
has anyone looked at the example programs? there are tons! and some are pretty cool
__________________
tville
Smarter than the average bear
twoodcc is offline   0 Reply With Quote
Old Nov 5, 2007, 07:20 AM   #9
Reflections
macrumors newbie
 
Join Date: Nov 2007
Location: United Kingdom
XCode is fine, I've slipped into that with ease.

But...
IB looks great but for me it's a nightmare as it will no doubt be for any other users of the previous versions of IB

A question for anyone who might know the answer, today was the first time I built a new interface from scratch using the new IB, now all went okay (with a few hiccups trying to find the "new" ways)
But one thing I'm still yet to discover;

I create myself a new Object and load it with various Outputs and Actions, now what I cannot figure out is how do I create and implement the *.h and *.c files !!!!
Reflections is offline   0 Reply With Quote
Old Nov 5, 2007, 09:54 AM   #10
garethlewis2
macrumors 6502
 
Join Date: Dec 2006
It's in my previous reply.
garethlewis2 is offline   0 Reply With Quote
Old Nov 5, 2007, 10:49 AM   #11
savar
macrumors 68000
 
savar's Avatar
 
Join Date: Jun 2003
Location: District of Columbia
Send a message via AIM to savar
Quote:
Originally Posted by thefil View Post
What I'm looking for is the following:
- an introduction to Objective-C 2.0, intended for either new or experienced programs, that includes information on variables, if structures, loops, etcetera. Syntax, basically.
- Using Interface Builder with Xcode 3 and how to interact with the GUI
- Core Animation

Any help would be much appreciated, at least until Apple gets into gear replacing their outdated help files...

*edit* An especially important thing that would help me is Objective-C's print to console command; at least then I could blindly make my way through it :P

Also, could somebody explain to me why classes in Obj-C come in two parts?
Well you're in a tough spot. The best way to learn is to get a book, but I don't know if there are any books specifically for XCode3 yet...still in addition to learning Obj-C and Interface Builder, you really need to learn Cocoa as well.

Core animation turns out to be pretty easy (or so I hear) once you've got firm knowledge of those three things.

I believe there's a command called NSLog to write to the console. It takes a specially formatted string, so either use an NSString object, or if you're using a constant string, try this:

NSLog(@"hello world");

It's been a while since I did Cocoa but it's actually a great toolchain/environment for building apps really quickly. There's a lot of "default" behavior there that means you spend more time actually creating useful features and less time worrying about standard details.

Finally, Obj-C classes are split into 2 parts for a very simple reason. One part is the declaration of the class; this contains the name of the class, and its public data members and public message handlers (functions, essentially). The other file contains the actual implementation for all of those message handlers as well as any private data structures.

The reason for this is that the first file acts like a header (if you were writing in C, you would always create a header file); when you want to use that class in another part of your program you just include the header file into that program file and now that file has access to the class structure.
__________________
Mehce
savar is offline   0 Reply With Quote
Old Nov 5, 2007, 11:20 AM   #12
slooksterPSV
macrumors 68030
 
Join Date: Apr 2004
Location: Nowheresville
Send a message via AIM to slooksterPSV Send a message via MSN to slooksterPSV Send a message via Yahoo to slooksterPSV
The new version of Interface builder, relies on the user implementing the functions instead of letting Interface builder do it for you. E.g.

Instead of making a function called: sumTableColumn:
you go into your header file and implement it
- (IBAction) sumTableColumn(id sender);

uh I may have that syntax wrong... I forgot my Objective-C OMG!!!

durr forgot: then when you go back into IB you'll be able to link that function to a button or whatever. I don't like it, but that's how apple implemented it... dunno why though....
__________________
AMD Phenom 9600, 2GB RAM, 250GB HDD, ATI Radeon 4850, Vista Home Premium 64-bit
Gateway NV53 with Windows 7 Home Premium 64-bit & Ubuntu 10.04 Lucid Lynx 64-bit
slooksterPSV is offline   0 Reply With Quote
Old Nov 5, 2007, 11:21 AM   #13
ghall
macrumors 68040
 
ghall's Avatar
 
Join Date: Jun 2006
Location: Rhode Island
Send a message via AIM to ghall
I'm learning C++ using Xcode, and the upgrade totally threw me off. I'm spending more time learning how to use the new Xcode than I am learning C++. I'm sure I'll get used to it in time. Interface builder is a bit crazy for me though. I'll definitaly be keeping an eye out for a book on Xcode 3.
ghall is offline   0 Reply With Quote
Old Nov 5, 2007, 12:12 PM   #14
Reflections
macrumors newbie
 
Join Date: Nov 2007
Location: United Kingdom
Quote:
Originally Posted by garethlewis2 View Post
It's in my previous reply.
My apologies garethkewis2, I have just noticed it now

In fact I ended up using method 2 as I'd already created the nib file and I tell you what it's a very clumsy approach to setting up, first of all you end up manually editing the *.h file to correctly name the interface, then the *.c file's @implementation...

This is going to be pretty awkward I'd of thought for people just coming into Xcode.

Anyway thanks again, I seem to have it sorted out now
Reflections is offline   0 Reply With Quote
Old Nov 5, 2007, 12:44 PM   #15
Alloye
macrumors 6502a
 
Join Date: Apr 2007
Location: Rocklin, CA
Quote:
Originally Posted by Reflections View Post
This is going to be pretty awkward I'd of thought for people just coming into Xcode.
The new way is actually less awkward overall. Now you can add/remove outlets and actions to your header file in Xcode and IB will automatically sync the NIB. This makes it much easier to incrementally design/implement your UI. Before you'd have to re-import the header into IB manually.

The old way, on the other hand, made it easier to initially create your UI classes, but keeping subsequent changes in-sync was more of a pain.

Last edited by Alloye; Nov 5, 2007 at 12:53 PM.
Alloye is offline   0 Reply With Quote
Old Nov 6, 2007, 06:11 AM   #16
Reflections
macrumors newbie
 
Join Date: Nov 2007
Location: United Kingdom
@Alloye
I suppose it will be okay if you have never used the "old" methods, it's just I'm a bit of an old dog now and new tricks don't seem to work for me

I have blended in quite well to XCode mind, in fact I'm impressed with XCode itself, I suppose IB will become second nature sooner or later but I think I'll have to take a new approach to building the GUI from now on as my old ways will most certainly conflict with this version of IB

All in all though well done Apple...
Reflections is offline   0 Reply With Quote
Old Nov 6, 2007, 09:47 AM   #17
Gelfin
macrumors 68020
 
Gelfin's Avatar
 
Join Date: Sep 2001
Location: San Francisco, CA
I've got to come down on the "way, way better" side of this debate. XCode has always been, and remains, one of the most incoherent development environments I've ever seen, but generating some of your code from inside a separate interface design tool was an astonishingly random architectural choice and I'm glad they fixed it. Design interfaces in the interface tool; write code in the code tool. Simple.

Just to reveal my biases, of course, if there's one thing Microsoft has done right ever, it's Visual Studio. It spoils you for other development environments. Some would say in a bad way, but I suspect those people simply enjoy pain.

I keep meaning to see if I can get a good workflow going using TextMate projects instead of XCode for my primary editor in Macland, but I haven't gotten around to it.
__________________
Reality is that which, when you stop believing in it, doesn't go away.
--Philip K. Dick
Gelfin is offline   0 Reply With Quote
Old Nov 6, 2007, 11:07 AM   #18
Alloye
macrumors 6502a
 
Join Date: Apr 2007
Location: Rocklin, CA
Quote:
Originally Posted by Gelfin View Post
Just to reveal my biases, of course, if there's one thing Microsoft has done right ever, it's Visual Studio. It spoils you for other development environments. Some would say in a bad way, but I suspect those people simply enjoy pain.
I use Visual Studio professionally, and I agree it has some nice features that Xcode doesn't. It's also great environment if you like really tight integration between tools.

That being said, I much prefer working in Xcode. The biggest problem with VS is that it encourages a poor design pattern that makes it difficult to adopt MVC. I also think the whole idea of using generated code for UI creation is utter garbage. I can't tell you how many times I've managed to get the code view and design view out-of-sync. I'll take Interface Builder's approach of creating a serialized object graph any day. (To be fair, WPF/XAML does address these issues to a degree if you're writing .NET 3.0 applications.)

As for my biases, I love Cocoa and tolerate .NET. YMMV.
Alloye is offline   0 Reply With Quote
Old Nov 6, 2007, 11:21 AM   #19
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
I've been using XCode 3.0 for some days now, and I think that it does need some polishing.

1) Some stability issues need to be fixed. Especially for XCode.
2) The run log does not appear by default. Why?
3) The build and run button no longer has a keyboard shortcut. Why?
4) IB: It certainly needs some polishing. When selecting an item in a window, it is very possible to select the cell. But you may not want that. It is also very difficult to select an NSView inside a Scroll View (to resize it, for example) without having to try one or two times. It always selects a cell, or the scroll view. Finding new stuff is also difficult.
4)When I create a class inside IB, when I try to create the class files, it no longer automatically points to the project in XCode whose .nib file I have open. I need to follow the path to the project in the finder. Why?

On the bright side: XCode 3.0 and IB look better, feel better, smoother and more reliable. XCode's automatic .nib synchronization is neat and very relaxing. The search function for Cocoa interface elements is also very good, and XCode's little visual enhancements (like when you point your mouse at the left of the editor's window, it will highlight the current branch you are pointing your mouse in).

I haven't been involved with OBJC 2.0 yet. Although ObjC 1.0 code can be compiled with ObjC 2.0, I don't know if new ObjC 2.0 style code can be run on pre-Leopard machines. I think I will just sit this one out for the time being, at least when Apple's documentation is updated. Same goes with Core Animation. Cool features, but I will adopt them later.

Overall, I think that the new XCode is a huge step forward, but it suffers some illnesses that plague most of the new products in their infant stages. I am sure that XCode 3.1 will address most, if not all the issues anyone has.
Soulstorm is offline   0 Reply With Quote
Old Nov 6, 2007, 11:29 AM   #20
Gelfin
macrumors 68020
 
Gelfin's Avatar
 
Join Date: Sep 2001
Location: San Francisco, CA
Quote:
Originally Posted by Alloye View Post
As for my biases, I love Cocoa and tolerate .NET. YMMV.
Probably helps that I don't do so much .NET. If you want to get into platforms, yeah, I'll take Cocoa any day. It's just XCode that irritates me.
__________________
Reality is that which, when you stop believing in it, doesn't go away.
--Philip K. Dick
Gelfin is offline   0 Reply With Quote
Old Nov 6, 2007, 11:55 AM   #21
Alloye
macrumors 6502a
 
Join Date: Apr 2007
Location: Rocklin, CA
Quote:
Originally Posted by Soulstorm View Post
2) The run log does not appear by default. Why?
In Xcode Preferences, open the Debugging tab and change the option for On Start from Do Nothing to Show Console.

Quote:
Originally Posted by Soulstorm View Post
3) The build and run button no longer has a keyboard shortcut. Why?
Command-R works for me.

Quote:
Originally Posted by Soulstorm View Post
4)When I create a class inside IB, when I try to create the class files, it no longer automatically points to the project in XCode whose .nib file I have open. I need to follow the path to the project in the finder. Why?
This might help. In a nutshell, the preferred workflow has changed.
Alloye is offline   0 Reply With Quote
Old Nov 14, 2007, 01:08 AM   #22
cerberus 12
macrumors member
 
Join Date: Nov 2007
Interface Builder Guide Updated

Hey,
I found this thread helpful and while I was poking around the Apple Dev site later I noticed they had updated a lot of their guides.

http://developer.apple.com/documenta..._UserGuide.pdf

That is the updated Interface Builder Guide
cerberus 12 is offline   0 Reply With Quote
Old Nov 14, 2007, 02:54 AM   #23
Sijmen
macrumors 6502a
 
Join Date: Sep 2005
I've noticed that Xcode text input is really slow on my G4 1.5 GHz, sometimes even just 2 or 3 characters per seconds appear when typing.
Sijmen is offline   0 Reply With Quote
Old Nov 14, 2007, 10:54 PM   #24
slooksterPSV
macrumors 68030
 
Join Date: Apr 2004
Location: Nowheresville
Send a message via AIM to slooksterPSV Send a message via MSN to slooksterPSV Send a message via Yahoo to slooksterPSV
Quote:
Originally Posted by Sijmen View Post
I've noticed that Xcode text input is really slow on my G4 1.5 GHz, sometimes even just 2 or 3 characters per seconds appear when typing.
Check to see if Spotlight is indexing, if not open Activity Monitor and see what's taking all your CPU power. When I used XCode with the Earlier versions of Tiger it was like that for me, it was the Finder problem that everyone was getting where it would use all the CPU for what it was doing, no one really knows. If you have to relaunch finder, but I suspect its Spotlight Indexing. I'm on a G4 1.33GHz 1GB RAM and XCode runs fine for me.
__________________
AMD Phenom 9600, 2GB RAM, 250GB HDD, ATI Radeon 4850, Vista Home Premium 64-bit
Gateway NV53 with Windows 7 Home Premium 64-bit & Ubuntu 10.04 Lucid Lynx 64-bit
slooksterPSV is offline   0 Reply With Quote
Old Dec 3, 2009, 12:01 PM   #25
daehl
macrumors newbie
 
Join Date: Dec 2009
Xcode 3 Applescript Studio Slowness Solution?

Quote:
Originally Posted by Sijmen View Post
I've noticed that Xcode text input is really slow on my G4 1.5 GHz, sometimes even just 2 or 3 characters per seconds appear when typing.
I have the same problem with an iMac G5 running Xcode 3 after uploading to Leopard (10.5.8). The CPU shot up to 100% whenever I was editing my code and it became unbearably slow to edit projects. I tried turning off Spotlight indexing in its Mac OS Preference pane, but that had no effect.

However, I went thru the Xcode Preferences and found that once I turned off the Indexing checkbox: "Enable for all project" under the Code Sense pane, then performance got back to what I expected. It still seems a bit slower than Xcode 2.5, but not by much.

BTW- I originally installed Xcode 3.1, which doesn't seem to have this performance problem, but it has an even worse problem where it immediately crashes whenever you put a script object in your Applescript code. That's a huge bug, but I've seen it reported elsewhere (and Apple has had a lot of time to fix it, but hasn't). So I was forced to downgrade to Xcode 3.
daehl is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
The App Store app thinks Xcode is installed, but I deleted Xcode. moonman239 Mac Applications and Mac App Store 3 May 6, 2014 05:53 PM
Moving from xcode 3.2 to xcode 4.5.2 compilation error for 'abs' macro in stdlib.h hrishidev Mac Programming 7 Jun 2, 2013 10:36 AM
Xcode 4.5 iNeedAnsurs iPhone 0 Jan 25, 2013 02:49 PM
Xcode 3 vs Xcode 4 when dealing with Objective-C timebourne Mac Programming 8 Sep 23, 2012 05:36 PM
XCode 4.4.1 to Xcode 4.5 in Mountain Lion VinegarTasters OS X 10.8 Mountain Lion 2 Sep 19, 2012 08:55 PM

Forum Jump

All times are GMT -5. The time now is 09:42 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC