我是目标C的新手,并试图为iPhone应用程序创建一个功能。但是,我很难在Objective C中创建这个C#函数。具体来说,传递整数数组并将其取回的正确语法,我只是在数组之间迷失,*和NSArray / NSMutableArray,NSInteger []等等。
我想出的最好的是,它不起作用,是:
- (NSInteger[])GetUniqueNumbers: (NSInteger *)nums[] WithMin: (int) min WithMax: (int) max;
{
return nums;
}
原始的C#功能:
private int[] GetUniqueNumbers(int[] nums, int min, int max)
{
int[] NewNumbers = new int[nums.Length];
for(int i=0; i < nums.Length; i++)
{
int trynum = nums[i];
while(ExistsAlready(NewNumbers, trynum) == true)
{
trynum = trynum + 1;
if (trynum > max)
{
trynum = min;
}
}
NewNumbers[i] = trynum;
}
return NewNumbers;
}
答案 0 :(得分:0)
这是我们在Objective c
中编写Method的方式- (NSArray *)GetUniqueNumbers: (NSArray *)nums WithMin: (int) min WithMax: (int) max;
{
return nums;
}
答案 1 :(得分:0)
试试这个
- (NSArray *)GetUniqueNumbers:(NSArray *)nums WithMin:(NSInteger)min WithMax:(NSInteger)max{
NSMutableArray *NewNumbers = [[NSMutableArray alloc]init];
for(int i=0; i<[nums count]; i++){
NSInteger trynum = [[nums objectAtIndex:i]intValue];
while([NewNumbers containsObject:[NSNumber numberWithInt:trynum]]){
trynum = trynum + 1;
if (trynum > max){
trynum = min;
}
}
[NewNumbers addObject:[NSNumber numberWithInt:trynum]];
}
return NewNumbers;
}