objective-c中使用cocoa的NSPredicate,谓词(十四)

objective-c中使用cocoa的NSPredicate,谓词(十四),第1张

概述在语言上,谓语,谓词是用来判断的,比如“我是程序猿”中的是,就是表判断的谓语,“是”就是一个谓词,在objective-c中,应该说在COCOA中的NSPredicate表示的就是一种判断。一种条件的构建。我们可以先通过NSPredicate中的predicateWithFormat方法来生成一个NSPredicate对象表示一个条件,然后在别的对象中通过evaluateWithObject方法来

在语言上,谓语,谓词是用来判断的,比如“我是程序猿”中的是,就是表判断的谓语,“是”就是一个谓词,在objective-c中,应该说在COCOA中的nspredicate表示的就是一种判断。一种条件的构建。我们可以先通过nspredicate中的predicateWithFormat方法来生成一个nspredicate对象表示一个条件,然后在别的对象中通过evaluateWithObject方法来进行判断,返回一个布尔值。还是看代码简单明了:

[plain]  view plain copy #import <Foundation/Foundation.h>   @interface Human :NSObject   {       Nsstring *name;       int age;       Human *child;          }   @property (copy)Nsstring *name;   @property int age;   @end   @implementation Human   @synthesize name;   @synthesize age;         int main(int argc, const char * argv[])       @autoreleasepool {           //利用kvc进行对象初始化           Human *human = [[Human alloc]init];           Human *child = [[Human alloc]init];           [human setValue:@"holydancer" forKey:@"name"];           [human setValue:[NSNumber numberWithInt:20] forKey:@"age"];           [human setValue:child forKey:@"child"];           [human setValue:[NSNumber numberWithInt:5] forKeyPath:@"child.age"];                      nspredicate *predicate1=[nspredicate predicateWithFormat:@"name=='holydancer'"];//创建谓词判断属性           nspredicate *predicate2=[nspredicate predicateWithFormat:@"child.age==5"];//创建谓词判断属性的属性           //此处在创建谓词时可以有好多种条件写法,比如大小比较,范围验证,甚至像数据库 *** 作那样的like运算符,这里就不一一列举了           BOol tmp1=[predicate1 evaluateWithObject:human];//验证谓词是否成立,得到布尔返回值           BOol tmp2=[predicate2 evaluateWithObject:human];           if (tmp1) {               NSLog(@"human对象的name属性为'holydancer'");           }           if (tmp2) {               NSLog(@"human对象的child属性的age为5");     }       return 0;   }  

2012-03-21 19:59:42.668 predicate[2246:403] human对象的name属性为'holydancer'

2012-03-21 19:59:42.670 predicate[2246:403] human对象的child属性的age5


关键字:objective-c,objective c,oc,谓词 ,nspredicate  ,IPhone开发基础 .


@H_419_247@好了,写到这里大家就会发现谓词的用法其实很简单,语法结构有点儿类似之前我们介绍的KVC,灵活多变,我们暂且掌握到这里便足够了。另外,到今天为止,我们的objective-c基础就告一段落了,马上我要推出IPhone开发的教学博客,希望大家继续关注。

@H_419_247@

@H_419_247@网上找的IOS开发面试题,暂无答案

1.Difference between shallow copy and deep copy?

2.What is advantage of categorIEs? What is difference between implementing a @R_403_4602@ and inheritance?
3.Difference between categorIEs and extensions?

4.Difference between protocol in objective c and interfaces in java?

5.What are KVO and KVC?
6.What is purpose of delegates?
7.What are mutable and immutable types in Objective C?
8.When we call objective c is runtime language what does it mean?
9.what is difference between NSNotification and protocol?
10.What is push notification?
11.polymorphism?
12.Singleton?
13.What is responder chain?
14.Difference between frame and bounds?
15.Difference between method and selector?
16.Is there any garbage collection mechanism in Objective C.?
17.NSOperation queue?
18.What is lazy loading?
19.Can we use two tablevIEw controllers on one vIEwcontroller?
20.Can we use one tablevIEw with two different datasources? How you will achIEve this?
21.What is advantage of using RESTful webservices?
22.When to use NSMutableArray and when to use NSArray?
23.What is the difference between REST and SOAP?
24.Give us example of what are delegate methods and what are data source methods of uitablevIEw.
25.How many autorelease you can create in your application? Is there any limit?
26.If we don’t create any autorelease pool in our application then is there any autorelease pool already provIDed to us?
27.When you will create an autorelease pool in your application?
28.When retain count increase?
29.Difference between copy and assign in objective c?
30.What are commonly used NSObject class methods?
31.What is convenIEnce constructor?
32.How to design universal application in Xcode?
33.What is keyword atomic in Objective C?
34.What are UIVIEw animations?
35.How can you store data in iPhone applications?
36.What is coredata?
37.What is NSManagedobject model?
38.What is NSManagedobjectContext?
39.What is predicate?

40.What kind of persistence store we can use with coredata?


:来自cocoaChian社区




转自holydancer的CSDN专栏,原文地址:http://blog.csdn.net/holydancer/article/details/7380799

总结

以上是内存溢出为你收集整理的objective-c中使用cocoa的NSPredicate,谓词(十四)全部内容,希望文章能够帮你解决objective-c中使用cocoa的NSPredicate,谓词(十四)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1053814.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存