• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: encodeConditionalObject:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: encodeConditionalObject:


  • Subject: Re: encodeConditionalObject:
  • From: Ondra Cada <email@hidden>
  • Date: Fri, 2 Aug 2002 17:37:50 +0200

On Friday, August 2, 2002, at 03:49 , Anthony Arthur wrote:

Anyone have an example of how to use encodeConditionalObject:?

Sure:

17 /tmp> cat q.m
#import <Foundation/Foundation.h>

@interface Foo:NSObject <NSCoding> {
@public // no need for accessors for this example
id delegate;
}
@end
@implementation Foo
-(void)encodeWithCoder:(NSCoder*)coder {
[coder encodeConditionalObject:delegate];
return;
}
-initWithCoder:(NSCoder*)coder {
self=[super init];
delegate=[coder decodeObject];
return self;
}
-(NSString*)description {
return [NSString stringWithFormat:@"Foo(%@)",delegate];
}
@end

int main() {
id p=[NSAutoreleasePool new];
Foo *foo=[Foo new];
id delegate=@"delegate";

foo->delegate=delegate;
// normally, if archiving just foo, you don't want the delegate archived:
NSLog(@"%@",[NSUnarchiver unarchiveObjectWithData:[NSArchiver archivedDataWithRootObject:foo]]);
// on the other hand, if delegate happens to be archived anyway, you want to keep the connexion:
NSLog(@"%@",[[NSUnarchiver unarchiveObjectWithData:[NSArchiver archivedDataWithRootObject:[NSArray arrayWithObjects:foo,delegate,nil]]] objectAtIndex:0]);
[p release];
return 0;
}
18 /tmp> cc -framework Foundation q.m && ./a.out
2002-08-02 17:36:30.816 a.out[477] Foo((null))
2002-08-02 17:36:30.830 a.out[477] Foo(delegate)
19 /tmp>

---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.

References: 
 >encodeConditionalObject: (From: Anthony Arthur <email@hidden>)

  • Prev by Date: Re: Better way to replace a character in a string?
  • Next by Date: Re: NSBox unclickable
  • Previous by thread: encodeConditionalObject:
  • Next by thread: Re: how do i read and send data through a serial port (using a keyspan adaptor)
  • Index(es):
    • Date
    • Thread