method with 2 return values

后端 未结 7 709
春和景丽
春和景丽 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 15:58

    You have a few options:

    • NSArray: Just return an array. Pretty simple.
    • Pointers: Pass in two pointers, and write to them instead of returning anything. Make sure to check for NULL!
    • Structure: Create a struct that has two fields, one for each thing you want to return, and return one of that struct.
    • Object: Same a structure, but create a full NSObject subclass.
    • NSDictionary: Similar to NSArray, but removes the need to use magic ordering of the values.

提交回复
热议问题