代码之家  ›  专栏  ›  技术社区  ›  futureelite7 Adam Rosenfield

如何拆分目标c函数定义?

  •  0
  • futureelite7 Adam Rosenfield  · 技术社区  · 16 年前

    -(id) initWithBsType:(NSInteger)buysell AccountCode:(NSString *):c_acc_code password:(NSString *)password exchangeCode:(NSString *)ecode productCode:(NSString *)product orderType:(NSString *)otype price:(NSString *)price qty:(NSString *):qty reference:(NSString *)ref enablePriceWarn:(BOOL)enablepw enableApprvWarn:(BOOL)enableaw orderValidity:(NSString *)validity;
    

    我应该插入什么来将其拆分为3-4行?

    3 回复  |  直到 16 年前
        1
  •  1
  •   mipadi    16 年前

    在典型的Objective-C样式中,跨越多行的方法通常以冒号对齐,以使其更具可读性:

    -(id) initWithBsType:(NSInteger)buysell
             AccountCode:(NSString *)c_acc_code
                password:(NSString *)password
            exchangeCode:(NSString *)ecode
             productCode:(NSString *)product
               orderType:(NSString *)otype
                   price:(NSString *)price
                     qty:(NSString *)qty
               reference:(NSString *)ref
         enablePriceWarn:(BOOL)enablepw
         enableApprvWarn:(BOOL)enableaw
           orderValidity:(NSString *)validity;
    
        2
  •  2
  •   rein    16 年前

        3
  •  0
  •   Georg Fritzsche    16 年前

    看到长长的参数列表,我想知道调用函数是什么样子的。。。可能很长。

    我建议使用structs,并可能将XML的读取拆分为更多方法,例如:

    typedef struct {
        /* ... */
    } Order;
    
    // extend the xml-reader for clean seperation, 
    // seperate into multiple methods if too big
    -(BOOL) readOrder:(Order*);
    

    -(id) initWithOrder:(Order*)order;