On 29/04/2009, at 10:48 PM, Тимофей Даньшин wrote:

- (void) intoArray:(NSMutableArray *)mutableRet addItemFromTable: (NSString *)table usingStatement:(sqlite3_stmt *)statement andSearchString:(NSString *) searchString {



Also, I don't mean to pick on your code (there's nothing obviously wrong with what you've posted so far apart from the leak I mentioned already), but as a matter of style, this way of designing methods is a bit strange. In the interests of being as self-contained and clean as possible, I'd rearrange this method something like this:

- (NSArray*) itemsFromTableWithName:(NSString*) table sqlStatement: (sqlite3_stmt*) statement searchString:(NSString*) searchString;

This way the method stands alone with a fully defined and self- documenting purpose that can be called by anyone without having first to create a NSMutableArray to pass into it. If they want to accumulate the results into a further array, then fine, do that; if they don't, they haven't had to create an array just to keep your code happy. There are also fewer failure modes, because this code is responsible for creating the returned array, and not relying on the client to do so. It's also easier for the client to detect success or failure, because a returned empty or nil array could mean something. In your case, the client would have to examine the contents of the array before and after to figure out if anything had actually happened.

This design is widely seen throughout the Cocoa frameworks, whereas the intoArray: type thing you have I don't think I've ever seen. It's usually a good plan to follow the approaches used in the frameworks, they are for good reason.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to