I don’t know exactly how to raise this question. I want to create a method like stringWithFormat:or predicateWithFormat:, i.e. My method takes an argument directly as a string with format specifiers. How can I achieve this?
eg.,
-(void) someMethod: (NSString *)str, format;
So I can later call it the following:
[someObject someMethod:@"String with format %@",anotherString];
This does not apply to any particular context.
I worked predicateWithFormatwith code similar to:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like myName"];
This did not work, but:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like 'myName'"];
worked similarly:
NSString *str = @"myName";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",str];
So this means that the method is able to understand whether the format specifiers used inside them have the given argument. I'm curious how to do this?
source
share