On Sun, Oct 24, 2010 at 5:54 PM, Tom Jones <tjo...@acworld.com> wrote:
> -(NSString *)getDataForType:(NSString *)aType error:(NSError **)err
> {
>    NSError *localErr = nil;
>    NSString *result = [self getDataForType:aType separator:@"\t" 
> excludeFields:nil error:&localErr];
>    *err = *localErr;
>    return result;
> }
>
> -(NSString *)getDataForType:(NSString *)aType excludeFields:(NSArray 
> *)aFields error:(NSError **)err
> {
>    NSError *localErr = nil;
>    NSString *result = [self getDataForType:aType separator:@"\t" 
> excludeFields:aFields error:&localErr];
>    *err = *localErr;
>    return result;
> }

(1) In Cocoa convention, methods that being with "get" return accept a
pointer to a type and return their data through it. See -[NSString
getCharacters:range:] for example. Your method should probably be
called simply "dataForType:error:". (2) Convention again says that the
error parameter is optional, and if you don't need it to pass
NULL/nil. In that case, your line "*err = *localErr;" will segfault
because you are derferencing NULL. You need to check for NULL before
trying to dereference it. (3) The localErr stuff is pointless anyway.
You could just as well do: "[self getDataForType:aType separator:@"\t"
excludeFields:aFields error:err]".

> -(NSString *)getDataForType:(NSString *)aType separator:(NSString 
> *)aSeperator excludeFields:(NSArray *)aFields error:(NSError **)err
> {
>    BOOL isValidQuery = [self hasValidType:aType];
>    if (isValidQuery == NO) {
>        NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary];
>        [errorDetail setValue:@"Failed to find the requested type." 
> forKey:NSLocalizedDescriptionKey];
>        *err = [NSError errorWithDomain:@"DataForType" code:1 
> userInfo:errorDetail];

Again, you need to check that err is NULL before trying to dereference it.

>        return nil;
>    } else {
>        err = nil;

This line will never do anything.

>    }
> ...
> ...
> ...
> }
_______________________________________________

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