开发者

Result of NSPredicate as a string

NSPredicate *predicate;
开发者_高级运维predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS 'aaa'"];
BOOL result = [predicate evaluateWithObject:@"anystringaaaggg"];

Result is true. But I need to create an NSString that will contain "aaa". How can I do this?


Doesn't work that way.

For example, how could you create a string that equals "Steve" OR "Novikoff"? Yet you can create a predicate to check for the same condition.


You said result is True for the above code so u need to make NSString object.

NSPredicate *predicate;
predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS 'aaa'"];
//this is for NSString object
NSString *checkMe=@"anystringaaaggg";
BOOL result = [predicate evaluateWithObject:checkMe];

Then we can use this checkMe as string object and use anywhere u want

OR

//other object
id *checkMe=anyObject;
BOOL result = [predicate evaluateWithObject:[NSString stringWithFormat:@"%@",checkMe]];
NSString *result=[checkMe stringValue];

Then we can use this result as string object and use anywhere u want

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜