structs and cocoa & doc
structs and cocoa & doc
- Subject: structs and cocoa & doc
- From: Jeff Childers <email@hidden>
- Date: Wed, 12 Oct 2005 11:58:45 -0500
I can't seem to find any info(examples) about using/reading/writing
structs in cocoa. Can someone point me to some examples or give some
insight?
Any help would be greatly appreciated.
//D2sClass.h
typedef struct _d2sData {
unsigned long header;
} d2sData;
@interface D2sClass : NSObject <NSCoding> {
d2sData* d2s_struct;
}
- (d2sData*)d2s_struct;
- (void)setD2s_struct:(d2sData*)newD2s_struct;
@end
//D2sClass.m
@implementation D2sClass
- (id)init
{
if (self = [super init]) {
//[self setD2s_struct:nil];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeValueOfObjCType:@encode(d2sData*) at:&d2s_struct];
}
- (id)initWithCoder:(NSCoder *)coder
{
if (self = [super init]) {
[coder decodeValueOfObjCType:@encode(d2sData*) at:&d2s_struct];
}
return self;
}
- (d2sData*)d2s_struct
{
return d2s_struct;
}
- (void)setD2s_struct:(d2sData*)newD2s_struct
{
d2s_struct = newD2s_struct;
}
- (void)dealloc
{
[super dealloc];
}
@end
//MyDocument.h
#import "D2sClass.h"
@interface MyDocument : NSDocument
{
D2sClass* D2S;
}
@end
//MyDocument.m
- (id)init
{
self = [super init];
if (self) {
D2S = [[D2sClass alloc] init];
NSLog(@"--> %h",D2S->header);
}
return self;
}
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
return [NSArchiver archivedDataWithRootObject: D2S];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
D2S = [NSUnarchiver unarchiveObjectWithData: data];
return YES;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden