1.获取随机数
unsigned index = arc4random() % x; // 0 ~ x -1
unsigned index2 = arc4random() % x + 1; // 1 ~ x
2. ? :
return _suit ? _suit : @"?";s
3.init
-(instancetpye)init
{
self = [super init];
if(self){
// ...
}
return self;
}
不一定是init,initWithAge:之类的也可以是初始化函数
最好在头文件中注释,当它有子类的时候,子类应该调用这个initWithAge来初始化,
此时你可以重写init ,返回nil
4.single view application
one mvc
5.prefix
default is ViewController
CardGame? CardGameViewController
6.
main.storyboard: view
ViewController: controller
自己创建model
7. if([sender.currentTitle length]){
// 会有两种检测 length = 0 以及 currentTitle为nil
}
8. 重写,利用setter getter
a.之前的初始化
b.单击按钮,计数器+1,同时在面板中的文本框更新计数
不需要在单击的事件函数中设置文本框,可以把文本框放到计数器的setter中,这样就能保持同步,
-(void)setFlipsCount:(int)flipCount
{
_flipCount = flipCount;
self.flipLabel.text = flipCount;
}
9.再说一下 count,_count,self.count
在getter函数中,不要使用self.count[取值,因为self.count本身就是调用getter函数,这样会无限循环,你可以调用_count,。但是在setter中,调用self.count的取值是没问题的
_count相当于用来在getter中取count
10.模型表示“什么”, 你的游戏是什么,纸牌游戏是什么,它封装数据,逻辑。没有任何的ui
纸牌游戏:
1.初始化: 纸牌数量,纸牌堆
2.分数: readonly
11.设计一个新类,先想好公开的api是什么,先在.h头文件中写好
12.头文件中声明了只读属性readonly,如果实现文件中需要setter,可以设置私有属性 @property (readwrite) NSInterger score;
13.定义常量
#define MISMATCH_PENALTY 2
or
static const int MISMATCH_PENALTY = 2;
objective-c 笔记2
最新推荐文章于 2024-10-02 10:45:53 发布