• 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: split up alloc and init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: split up alloc and init?


  • Subject: Re: split up alloc and init?
  • From: Scott Andrew <email@hidden>
  • Date: Mon, 11 Feb 2008 08:36:13 -0800

Not knowing the app.. Wouldn't it make sense to create the invocation object when needed and not hold it around so you get one for each operation? (just curious). But back on to the first part of the subject. I think its bad to separate alloc and init.

On Feb 11, 2008, at 8:25 AM, John Terranova wrote:

I'm not sure I follow.

Once I call [NSInvocationOperation initWithTarget:selector:object:], then the object is set and unchangeable. I guess one option would be to learn about NSInvocation and modify the parameters in it directly.

DDLThumbMakerOp *opBig = [[DDLThumbMakerOp alloc] initWithTarget:self selector:@selector(threadedThumbMaker:) object: [NSNull null]; // placeholder object
NSInvocation *inv = [opBig invocation];
[inv setArgument:&opBig atIndex:3];


Hmmm, that might be an option.

	john


On Feb 11, 2008, at 12:46 AM, Scott Andrew wrote:

Wouldn't it be better to make it a wrapper around invocation object? Ten the problem goes away. You could then have a function

-(InvocationObject*) invocationObject;

or even a static init that returnes an auto released invocation object that has a single instance of your op class. Something like..


@interface DDLThumbMakerOp { NSInteger pageIndex; CGFloat thumbSize; }

@property(assign, readwrite) NSInteger pageIndex;
@property(assign, readwrite) CGFloat thumbSize;

-(InvocationObject*) invocationObjectForTarget:(id)target selector: (SEL)selector;

@end

You call can then use.

DDLThumbMakerOp *opBig = [[[DDLThumbMakerOp alloc] init] autorelease];

opBig.pageIndex = index;
opBig.thumbSize = size;

NSInvocationObject* invocationObject = [opBig invocationObjectForTarget:self selector:@selector(threadedThumbWithData)];

[opQ addOperation: invocationObject];

The invocation creation would be.

-(InvocationObject*) invocationObjectForTarget:(id)target selector: (SEL)selector
{
return [[NSInvocationObject alloc] initWithTarget:target selector:selector object:self];
}


This will make your DLLThumbMakerOp still a parameter of the selector. And i think its a bit easier on the eyes, at least to me and encapsulated nicely.

Scott


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >split up alloc and init? (From: John Terranova <email@hidden>)
 >Re: split up alloc and init? (From: Scott Andrew <email@hidden>)
 >Re: split up alloc and init? (From: John Terranova <email@hidden>)

  • Prev by Date: Re: split up alloc and init?
  • Next by Date: Re: Objective-C++
  • Previous by thread: Re: split up alloc and init?
  • Next by thread: Re: split up alloc and init?
  • Index(es):
    • Date
    • Thread