{"action":"created","issue":{"url":"https://api.github.com/repos/zhdh2008/JohnsonUtils4Droid/issues/27","labels_url":"https://api.github.com/repos/zhdh2008/JohnsonUtils4Droid/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/zhdh2008/JohnsonUtils4Droid/issues/27/comments","events_url":"https://api.github.com/repos/zhdh2008/JohnsonUtils4Droid/issues/27/events","html_url":"https://github.com/zhdh2008/JohnsonUtils4Droid/issues/27","id":114181828,"number":27,"title":"iOS学习笔记","user":{"login":"zhdh2008","id":8311285,"avatar_url":"https://avatars.githubusercontent.com/u/8311285?v=3","gravatar_id":"","url":"https://api.github.com/users/zhdh2008","html_url":"https://github.com/zhdh2008","followers_url":"https://api.github.com/users/zhdh2008/followers","following_url":"https://api.github.com/users/zhdh2008/following{/other_user}","gists_url":"https://api.github.com/users/zhdh2008/gists{/gist_id}","starred_url":"https://api.github.com/users/zhdh2008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhdh2008/subscriptions","organizations_url":"https://api.github.com/users/zhdh2008/orgs","repos_url":"https://api.github.com/users/zhdh2008/repos","events_url":"https://api.github.com/users/zhdh2008/events{/privacy}","received_events_url":"https://api.github.com/users/zhdh2008/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-10-30T01:46:35Z","updated_at":"2015-11-07T08:03:58Z","closed_at":null,"body":"1.框架\r\n   （Interface Builder）\r\n   UIKit、  Foundation、Cocoa、Cocoa Touch\r\n   1.1 关于Cocoa\r\n    http://www.cnblogs.com/margincc/archive/2011/03/17/2095059.html\r\n    http://jingyan.baidu.com/article/22fe7ced1361683002617f3c.html\r\n  \r\n2.Objective-C\r\n   2.1 对象的创建 ：通过类方法alloc分配内存，然后调用init方法初始化对象\r\n   alloc 是来自NSObject 类方法，init是成员方法。\r\n   方法的调用规则如下：\r\n   [类名称  类方法];\r\n   [对象   成员方法];\r\n\r\n   2.2 self关键字类似于Java中的this\r\n         super也类似于Java中的super\r\n         NSObject的description方法类似Java中的toString方法\r\n\r\n  2.3 内存管理\r\n        关于ARC机制、autoreleasepool\r\n\r\n  2.4 异常捕获\r\n       和Java类似， 只不过要在try、catch、finally前面加上‘@’符号\r\n\r\n  2.5 id可以指向任意类型\r\n        我们将其称之为泛型对象。\r\n\r\n  2.6 动态判定与选择器\r\n  -(BOOL) isMemberOfClass: (Class) clazz 用于判断对象是否是clazz 类型的实例，但\r\n不包含子类的实例。\r\n-(BOOL) isKindOfClass: (Class) clazz 用于判断对象是否是clazz 类型的实例或\r\n者clazz 的子类的实例。\r\n-(BOOL) respondsToSelector: (SEL) selector 用于判断类型或者对象是否能够回应某个\r\n方法，这个方法使用选择器表示。\r\n+(BOOL) instancesRespondToSelector:(SEL) selector 用于判断类型所产生的实例是否能够回应\r\n某个方法，这个方法使用选择器表示。\r\n-(id) performSelector: (SEL) selector 用于动态调用类型或者对象上的一个方\r\n法。\r\n\r\n  2.7 类别Category\r\n我们不希望继承某个类，又想增加方法，可以采用下面的方式实现，括号中的字符串即为类别\r\nFractionMath.h\r\n#import \"Fraction.h\"\r\n@interface Fraction (Math1)\r\n-(Fraction*) mul: (Fraction*) f;//乘法，就是传入一个Fraction 作为参数，与当前的Fraction\r\n进行计算\r\n-(Fraction*) div: (Fraction*) f;//除法\r\n@end\r\n@interface Fraction (Math2)\r\n-(Fraction*) add: (Fraction*) f;//加法\r\n@end\r\n\r\n然后在m文件中这样实现它\r\nFractionMath.m\r\n#import \"FractionMath.h\"\r\n@implementation Fraction (Math1)\r\n-(Fraction*) mul: (Fraction*) f{\r\nreturn [[Fraction alloc] initWithNumerator: numerator*[f numerator]\r\ndenominator: denominator*[f denominator]];\r\n}\r\n-(Fraction*) div: (Fraction*) f{\r\nreturn [[Fraction alloc] initWithNumerator: numerator*[f denominator]\r\ndenominator: denominator*[f numerator]];\r\n}\r\n@end\r\n@implementation Fraction (Math2)\r\n-(Fraction*) add: (Fraction*) f{\r\nreturn [[Fraction alloc] initWithNumerator:\r\nnumerator*[f denominator] + denominator*[f numerator]\r\ndenominator: denominator*[f denominator]];\r\n}\r\n@end\r\n\r\n2.8 协议@protocol\r\n@interface 相当于是Objective-C的类的原型，与Java中的接口意义是不同的。\r\n此处的@protocol才是和Java中的interface等价的。\r\n\r\n//-(BOOL) conformsToProtocol: (Protocol*) prot //判断某个对象是否遵从某个协议\r\n例如：\r\n@protocol Printing1\r\n-(void)print1;\r\n@end\r\n\r\n@protocol Printing2\r\n-(void)print2;\r\n@end\r\n\r\n@protocol Printing3 <Printing2>\r\n\r\n-(void)print3;\r\n\r\n@end\r\n\r\n\r\n#import \"PrintingImpl.h\"\r\n\r\n@implementation PrintingImpl\r\n\r\n-(void)print1{\r\n    //TODO\r\n    \r\n    PrintingImpl *pi = [[PrintingImpl alloc]init];\r\n    \r\n    // 判断某个对象是否遵从某个协议\r\n    if ([pi conformsToProtocol:@protocol(Printing1)]) {\r\n        NSLog(@\"YES\");\r\n    }else{\r\n        NSLog(@\"NO\");\r\n    }\r\n    \r\n};\r\n\r\n-(void)print2{\r\n    //TODO\r\n    \r\n};\r\n\r\n-(void)print3{\r\n    //TODO\r\n    \r\n};\r\n\r\n@end\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n\r\n  "},"comment":{"url":"https://api.github.com/repos/zhdh2008/JohnsonUtils4Droid/issues/comments/154652954","html_url":"https://github.com/zhdh2008/JohnsonUtils4Droid/issues/27#issuecomment-154652954","issue_url":"https://api.github.com/repos/zhdh2008/JohnsonUtils4Droid/issues/27","id":154652954,"user":{"login":"zhdh2008","id":8311285,"avatar_url":"https://avatars.githubusercontent.com/u/8311285?v=3","gravatar_id":"","url":"https://api.github.com/users/zhdh2008","html_url":"https://github.com/zhdh2008","followers_url":"https://api.github.com/users/zhdh2008/followers","following_url":"https://api.github.com/users/zhdh2008/following{/other_user}","gists_url":"https://api.github.com/users/zhdh2008/gists{/gist_id}","starred_url":"https://api.github.com/users/zhdh2008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhdh2008/subscriptions","organizations_url":"https://api.github.com/users/zhdh2008/orgs","repos_url":"https://api.github.com/users/zhdh2008/repos","events_url":"https://api.github.com/users/zhdh2008/events{/privacy}","received_events_url":"https://api.github.com/users/zhdh2008/received_events","type":"User","site_admin":false},"created_at":"2015-11-07T08:03:58Z","updated_at":"2015-11-07T08:03:58Z","body":"2.15 谓词NSPredicate：\r\nCocoa 提供了NSPredicate 用于指定过滤条件，谓词是指在计算机中表示计算真假值的函数，\r\n它使用起来有点儿像SQL 的查询条件，主要用于从集合中分拣出符合条件的对象，也可以\r\n用于字符串的正则匹配。首先我们看一个非常简单的例子，对谓词有一个认知。"}}