• 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: Building a C library Objective-C wrapper framework
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Building a C library Objective-C wrapper framework


  • Subject: Re: Building a C library Objective-C wrapper framework
  • From: Uli Kusterer <email@hidden>
  • Date: Sat, 19 Jul 2008 18:12:29 +0200

On 15.07.2008, at 09:48, Sebastian Nowicki wrote:
I guess that didn't work. I forgot that categories only add to a class, so I can't use the stuff from the category in the original class. I also can't think of a way to use the typedef'd C structs and enums from the library in the header file without including the library header file. This is tricky indeed. If only I could see how Apple did it with OpenGL, etc :P.


Well, for enums and things like that, I guess you'd have to directly expose those. Maybe you can selectively include only their header? Alternatively, you could define your own constants and translate between those and the library's.

Instance variables are easy: You can declare a pointer to a struct without needing to declare the struct itself, so put all your ivars into a struct:

@interface MyClass : NSObject
{
	struct MyClassPrivateIVars*	ivars;
}
@end

And then declare the struct in a private header or in your implementation file:

struct MyClassPrivateIVars
{
	int var1;
	int var2;
};

@implementation MyClass

-(id)	init
{
	if(( self = [super init] ))
	{
		ivars = calloc( 1, sizeof(struct MyClassPrivateIVars) );
		// check ivars for success here.
		ivars->var1 = 1;
		ivars->var2 = 2;
	}
	return self;
}

-(int)	var1
{
	return ivars->var1;
}

-(void)	setVar1: (int)n
{
	ivars->var1 = n;
}

-(void)	dealloc
{
	// Clean up any object references or pointers in ivars here.
	if( ivars )
		free( ivars );
	[super dealloc];
}

@end

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Building a C library Objective-C wrapper framework
      • From: Jens Alfke <email@hidden>
References: 
 >Building a C library Objective-C wrapper framework (From: Sebastian Nowicki <email@hidden>)
 >Re: Building a C library Objective-C wrapper framework (From: Jens Alfke <email@hidden>)
 >Re: Building a C library Objective-C wrapper framework (From: Sebastian Nowicki <email@hidden>)
 >Re: Building a C library Objective-C wrapper framework (From: Sebastian Nowicki <email@hidden>)

  • Prev by Date: Re: Spoiled by Java IDEs
  • Next by Date: IB won't launch
  • Previous by thread: Re: Building a C library Objective-C wrapper framework
  • Next by thread: Re: Building a C library Objective-C wrapper framework
  • Index(es):
    • Date
    • Thread