I’m building a bunch of functions that will make my core data calls a bit nicer, and not so bloated.
Lets say I have a method that looks like this:
- (NSArray*)retrieveDataFrom:(NSString *) name where:(NSString *) where is:(NSString *) is {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%@ = '%@')", where, is];
return [self retrieveDataFrom:name withPredicate:predicate];
}
and then sometimes I want to do something like this (for example):
[self retrieveDataFrom:@"table" where:@"id" is:int 2];
instead of this:
[self retrieveDataFrom:@"table" where:@"id" is:@"2"];
Is there a way to get a method to accept an argument without knowing its type?
Not directly. You can declare the input as
NSObject *so it can take aNSString *or aNSNumber *, but you’re still stuck usingNSNumber‘s ugly syntax.However, better syntax is coming soon in the form of Clang Language Extensions.
When these land, you’ll be able to write this instead:
At present, the LLVM website says these will be in llvm 4.0. The smart money says this will be in Xcode 4.4, but I doubt Apple is beholden to a statement on the LLVM website.