using structs in cocoa

Lango's picture

I have a very beginner question here.

I want to output a struct from a custom patch.

Right now this is similar to what I have (this is in my main header file)

( The ... is code i left out to make this short)

#import <Quartz/Quartz.h>
 
typedef struct {
float x;
float y;
} Vector2D
 
@interface myCustomPatch : QCPlugIn
{
}
 
...
@property Vector2D outputPosition;

in my implementation i have

...
@implementation myCustomPatch
 
@dynamic ... outputPosition;
...
 
- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time witArguments:(NSDictionary*)arguments
{
   ...
   self.position.x = 2; /* GET ERROR HERE */
 
   return YES;
}

However I recieve the error "error:request for member 'position' in something not a structure or union"

I know this is really simple and right now i'm feeling very simple :)

But google-ing cocoa and structs doesn't bring back much.

I read somewhere the self.position will actually return a copy or the struct and the above should of given me another area. is that true?

Any help would be fantastic

Regards

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
Re: using structs in cocoa

First -- I've never seriously used the official api, so I can't help you much.

But, I'm pretty certain you want to use an NSArray or NSDictionary as an output property to create a structure (internally, we use QCStructure, to save on the relatively cheap type conversion)

You'll also want to use the same name as the property -- you're using "position" in the execute function, but "outputPosition" as the property name.

toneburst's picture
Re: using structs in cocoa

No advice, just wanted to wish you luck! This is something I want to do too, sometime (when/if I ever get around to having another stab at learning Cocoa/Objective-C).

a|x

franz's picture
Re: using structs in cocoa

Apple official documentation says to use NSDictonnary to return QC structures. There's a list of corresponding cocoa-QC datatypes at the help center. hope this helps....

cybero's picture
Re: using structs in cocoa

your code reads

 witArguments

your code should read with the following format

execute:atTime:withArguments

That's why your getting an error breakdown at the next line.

Please see gemma's documentation on Apple's site for further details.

By the way - loved the unintended 'slang' towit 'wit' :-)

Hope that helps - cybero

Lango's picture
Re: using structs in cocoa

Thanks for everyones reply.

cwright wrote:
But, I'm pretty certain you want to use an NSArray or NSDictionary as an output property to create a structure

hmm, okay i'll give that a try.

cwright wrote:
You'll also want to use the same name as the property -- you're using "position" in the execute function, but "outputPosition" as the property name.

Aaaand there was the silly thing I was doing, maybe next time I should sleep on it and check it in the morning before I post it up. I'm at work at the moment so I can't check, but this should just give me the error I was supposed to be getting.

toneburst wrote:
No advice, just wanted to wish you luck! This is something I want to do too, sometime (when/if I ever get around to having another stab at learning Cocoa/Objective-C).

Thanks toneburst! I'll make sure to post up my patch so you can see how I did things. However i'm in the middle of renevating at the moment so I only get to work on it every few days.

cybero wrote:
your code reads

 witArguments

your code should read with the following format

execute:atTime:withArguments

That's why your getting an error breakdown at the next line.

Please see gemma's documentation on Apple's site for further details.

Ahh, that was a typo in my post its not actually in my code :) My iMac (which has the code) has trouble getting on the net so I had to post using my laptop.

That documentation is what I was looking for. Thanks for that, i'll give it a read.