Re: Warning when using NSSplitView
Re: Warning when using NSSplitView
- Subject: Re: Warning when using NSSplitView
- From: "Louis C. Sacha" <email@hidden>
- Date: Sat, 3 Jan 2004 19:03:47 -0800
Hello...
This same issue came up a few days ago, that time it was NSString's
length method that returns an unsigned int, and NSStatusItem's method
length that returns a float (the subject line was "Multiple
declarations for method length" if you want to look at that thread in
the archives).
The solution, as you figured out, is to statically type the object as
an NSSplitView. You could also change that message in your code to
[(NSSplitView *)splitView isVertical] to prevent the error, but what
you have already done is probably the best way.
If your program requires that an object be a specific type (or your
code crashes, etc...) then that object should be statically typed in
its declaration. Some people might argue otherwise, but it does very
little good for an object to be typed id if it is always going to be
a specific type of object (with the exception of some coding
conventions, like initializers returning type id, and other selectors
where different types of objects would be valid return values or
arguments depending on which class it is sent to, etc...).
The dynamic nature of objective-C is very powerful, but dynamic
typing places almost the entire burden on the programmer to ensure
that everything works properly, and also requires that every method
with the same name have an identical method signature (or you get
warnings like the one you got, and the possibility of runtime
errors). By statically typing objects when appropriate, a good part
of the burden is shifted to the compiler, and the programming process
becomes much easier because the compiler can provide warnings when
you are sending messages to the wrong type of object or trying to
change an object that might be immutable , for example, instead of
having to figure out what is wrong from runtime errors.
So, in other words, static typing is your friend :)
Hope that helps,
Louis
Sorry for posting twice...
XCode seems to display warnings for header files in the c files. The
two errors come from 'NSSplitView.h' (defines as BOOL) and
NSSliderCell.h (defined there as int). I fixed it by changing the
'IBOutlet id' to an 'IBOutlet NSSplitView *'. Is this the only way
to solve the problem?
Cheers,
Oli
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.