On Fri, Jun 12, 2009 at 1:01 PM, Joshua Garnham<[email protected]> wrote: > How would I declare it ?
The same way you declare any method: in an @interface block. You haven't posted enough code to illuminate *why* the method you're trying to use can't be found, but here are a few common reasons: 1. Forgetting to #import the header file with the class's @interface. 2. Forgetting to declare the method in the class's @interface. 3. The method is actually defined in a category or class extension that lives in a header file that you haven't #imported. 4. The method is intentionally not declared in an @interface (for example, it's a helper method), and the code that's trying to use this method comes before the helper method in the source file. When the compiler is going through your code, it needs to know the types of the method's arguments and return value, because it needs to generate different code for objects than it does for structs or floats. So, using your example, the compiler is trying to compile the expression [self objectArray]. Objective-C is compiled file-by-file, from top to bottom, and the compiler doesn't do any external resolution. This is different from Java or C#, whose compilers look elsewhere in the project for definitions of symbols they haven't seen yet. C and Objective-C instead use #import to copy-paste the contents of header files on top of source files before compiling. This means that by the time the compiler has gotten to the line of code containing your troublesome expression, it better have seen some class somewhere that declares a -(id)objectArray method, even if it's not declared on the class that you're sending the message to. It just needs at least one declaration of the method so it can work out the appropriate types. This is getting rather long, and I'm sure there are better-written explanations elsewhere. Like, say, Apple's Objective-C documentation. Also, I've copied this reply to the list, because I think it's useful to more people than just yourself. --Kyle Sluder _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
