Re: Cocoa Documentation on NSFormatter
Re: Cocoa Documentation on NSFormatter
- Subject: Re: Cocoa Documentation on NSFormatter
- From: Thomas Lachand-Robert <email@hidden>
- Date: Sat, 15 Dec 2001 23:15:57 +0100
Le samedi 15 dicembre 2001, ` 03:43 , Ondra Cada a icrit :
Thomas,
perhaps I just don't understand properly, but...
Thomas Lachand-Robert (TLR) wrote at Sat, 15 Dec 2001 14:44:07
+0100:
TLR> Also I discovered today that the "obj" item returned by
TLR> getObjectValue:(id *)obj forString:(NSString *)exprstr
TLR> errorDescription:(NSString **)error
TLR> is supposed to conform to NSCopying, since I got
TLR> *** -[myObjectClass copyWithZone:]: selector not recognized
TLR> Then, the correct declaration should be
TLR> getObjectValue:(id<NSCopying>*)obj forString:...
...I can't make sense of this. First, quite generally:
The "obj" is _made by the formatter and given to you_, not the vice versa.
Therefore, the declaration is quite right: since the returned object is
just
plain id, you cannot presume any other behaviour -- especially not that it
conforms to NSCopying.
Sorry if it wasn't so clear, I explain more precisely. I am programming my
own subclass of NSFormatter (to parse mathematical expressions). The Apple
doc seems to indicate that you get a string for the text field and
transform it to an id (named 'obj' in the declaration)... I said 'seems'
because it is far for being clear on this subject, that's my first
complaint: the chain of actions from the last key typed in the field to
the complete validation is NOT explained. But you apparently confirm that
by saying 'The "obj" is _made by the formatter and given to you_', that's
exactly what I understand.
Anyway, in my own subclass of NSFormatter, getObjectValue... is called
first with the string I typed in the text field. I return a custom object
which is here a subclass of NSObject, say myObjectClass. SINCE the
declaration declares the object of type 'id', I presume that any object
should be convenient, but it is NOT. Just after the return, I get the
exception, which apparently means that Apple expects here a
NSObject<NSCopying>*, not just a basic 'id'. It turns out that my object
is not intended to be copied, and doesn't implement NSCopying (it would be
complicated and very inconvenient to do so). So I believe there is
something wrong in Apple's doc, here, and don't know exactly what to do.
Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.