Quickies

[categories] [index] [all (527)] [latest]

Cocoa Foundation
  1. Cache the implementation pointer for -[NSString hasPrefix:]

    SEL hasPrefixSelector = @selector(hasPrefix:);
    BOOL (*hasPrefixIMP) (id, SEL, id) = (BOOL (*) (id, SEL, id))[@"" methodForSelector:hasPrefixSelector];
    

    Use the cached pointer instead of sending the message

    BOOL b = hasPrefixIMP (@"Europe", hasPrefixSelector, @"e");