method with 2 return values

后端 未结 7 714
春和景丽
春和景丽 2021-01-24 15:48

I want to call a method which returns two values

basically lets say my method is like the below (want to return 2 values)

NSString* myfunc
{
   NSString          


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 16:00

    Wrap the two strings in an NSArray:

    - (NSArray*)myFunc
    {
       NSString *myString = @"MYDATA";
       NSString *myString2 = @"MYDATA2";
       return [NSArray arrayWithObjects:myString, myString2, nil];
    }
    
    NSArray *theArray = [self myFunc]
    NSString *value1 = [theArray objectAtIndex:0];
    NSString *value2 = [theArray] objectAtIndex:1];
    

提交回复
热议问题