美文网首页iOS 开发
Struct 在iOS中的集合中使用

Struct 在iOS中的集合中使用

作者: liyc_dev | 来源:发表于2017-02-15 10:54 被阅读45次

迁移自开源中国

// 定义结构体
struct NoteGroup {
    CGRect rect;
    int page;
};
typedef struct NoteGroup NoteGroup;

// 存入集合
NoteGroup noteGroup = {rect, 3};
[array addObject:[NSValue valueWithBytes:&noteGroup objCType:@encode(NoteGroup)]];

// 取出
NoteGroup noteGroup;
NSValue *noteGroupValue = array[index];
[noteGroupValue getValue:&noteGroup];

相关文章

网友评论

    本文标题:Struct 在iOS中的集合中使用

    本文链接:https://www.haomeiwen.com/subject/ljfqwttx.html