合成的目的

编程入门 行业动态 更新时间:2024-10-11 03:17:10
本文介绍了合成的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用iOS5书来学习iOS编程。

I am using an iOS5 book to learn iOS programming.

@synthesize coolWord;

^ synthesize用于.m文件中的所有属性

^synthesize is used for all properties in .m files

我听说在iOS6中不需要合成,因为它是自动完成的。这是真的吗?

I heard that in iOS6 there is no need for synthesize, since it is automatically done for you. Is this true?

合成是否会为iOS6扮演任何角色?

Does synthesize play any role for iOS6?

感谢您的澄清。 :)

推荐答案

在objective-c中的@synthesize只实现属性设置器和getter:

@synthesize in objective-c just implements property setters and getters:

- (void)setCoolWord:(NSString *)coolWord { _coolWord = coolWord; } - (NSString *)coolWord { return _coolWord; }

Xcode 4的确适用于此(iOS6需要Xcode) 4)。从技术上讲,它实现了 @synthesize coolWord = _coolWord ( _coolWord 是实例变量而 coolWord 是属性)。

It is true with Xcode 4 that this is implemented for you (iOS6 requires Xcode 4). Technically it implements @synthesize coolWord = _coolWord (_coolWord is the instance variable and coolWord is the property).

要访问这些属性,请使用 self.coolWord 进行设置 self.coolWord = @YEAH!; 并获得 NSLog(@%@,self.coolWord);

To access these properties use self.coolWord both for setting self.coolWord = @"YEAH!"; and getting NSLog(@"%@", self.coolWord);

另请注意,setter和getter仍然可以手动实现。如果你同时实现了setter和getter,你还需要手动包含 @synthesize coolWord = _coolWord; (不知道为什么会这样)。

Also note, both the setter and getter can still be manually implemented. If you implement BOTH the setter and getter though you NEED to also manually include @synthesize coolWord = _coolWord; (no idea why this is).

更多推荐

合成的目的

本文发布于:2023-11-25 21:15:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631372.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目的

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!