oc中自定义结构体
来源:互联网 发布:windows 10 周年更新 编辑:程序博客网 时间:2024/06/06 03:22
OC中自定义结构体
1. 方式一
//自定义一个结构体
struct WSBounds{ CGFloat WSWidth; CGFloat WSHeight; };
//自定义类型起别名
typedef struct WSBounds WSBounds;
//快速创建结构体
static inline WSBounds WSBoundsMake(CGFloat width, CGFloat height){ WSBounds bounds; bounds.WSWidth = width; bounds.WSHeight = height; return bounds; }
2. 方式二
//快速创建 typedef struct WSBounds { CGFloat width; CGFloat height; } WSBounds;
//快速创建结构体 static inline WSBounds WSBoundsMake(CGFloat width, CGFloat height { WSBounds bounds; bounds.width = width; bounds.height = height; return bounds; }
3.关于static inline
苹果官方标准结构体的写法
/* Points. */ struct CGPoint { CGFloat x; CGFloat y; }; typedef struct CGPoint CGPoint; /*** Definitions of inline functions. ***/ CG_INLINE CGPoint CGPointMake(CGFloat x, CGFloat y) { CGPoint p; p.x = x; p.y = y; return p; } //苹果官方宏定义 # define CG_INLINE static inline
static 标识此内联联函数只能在本文件中使用,限制了内联函数的作用域。相对于宏来说,static inline具有和宏同样级别的开销,而且还提供了类型安全,没有长度和格式的具体限制。
0 0
- oc中自定义结构体
- oc中常用结构体
- oc中结构体和枚举类型
- OC 中 objc_selector 结构体详解
- OC中常用的结构体
- Foundation -- OC结构体
- OC结构体
- OC 常用结构体
- OC结构体
- OC结构体
- OC之【objective-c中结构体】
- 19-OC中Foundation下的结构体使用
- OC中Foundation框架的结构体和字符串
- 黑马程序员--OC中常见的结构体
- OC中修改 对象的结构体属性
- Delphi中自定义结构体的应用
- vector中自定义结构体的排序
- OC中定义了一个结构体(struct),设置结构体的值
- 图像编程-彩色图像灰度化
- 【随笔】聊一聊服务器的那些事儿
- leetcode 1 Two Sum
- SVN的Trunk、Branch和Tag(一)
- Android多媒体应用——通知的使用(Notification)
- oc中自定义结构体
- Github上如何取消fork别人的repository
- Essential Notes on Database(III) Normalization 范式 (I)
- Java开发者必备的六款工具
- 数据结构-Java实现-链表回顾
- iOS中对数据的存储的一种方法--归档
- Android开源之仿微信UI
- Android一键锁屏的实现
- java基础之正则表达式