[Biococoa-dev] mass calculator bug
Alexander Griekspoor
mek at mekentosj.com
Sun Aug 29 16:21:14 EDT 2004
>> So we start with the first interface line in the BCSequence header:
>> @interface BCSequence : NSObject {
>> should become:
>> @interface BCSequence : NSObject <NSCopying, NSCoding> {
>>
>
> Hmm, I have never used such a construction before and have done
> similar things (passing an object to another class).
It's not passing an object to another class:
With the line:
@interface BCSequence: NSObject <protocol1, protocol2> {
you simply declare that the BCSequence object adheres to protocol1 and
protocol2.
Protocols are lists of methods that you promise this class has
implemented. An example protocol from EnzymeX:
@protocol EXMapSequenceViewDelegate <NSObject>
- (NSString *) sequenceForMapView:(EXMapSequenceView *)mview;
- (void) setVisibleSequence: (NSRange) aRange;
- (NSRange) visibleSequence;
- (NSRange) selectedSequence;
- (void)generateMap;
@end
This has a number of big advantages, first the compiler will help to
check if classes conform to required protocols. Second, it allows you
to check if an object at runtime supports certain methods using
NSObject's conformsToProtocol: classmethod. Finally, you can promise
the compiler that a class you are calling supports the protocol: [<
EXMapSequenceViewDelegate>theObject doThis]; , even if you don't know
exactly what type of class theObject will be at runtime (as long as it
adheres to the protocol it's fine).
A number of protocols are predefined in the cocoa frameworks and for
instance <NSDraggingInfo> <NSCopying> <NSCoding>. In order to make your
class NSCoding compatible, you have to let this know by adding that
particular part to your @interface line, plus you have to implement the
methods declared in the protocol (initWithCoder and encodeWithCoder in
this case). These are described in the docs.
>> In BCMassCalculator, InitWithSequence, change:
>>
>>> sequence = [seq copy]; <--------- error
>>
>> to sequence = [seq copyWithZone: [self zone]]; // I believe this is
>> more efficient memory wise
>>
>
> Even if I use an accessor:
>
> [self setSequence: seq];
>
> and then:
>
> - (void)setSequence:(BCSequence *)s
> {
> [s retain];
> [sequence release];
> sequence = s;
> }
>
> I get the same copywithZone error. But maybe this is different
> because BCSequence passes a copy of itself?
That's probably because you still did not implement the copyWithZone
method and thus did not implement the NSCopying protocol.
Did you implement the methods that I wrote in my email, and change the
interface line?
Alex
*********************************************************
** Alexander Griekspoor **
*********************************************************
The Netherlands Cancer Institute
Department of Tumorbiology (H4)
Plesmanlaan 121, 1066 CX, Amsterdam
Tel: + 31 20 - 512 2023
Fax: + 31 20 - 512 2029
AIM: mekentosj at mac.com
E-mail: a.griekspoor at nki.nl
Web: http://www.mekentosj.com
The requirements said: Windows 2000 or better.
So I got a Macintosh.
*********************************************************
More information about the Biococoa-dev
mailing list