温州网站建设培训,美术类网站建设费用,软考证书有用吗张雪峰,宁都网站建设Creating Objects 这件事困扰我一点时间了#xff0c;ObjC没有一个Constructor的概念 而在Create Objects这件事上既有用过自己写的-init#xff0c;还return instancetype#xff0c;大概这个#xff0c;也有用过一些Class Method#xff0c;就是明确知道是id类型的… Creating Objects 这件事困扰我一点时间了ObjC没有一个Constructor的概念 而在Create Objects这件事上既有用过自己写的-init还return instancetype大概这个也有用过一些Class Method就是明确知道是id类型的Slides总结了 alloc init来创建NSMutableArray *cards [[NSMutableArray alloc]init]Class Method来创建NSString *moltuae [NSString stringWithFormat:“%d”, 42];NSString *a hello world;//不过一般应该都用这个吧 也有init 和 Class Method共存的状况[NSString stringWithFormat:...] same as [[NSString alloc] initWithFormat:...]老爷爷推荐alloc/init 利用objects的方法创建新的objectsNSString’s - (NSString *)stringByAppendingString:(NSString *)otherString;
NSArray’s - (NSString *)componentsJoinedByString:(NSString *)separator;
NSString’s NSArray’s - (id)mutableCopy;//这个很有意思将一个immutable的object变成一个mutable的新的object这种则不是在创建object虽然传递出objectNSArray’s - (id)lastObject;
NSArray’s - (id)objectAtIndex:(int)index; 除非NSArray不存在才会创建出NSArray但是也是nil吧 nil nil很好用只需注意struct状况 id id是一个很特殊很特殊的pointer It means “pointer to an object of unknown/unspecified” type. 所以其实之前写的 NSString *a [NS....];能被完全写成 id a [NS....];id很有用但是有危险。 因为给的信息很通用则complier难以察觉出语法上的问题。 但是运行的时候可能就崩溃 Really all object pointers (e.g. NSString *) are treated like id at runtime. But at compile time, if you type something NSString * instead of id, the compiler can help you. Introspection 如果出现id,可以使用一下方法来保护自己 isKindOfClass (inheritance included)
isMemberOfClass (no inheritance)
respondsToSelectorClass testing methods take a Class
You get a Class by sending the class method class to a class (not the instance method class).
这里可以这样做感觉就是把NSString class生成为一个class然后再来测试因为classes也是objects老爷爷怕大家迷茫让大家记住这个用法就好了if ([obj isKindOfClass:[NSString class]]) {NSString *s [(NSString *)obj stringByAppendingString:”xyzzy”];
}以下 这里的第一个shoot是没有参数的 第二个shootAt有一个参数对于obj使用了target Method有多个参数需要写成addCard:AtTop:类似 if ([obj respondsToSelector:selector(shoot)]) {[obj shoot];
} else if ([obj respondsToSelector:selector(shootAt:)]) {[obj shootAt:target];
} SEL is the Objective-C “type” for a selector
SEL shootSelector selector(shoot);
SEL shootAtSelector selector(shootAt:);
SEL moveToSelector selector(moveTo:withPenColor:); 个人感觉这里的code将会有很大的用处不过我目前还是暂时都不知了的状态 If you have a SEL, you can also ask an object to perform it ...Using the performSelector: or performSelector:withObject: methods in NSObject
[obj performSelector:shootSelector];
[obj performSelector:shootAtSelector withObject:coordinate];Using makeObjectsPerformSelector: methods in NSArray
[array makeObjectsPerformSelector:shootSelector]; // cool, huh?
[array makeObjectsPerformSelector:shootAtSelector withObject:target]; // target is an idIn UIButton,
- (void)addTarget:(id)anObject action:(SEL)action ...;
[button addTarget:self action:selector(digitPressed:) ...];Foundations ----Primitive Data Types --------Foundation Data Structures--------
| int | NSNumber - generic |
| double | NSString |
| float | NSArray |
| struct | NSSet |
| struct | NSDictionary |
| ... | ... |
------------------------------------------------------------------- 大概就是这样.... 还有很多的Mutable版本NSDate还有NSData... 再举了一些常用的Class Method Colors Fonts 因为木有例子存在一直都听的磕磕碰碰充满了困意 让我假装直到每个有关的几件事吧 UIColor 可以设置alpha我喜欢透明度可以用RGBHSB甚至图片patten来定义color[UIColor greenColor]有此种[UIColor lightTextColor]也有此种Fonts UIFont *font [UIFont preferredFontForTextStyle:UIFontTextStyleBody];//用到users contents里 (UIFont *)systemFontOfSize:(CGFloat)pointSize;(UIFont *)boldSystemFontOfSize:(CGFloat)pointSize;//用到button之类的困意不断我决定把NSMutableString以及这些相关的在demo时候再来复习/学习.... 就是这么一个爱贪有趣的人....