Objective-C中防止重复代码的一种方法
来源:互联网 发布:java math.random 编辑:程序博客网 时间:2024/05/21 04:19
假设有一个CGRect需要通过计算求得,而我需要在多个方法中使用这个CGRect,为了防止在每个方法中都计算一遍这个CGRect,可以使用以下方法:
Step One:
在.h文件中添加一条属性:
@property (readonly) CGRect myRect;
Step Two:
在.m文件中添加相对应的方法
- (CGRect)myRect{ return CGRectMake(firstTouch.x, firstTouch.y, lastTouch.x - firstTouch.x, lastTouch.y - firstTouch.y);}
注意方法的返回值和方法名要和属性相对应.
之后,便可在其他方法中这样使用这个CGRect
self.myRect
- Objective-C中防止重复代码的一种方法
- 游戏中防止加速的一种方法
- sql中防止记录重复的方法
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector withObject
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法per…
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- 黑马程序员——Java基础---String类和基本数据类型包装类
- 【xtku】巧删显卡右键菜单 还系统干净界面
- js 根据模板增加表格(table)
- ubuntu下搭建ftp服务器vsftpd,cuteFTP登录该服务器
- Three Swaps DFS
- Objective-C中防止重复代码的一种方法
- Java中继承thread类与实现Runnable接口的区别
- codeforces 340 A. The Wall
- linux下如何添加一个用户并且让用户获得root权限
- jQuery之使用jQuery.fn.prop()替换jQuery.fn.attr()
- Book of Evil 树双向DFS
- 设置picturebox 背景为透明
- u- boot 的认识
- Google Protocol Buffer 的使用和原理