Objective-C Default Argument Value

前端 未结 6 1738
广开言路
广开言路 2020-12-10 03:58

Hey there, quick question here. I\'m sure there\'s a simple answer.

Coming from PHP, I\'m used to declaring a function with a default argument value like this:

6条回答
  •  [愿得一人]
    2020-12-10 04:32

    This question is super old, but in case anyone finds it, the Objective-C version of the PHP code (assuming this is inside a class) would probably be something like this:

    -(id)myFunction:(NSArray*)array {
      return [self myFunction:array withSort:FALSE];
    }
    
    -(id)myFunction:(NSArray*)array withSort:(BOOL)useSort {
       // CODE
    }
    

    I used (id)s as there is no data type information in your PHP code. Replacing the (id)s with actual data types would be wise.

提交回复
热议问题