Thread function that returns a value

Discussion in 'iOS Programming' started by bluehill, Jun 24, 2011.

  1. bluehill macrumors newbie

    Joined:
    Feb 5, 2011
    #1
    Please help with this......is this possible

    Code:
    -(void)someFunction
    {
    NSOperationQueue *queue = [NSOperationQueue new];
    		
    NSInvocationOperation *operation1 = [[NSInvocationOperation alloc] initWithTarget:self	
    selector:@selector(loadframe) object:nil];
    
    [queue addOperation:operation1];
    			
    [operation1 release];
    [queue release];
    
    
    //Use the value which has been returned from the thread 
    
    }
    
    -(NSString *)loadframe{
    return @"Test";
    }
    
    
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Yes. If you look at the NSInvocationOperation documentation you will see there is a result method. This will contain the result of the invocation once it's complete. Note you have to wait for completion (there are a few ways of doing this, look at NSOperation, for this to be available.
     

Share This Page