0

I know NSDictionary can be used to return multiple things from a method when all the objects are Objective C type objects, but is there a way to package objects that are non-Objective C?

I have a method that I need to return an int and an IplImage. Without converting the IplImage to a NSValue (which I do not know how to do and wish to avoid), can I return 2 items from a method?

Also note that this method is defined in a separate class from which it is being called, thus I don't think I can use a class variable to store the int (or maybe I can?).

Thanks.

3 Answers 3

1

this approach will work for simple cases, i am sure you have seen it:

- (BOOL)caclulate:(NSError**)outError;

it returns a BOOL and an NSError.

To return an int:

- (BOOL)caclulate:(int*)outInt;

Using that approach, you can declare your method like this:

- (int)calculate:(IplImage*)outImage;

and then the caller's code takes the following form:

IplImage outImage;
int result = [object calculate:&outImage];
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure I understand, so where is the IplImage returned?
1

If NSError** solution doesn't work for you, you might want to create a helper struct that holds both the int and IplImage:

typedef struct _Data {
    int num;
    IplImage image;
} Data;

and then pass it around.

Comments

0

Short answer: no.

The common way is what you described, using a NSDictionary. Unfortunately, that means working with NSValue for non-standard types (NSNumber, etc).

Or you could use in/out params similar to the way most methods work with NSError.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.