View Full Version : Beginning Objective C - Help!
Jul 9, 2006, 12:36 PM
I've been teaching myself Objective C over the last few days using this Wikibook (http://en.wikibooks.org/wiki/Programming_Mac_OSX_with_Cocoa_for_beginners).
I keep getting errors on the WKDDrawView class (which I've called SDDrawView) and I can't think how to fix them.
I've uploaded my attempt here (http://www.matefeedkillrepeat.com/SDDrawView.m). if anyone can give me any help I'd greatly appreciate it.
Jul 9, 2006, 01:08 PM
1. kHandleSize doesn't seem to be declared anywhere.
2. Looks like you never give _dragShape a type. Maybe you just want it untyped as id or a specific type like SDShape or something but it needs to have one:
SDShape *_dragShape = ...
or id _dragShape = ...
(but I can't see your .h files)
...and so on. Basically, the compiler seems to be telling you the right things here generally, pay attention to what it says and go fix it line by line. Variables need to be declared in advance (either locally or in a .h file if instance variables). When you get argument warnings like that, look up the function or method in the Apple docs and check your argument types against the reference.
It looks like you are in fact giving NSIntersectsRect an NSRect as the second arg (which is correct). In this case, the compiler might be complaining about other errors down the line and coming up with phantom errors at the top. It's a bit wonky and does that sometimes, so sometimes you need to skip down and start fixing lower errors and the top ones will magically go away.
Jul 9, 2006, 02:09 PM
I've uploaded the .h file here (www.matefeedkillrepeat.com/SDDrawView.h).
I think you're right about the phantom errors. It also says that the Switch quantity given is not an integer, even though in it's parameter I give it a method which returns an integer.
Jul 9, 2006, 08:53 PM
So yeah it looks like you do need to declare a type for _dragShape somewhere. I don't see that in your .h file or in the local methods you use it in. Sometimes the compiler will come out with 24 errors and you fix one forgotten semicolon or brace and it compiles, it takes a while to figure out what it's really trying to tell you. If the errors just don't make sense, start suspecting something else.
Jul 10, 2006, 09:58 AM
Thanks for your help. I understand what's wrong, but can't fix it as I don't know what to declare _dragshape as. The author of the Wikibook doesn't make it very clear. I'll have to wait for it to be updated.
Jul 11, 2006, 06:30 AM
Looks like you'd want to declare it as an SDShape*, or possibly untyped as an id. But if that part doesn't work, very likely there's other stuff wrong too.