供将要学习objective-c的人士
来源:互联网 发布:福师大网络教育作业 编辑:程序博客网 时间:2024/06/11 00:24
Class Header (.h)
#import"AnyHeaderFile.h"@interfaceClassName :SuperClass
// define public properties// define public methods
@end
Class Implementation (.m)
#import"YourClassName.h"
@interfaceClassName ()
// define private properties// define private methods@end
@implementationClassName {
// define private instance variables}
// implement methods
@end
Defining Methods
- (type)doIt;
- (type)doItWithA:(type)a;- (type)doItWithA:(type)a
b:(type)b;Implementing Methods
- (type)doItWithA:(type)ab:(type)b {
// Do something with a and b...
returnretVal;}
Creating an Object
ClassName* myObject =[[ClassNamealloc]init];
Calling a Method
[myObject doIt];
[myObject doItWithA:a];[myObjectdoItWithA:ab:b];
Declaring Variables
typemyVariable;
Variable types
int
1, 2, 500, 10000
floatdouble
1.5, 3.14, 578.234
BOOL
YES, NO
ClassName *
NSString *, NSArray *, etc.
id
Can hold reference to any object
Defining Properties
@property (attribute1, attribute2)type propertyName;
strong
Adds reference to keep object alive
weak
Object can disappear, become nil
assign
Normal assign, no reference
copy
Make copy on assign
nonatomic
Make not threadsafe, increase perf
readwrite
Create getter&setter (default)
readonly
Create just getter
Using Properties
[myObject setPropertyName:a];myObject.propertyName = a; // alt
a = [myObject propertyName];
a = myObject.propertyName; // alt
What is a Property?
1) Automatically defines a private instance variable:
type_propertyName;
2) Automatically creates a getter and setter:
- (type)propertyName;
- (void)setPropertyName:(type)name;
Using _propertyNameuses the private instancevariable directly. Usingself.propertyNameusesthe getter/setter.
Custom Initializer Example
- (id)initWithParam:(type)param {if((self= [superinit])) {
_propertyName = param;}
return self; }
NSString Quick Examples
NSString*personOne =@"Ray";NSString*personTwo =@"Shawn";NSString*combinedString =
[NSStringstringWithFormat:@"%@: Hello, %@!",personOne, personTwo];
NSLog(@"%@", combinedString);
NSString*tipString =@"24.99";
floattipFloat = [tipStringfloatValue];
NSArray Quick Examples
NSMutableArray*array =
[@[person1, person2]mutableCopy];
[array addObject:@"Waldo"];NSLog(@"%d items!", [arraycount]);for(NSString*person inarray) {
NSLog(@"Person: %@", person);}
NSString*waldo = array[2];
- 供将要学习objective-c的人士
- 转的 供自己和大家以后学习 Objective-C JSON的数据源
- 对将要学习的迷惑
- 即将要学习的东西
- [置顶] 我将要学习的
- swift初探(供objective c开发者参考)
- 微软发布供专业人士使用的Vista入门手册
- Objective-C 的property学习
- Objective-C类的学习
- Objective-c的指针学习
- 近期将要学习的内容(flag)
- 学习Pytorch将要写的内容
- 本文将要讨论Objective-C中的方法替换(method replacement)和swizzling(移魂大法)。
- Objective-C 的Runtime的学习
- 关于寒假学习objective-c的感想
- 学习Objective-c的原创书籍
- objective-c语法学习:类的继承
- Objective C的学习之HelloWorld
- Android获取网址前的网站Icon图片
- Leetcode: Recover Binary Search Tree
- 为什么在webroot下新建文件夹,里面的jsp访问不到?
- USB中的NRZI编码浅析
- 详解堆栈的几种实现方法——C语言版
- 供将要学习objective-c的人士
- 小波变换和motion信号处理
- hdu 1026 Ignatius and the Princess I(广搜+优先队列)
- DELPHI FOR IOS 开发入门指南
- 1037. Magic Coupon (25)
- hdu 1394 Minimum Inversion Number 线段树
- 大年初二,好几天没编程了。。。
- win8.1配置java环境
- usb的pid和vid