Re: It doesn't work without the NSLog()... Why?
Re: It doesn't work without the NSLog()... Why?
- Subject: Re: It doesn't work without the NSLog()... Why?
- From: Graham Cox <email@hidden>
- Date: Wed, 29 Apr 2009 23:36:16 +1000
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 (email@hidden)
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:
This email sent to email@hidden