How to split objective c function definition?
I have a really long objective c function definition, and would like to split it into multiple lines to make the function more readable. Let's say I have this definition:
-(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;
What should I insert to split it into 3-4 lines?
(I'm creating an object that can b开发者_如何学Pythone serialized into xml using libxml, so I need to be able to assign this many params to the object on creation.)
Alternatively, in Xcode's configuration under "Indentation" you can turn on "Line Wrapping" to enable soft wrapping and you'll never have to worry about this again.
In typical Objective-C style, methods that span multiple lines are usually aligned by colon to make them more readable:
-(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;
Seeing the long parameter list makes me wonder how the calling function looks like... probably quite long.
I'd recommend using structs and maybe split the reading of the XML into more methods, e.g.:
typedef struct {
/* ... */
} Order;
// extend the xml-reader for clean seperation,
// seperate into multiple methods if too big
-(BOOL) readOrder:(Order*);
Now your initializer needs to take only one parameter:
-(id) initWithOrder:(Order*)order;
精彩评论