Can I pass delegate as a parameter objective-c

I am working with an NSOperationQueue and I want to add new NSOperations to the NSOperationQueue. It is a queue that lives in a singleton instance of a class I have. It would make things a lot easier if I could move everything into the static class by passing the delegate.

Here is my code now as it lives in - this is in a cellForRowAtIndexPath

 NSString *key = [NSString stringWithFormat:@"%@%@",cell.dataItem.ItemID, cell.dataItem.ManufacturerID];

        if (![self.imgOperationInQueue valueForKey:key]) {

            ImageOperation *imgOp = [[ImageOperation alloc] initWithItemID:cell.dataItem.ItemID withManufacturerID:cell.dataItem.ManufacturerID withReurnType:kThumbnail];
            imgOp.identifier = [NSString stringWithFormat:@"%i", cell.tag];
            imgOp.delegate = self;
            [[SharedFunctions sharedInstance] addImageOperationToQueue:imgOp];
            [imgOp release];

            // store these in the dictionary so we don;t queue up requests more than once
            [self.imgOperationInQueue setValue:cell.dataItem.ItemID forKey:key];

If I could add the delegate as a parameter I could put all of this code into the shared singleton class and call it from anywhere in my app.

I suppose that I could use an NSNotification - or can I use a block of some sort?


Just create the appropriate init method that passes in the delegate.

- (id)initWithItemID:(NSString *)itemID
  withManufacturerID:(NSString *)manufacturerID
    self = [super init];
    if (self)
        .... // Other assignments
        self.delegate = theDelegate;

    return self;

Need Your Help

Uninstall application programmatically: crash rotating the device

java android xml

I'm trying to make a listview with all the applications installed inside where you can make multiple uninstalls applications. I have a problem. This is the code.