Your other thread was locked.
I'm not sure you fully understand blocks or I'm not understanding what you want. "completionHandler" is a block that is being passed as an argument. If you are passing the block into the init method then calling it later you need to make sure you are copying the block either via a property or doing a block copy and setting it to a private variable so it does not go out of scope. As far as the array goes that's only a matter of passing it in as an argument to the block. The "completionHandler" you refer to is a alternative to a delegate callback. If you're unsure what a delegate callback or a block is then you need to do further reading. Post more code with better context and hopefully we can help.
On a site note, giving your objects a better naming convention \ more specific names will help other people help you. Having an array with a name of arrayForObject and another one named arrayObject can be confusing when it's not your code base.
Edit: I had a few moments so I typed up an example I hope this helps.
Code:
//
// DJSFactory.h
//
#import <Foundation/Foundation.h>
typedef void(^ myCustomCompletionHandler)(NSArray *factoryArray); //This is not required but I would prefer to work with a type especially when you have multiple arguments, you can declare the block inline if you want.
@interface DJSFactory : NSObject
@property(nonatomic, copy)myCustomCompletionHandler completionCallBack;//our block as a property
@property(nonatomic, retain)NSArray *myFactoryArray; //misc data doesn't matter
-(id)initWithCompletionHandler:(myCustomCompletionHandler)completionHandler; //our custom init method
-(void)startReallyLongAsyncTaskHere; //stupid task doesn't really matter
@end
Code:
//
// DJSFactory.m
//
#import "DJSFactory.h"
@implementation DJSFactory
@synthesize completionCallBack;
@synthesize myFactoryArray;
-(id)initWithCompletionHandler:(myCustomCompletionHandler)completionHandler {
self = [super init];
if (self) {
self.completionCallBack = completionHandler; //we have a property copying the block
[self startReallyLongAsyncTaskHere];
}
return self;
}
-(void)startReallyLongAsyncTaskHere {
//we make a really large factory array here in the background
//once we are ready to call our completionHandler
self.completionCallBack(self.myFactoryArray);
}
@end
Code:
//
// ViewController.m
//
#import "ViewController.h"
#import "DJSFactory.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
DJSFactory *factoryObject = [[DJSFactory alloc] initWithCompletionHandler:^(NSArray *factoryArray) {
//here we place what we want out of the factory array
//we will do a simple log statement.
NSString *myName = [factoryArray objectAtIndex:0];
NSLog(@"%@", myName);
//Side Note: if this was a true async call this may not return immediately, so the NSLog statement would be delayed.
//You can however use this synchronously and get an immediate call back.
}];
}
@end
This is a stupid example and typed by hand but hope it helps. No guarantee it will copy/paste properly.