views:

65

answers:

2

Hi.

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.

+3  A: 

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

gga80
+2  A: 

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
0x4b