`
董瑞龙
  • 浏览: 105476 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

ios @property

    博客分类:
  • ios
阅读更多
@property (copy, assign) NSString *title;
什么是assign,copy,retain之间的区别?

assign: 简单赋值,不更改索引计数(Reference Counting)。
copy: 建立一个索引计数为1的对象,然后释放旧对象
retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1
retain的实际语法为:

- (void)setName:(NSString *)newName {
    if (name != newName) {
       [name release];
       name = [newName retain];
       // name’s retain count has been bumped up by 1
    }
}
说了那么麻烦,其实接下来的话最重要:

?如果你不懂怎么使用他们,那么就这样 ->

使用assign: 对基础数据类型 (NSInteger,CGFloat)和C数据类型(int, float, double, char, 等等)
使用copy: 对NSString
使用retain: 对其他NSObject和其子类
分享到:
评论

相关推荐

    IOS开发之@property的详细介绍

    IOS开发之@property的详细介绍 在类中定义属性时,总会使用到@property进行定义,下面就来说说@property的使用。 在使用过程中,如果需求公开且在其他类中使用时,通常会定义在.h头文件中;而如果只是该类自已需要...

    iOS基础知识之@property 和 Ivar 的区别

    @property 属性其实是对成员变量的一种封装。我们先大概这样理解: @property = Ivar + setter + getter Ivar Ivar可以理解为类中的一个变量,主要作用是用来保存数据的。 我们不妨来看个例子,通过下边的例子...

    iOS-UI控件常见属性总结

    @property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // 控件的标记(父控件通过标记可以找到对应的子控件) @property(nonatomic) NSInteger tag; // 控件的位置和尺寸(以父控件...

    ios-一款可以自定义的segmented control.zip

    自定义属性有: @property (nonatomic , strong) NSArray *btnTitleArray; @property (nonatomic , strong) UIColor *btnTitleNormalColor; @property (nonatomic , strong) UIColor *btnTitleSelectColor; @...

    IOS 中NSTimer定时器的使用

    主要介绍了IOS 中NSTimer定时器的使用的相关资料,希望通过本文能帮助到大家,能让大家彻底理解使用该方法,需要的朋友可以参考下

    IOS详细瀑布流

    @property (nonatomic, strong) NSMutableArray *attrsArray; /** 存放所有列的当前高度 */ @property (nonatomic, strong) NSMutableArray *columnHeights; /** 内容的高度 */ @property (nonatomic, assign) ...

    关于NSString @property的问题

    nsstring 详细描述 大多数对于NSString类型的对象作为属性都用的是copy

    ios-无限图片轮播器.zip

    @property (nonatomic,strong) UIImage *placeImage; @property (nonatomic,assign) NSTimeInterval AutoScrollDelay; //default is 2.0f,如果小于0.5不自动播放 //设置PageControl位置 @property (nonatomic...

    05-图片浏览器.zip

    @property (nonatomic,assign) int index; //索引标签 @property (weak, nonatomic) IBOutlet UILabel *indexLabel; // 图像数据 @property (nonatomic, strong) NSArray *imageArray; // 图像控件 @property ...

    ios-YBUploadView 上传图片.zip

    @property (nonatomic, strong) NSArray *images; @property (nonatomic, assign) NSInteger maxCount;//最多选择几张 默认9张 @property (nonatomic, assign) BOOL editEnabled;//是否可以编辑 默认YES //...

    iOS开发中属性 property 和 synthesize 详解

    针对iOS开发中属性 property 和 synthesize 进行了详细介绍

    ios-FTYCustomSetting.zip

    头部view的高度 / @property (assign, nonatomic) CGFloat headerViewHeight; /* 底部标题 / @property (copy, nonatomic) NSString *footerTitle; /* 底部view / @property (strong, nonatomic) UIView *...

    iOS UIPageView

    @property(nonatomic, strong) NSMutableArray * imageNameArray; //图片视图数组 @property(nonatomic, strong) NSMutableArray * imageViewArray; //图片当前下标 @property(nonatomic, assign) NSInteger ...

    ios-JoanKing灵活的瀑布流.zip

    @property(nonatomic,assign) UIEdgeInsets sectionInset; /** * 每一列之间的间距 */ @property(nonatomic,assign) CGFloat columnMargin1; /** * 每一行之间的间距 */ @property(nonatomic,...

    ios-水波图;支文字在2种颜色之间交换显示;.zip

    //创建 支持xib创建,init,initWithFrame; ... self.percentView = [[ZBPercentWaterView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];...@property (assign, nonatomic) CGFloat topLineWidth;

    ios-TitleMenuView.zip

    @property (nonatomic, strong) UIColor *btnNormalColor; //按钮选中时字体的颜色 @property (nonatomic, strong) UIColor *btnSelectedColor; //标题栏的背景颜色 @property (nonatomic, strong) UIColor *...

    举例讲解Objective-C中@property属性的用法

    主要介绍了Objective-C中@property属性的用法,包括@property的属性关键字的整理,需要的朋友可以参考下

    iOS系统定位demo封装

    基于iOS系统定位封装,封装成单例,可直接调用 //获取经纬度回调 typedef void(^LocationToolData)(NSString*longitude,NSString*latitude); @property (nonatomic,copy)LocationToolData longitudeAndLatitude;//...

Global site tag (gtag.js) - Google Analytics