2

I'm using Objective-C language. But I don't know how to use c with Objective-C.

Ex) This is Function method.

- ( ?? ) function{
unsigned int first = ..
unsigned int second = ..
unsigned int third = ..

int infoData = {first,second,third};
return infoData;
}

How to fill in parenthesis.

I don't use NSArray.

Please help me.

2 Answers 2

4

the answer is the same as it is in C. Objective-C is a strict superset of C.

Sign up to request clarification or add additional context in comments.

Comments

3

Assuming you declared int[] infoData you could make the return int*, but you're still going to have problems because the array is allocated on the function's stack. You'll need to dynamically allocate space for it just like you would in C.

(You cannot use int[] as a return type)

The code below will compile, but gcc will warn about returning the address of a function local variable.

@interface test
- (int*) function;
@end

@implementation test

- (int*) function{
  unsigned int first = 0;
  unsigned int second = 1;
  unsigned int third = 2;

  int infoData[] = {first,second,third};
  return infoData;
}

@end

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.