Xcode编译器的特性,自动生成getter和setter
 

A.@property

自动生成某个成员变量的getter和setter的声明
变量的命名要求:以下划线开头
 Student.h
@interface Student : NSObject
{
int _age;
int _no;
int age;//此变量不会被访问到
double height;
NSString *_name;
} @property int age, no;
@property int height;
@property NSString *name; @end
 
B.@synthersize
自动生成getter和setter的实现
 @implementation Student

 @synthesize age = _age, no = _no, height = _height;//指定一下成员变量,否则会访问同名变量,如果不存在,就会自动生成@private的变量
@synthesize name = _name; @end
C.省略变量的声明,在.h中得声明可以省略
注意:XCode自动生成的成员变量都是@private
 
 @interface Student : NSObject

 @property int age;
@property double height;
@property NSString *name; @end

D.省略实现(XCode4.4以上)
只需要写@property,默认访问下划线开头的成员变量
 @interface Car : NSObject

 @property int wheels;

 @end
 
E.如果手动实现了setter和getter,编译器就不再自动生成下划线开头的成员变量
 

[Objective-c 基础 - 2.6] @property和@synthesize的更多相关文章

  1. Objective-C基础笔记(2)@property和@synthesize

    先贴出使用@property和@synthesize实现的上一篇中的代码,再解释这两个keyword的使用方法和含义,代码例如以下: Person.h文件 #import <Foundation ...

  2. @property和@synthesize的特性

    基础回顾:get方法和set方法 定义类成员变量时,可以在@interface中定义,也可以在@implementation中定义: 在@interface中声明,成员变量的状态是受保护的,即“@pr ...

  3. iOS 内存管理-copy、 retain、 assign 、readonly 、 readwrite、nonatomic、@property、@synthesize、@dynamic、IB_DESIGNABLE 、 IBInspectable、IBOutletCollection

    浅谈iOS内存管理机制 alloc,retain,copy,release,autorelease 1)使用@property配合@synthesize可以让编译器自动实现getter/setter方 ...

  4. @synthesize obj=_obj的意义详解 @property和@synthesize

    本文转载至 http://blog.csdn.net/ztp800201/article/details/9231969 http://hi.baidu.com/feng20068123/item/c ...

  5. Objective-C中的@property和@synthesize用法

    @代表“Objective-C”的标志,证明您正在使用Objective-C语言 Objective-C语言关键词,@property与@synthesize配对使用. 功能:让编译好器自动编写一个与 ...

  6. iOS 详细解释@property和@synthesize关键字

    /** 注意:由@property声明的属性 在类方法中通过下划线是获取不到的 必须是通过 对象名.属性 才能获取到!- @property和@synthesize关键字是针对成员变量以及get/se ...

  7. OC中两个关键字的作用:@property和@synthesize

    两个关键字的使用:@property和@synthesize 一.@property关键字这个关键字是OC中能够快速的定义一个属性的方式,而且他可以设置一些值,就可以达到一定的效果,比如引用计数的问题 ...

  8. OC语法5——@property和@synthesize

    @property和@synthesize: 我们回想一下: 在OC中我们定义一个Student类需要两个文件Student.h 和 Student.m. Student.h(声明文件):定义成员变量 ...

  9. Objective-c @property和@Synthesize

    在Objective-c中,使用@property来标识属性(一般是实例变量).在实现文件中使用@synthesize标识所声明的变量,让系统自动生成设置方法和获取方法. 也就是说@property和 ...

随机推荐

  1. 1.Getting Started with ASP.NET MVC 5

    Getting Started Start by installing and running Visual Studio Express 2013 for Web or Visual Studio ...

  2. CentOS系统内核升级

    yum -y update 升级所有包,改变软件设置和系统设置,系统版本内核都升级 yum -y upgrade 升级所有包,不改变软件设置和系统设置,系统版本升级,内核不改变

  3. ArcGIS Engine 连接SQL Server并建立关联

    IWorkspaceFactory  pWFactory=new OLEDBWorkspaceFactory(); IPropertySet  pPropertySet=new  PropertySe ...

  4. Linux信号列表

    我们运行如下命令,可看到Linux支持的信号列表: ~$ kill -l1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL5) SIGTRAP 6) SIGABRT 7) ...

  5. BIRT使用1:简介、概念、元素、报表设计器组成

    前一篇博客对birt进行了一个初探,相信通过上篇博客大家对birt有个初步认识,接下来我们随着下面这张思维导图的展示,进入birt的使用学习. 这一篇博客是第一部分,主要介绍一下birt的简介.概念. ...

  6. 微软嵌入式WEC2013产品研讨会(深圳站---2013.10.16)

    主要内容如下: 1.      Windows Embedded Compact 2013面向的市场 主要面向工业自动化.医疗设备和零售行业这些市场,和物联网关系非常紧密. 2.      Windo ...

  7. 【HDOJ】4366 Successor

    基本思路是将树形结构转换为线性结构.然后,所求即为一个区间内大于abi的最大的loy指向的ID.将结点按照abi降序排序,注意abi可能相等.然后,使用线段树单点更新,区间查询可解. /* 4366 ...

  8. tlplayer 所有平台版本支持水印叠加

    tlplayer支持视频渲染前水印叠加,各个系统版本同样支持. 联系方式:weinyzhou86@gmail.com QQ:514540005 版权所有,禁止转载. 发布自:http://blog.c ...

  9. 新建并保存一个空的Excel

    测试用的 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...

  10. Java [leetcode 21]Merge Two Sorted Lists

    题目描述: Merge two sorted linked lists and return it as a new list. The new list should be made by spli ...