<legend id='cPYgk'><style id='cPYgk'><dir id='cPYgk'><q id='cPYgk'></q></dir></style></legend>

<small id='cPYgk'></small><noframes id='cPYgk'>

  • <i id='cPYgk'><tr id='cPYgk'><dt id='cPYgk'><q id='cPYgk'><span id='cPYgk'><b id='cPYgk'><form id='cPYgk'><ins id='cPYgk'></ins><ul id='cPYgk'></ul><sub id='cPYgk'></sub></form><legend id='cPYgk'></legend><bdo id='cPYgk'><pre id='cPYgk'><center id='cPYgk'></center></pre></bdo></b><th id='cPYgk'></th></span></q></dt></tr></i><div id='cPYgk'><tfoot id='cPYgk'></tfoot><dl id='cPYgk'><fieldset id='cPYgk'></fieldset></dl></div>

  • <tfoot id='cPYgk'></tfoot>
    • <bdo id='cPYgk'></bdo><ul id='cPYgk'></ul>

        语义问题:属性的合成 getter 遵循 Cocoa 命名约定以

        时间:2023-06-01

        • <i id='gA0PW'><tr id='gA0PW'><dt id='gA0PW'><q id='gA0PW'><span id='gA0PW'><b id='gA0PW'><form id='gA0PW'><ins id='gA0PW'></ins><ul id='gA0PW'></ul><sub id='gA0PW'></sub></form><legend id='gA0PW'></legend><bdo id='gA0PW'><pre id='gA0PW'><center id='gA0PW'></center></pre></bdo></b><th id='gA0PW'></th></span></q></dt></tr></i><div id='gA0PW'><tfoot id='gA0PW'></tfoot><dl id='gA0PW'><fieldset id='gA0PW'></fieldset></dl></div>

          1. <small id='gA0PW'></small><noframes id='gA0PW'>

          2. <legend id='gA0PW'><style id='gA0PW'><dir id='gA0PW'><q id='gA0PW'></q></dir></style></legend>

                <bdo id='gA0PW'></bdo><ul id='gA0PW'></ul>

                    <tbody id='gA0PW'></tbody>
                  <tfoot id='gA0PW'></tfoot>

                1. 本文介绍了语义问题:属性的合成 getter 遵循 Cocoa 命名约定以返回“拥有"对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我目前正在使用 iOS 5 SDK 尝试开发我的应用程序.我正在尝试使 NSString 成为属性,然后在 .m 文件中合成它(我之前已经这样做了,没有任何问题).现在,我遇到了这个问题:语义问题:属性的合成 getter 遵循 Cocoa 命名约定以返回‘拥有’对象."

                  I'm currently using the iOS 5 SDK trying to develop my app. I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects."

                  这是我的代码:.h

                  @interface ViewController : UIViewController {
                       NSString *newTitle;
                  }
                  @property (strong, nonatomic) NSString *newTitle;
                  

                  .m

                  @synthesize newTitle;
                  

                  有人知道我该如何解决这个问题吗?谢谢!!

                  Does anyone have a clue how I could fix this? Thanks!!

                  推荐答案

                  我猜你使用的编译器版本如下 内存管理规则 用于声明的属性——更具体地说,用于声明的属性的访问器:

                  My guess is that the compiler version you’re using follows the memory management rules for declared properties, too — more specifically, for declared properties’ accessors:

                  如果您使用名称以alloc"、new"、copy"或mutableCopy"开头的方法创建对象,您将获得该对象的所有权.

                  You take ownership of an object if you create it using a method whose name begins with "alloc", "new", "copy", or "mutableCopy".

                  一个名为 newTitle 的属性在合成时会产生一个名为 -newTitle 的方法,因此会出现警告/错误.-newTitle 应该是 newTitle 属性的 getter 方法,但是命名约定规定名称以 new 开头的方法返回一个对象它归调用者所有,而 getter 方法则不然.

                  A property named newTitle, when synthesised, yields a method called -newTitle, hence the warning/error. -newTitle is supposed to be a getter method for the newTitle property, however naming conventions state that a method whose name begins with new returns an object that’s owned by the caller, which is not the case of getter methods.

                  您可以通过以下方式解决此问题:

                  You can solve this by:

                  1. 重命名该属性:

                  1. Renaming that property:

                  @property (strong, nonatomic) NSString *theNewTitle;
                  

                2. 保留属性名称并指定不以特殊方法名称前缀之一开头的 getter 名称:

                3. Keeping the property name and specifying a getter name that doesn’t begin with one of the special method name prefixes:

                  @property (strong, nonatomic, getter=theNewTitle) NSString *newTitle;
                  

                4. 同时保留属性名和getter名,并告诉编译器,即使getter名以new开头,它也属于nonenew 方法族相对的方法族:

                5. Keeping both the property name and the getter name, and telling the compiler that, even though the getter name starts with new, it belongs to the none method family as opposed to the new method family:

                  #ifndef __has_attribute
                  #define __has_attribute(x) 0  // Compatibility with non-clang compilers
                  #endif
                  
                  #if __has_attribute(objc_method_family)
                  #define BV_OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
                  #else
                  #define BV_OBJC_METHOD_FAMILY_NONE
                  #endif
                  
                  @interface ViewController : UIViewController
                  @property (strong, nonatomic) NSString *newTitle;
                  - (NSString *)newTitle BV_OBJC_METHOD_FAMILY_NONE;
                  @end
                  

                  请注意,即使此解决方案允许您将 newTitle 保留为属性名称和 getter 名称,但有一个名为 -newTitle 的方法不会返回调用者拥有的对象可能会让其他阅读您的代码的人感到困惑.

                  Note that even though this solution allows you to keep newTitle as both the property name and the getter name, having a method called -newTitle that doesn’t return an object owned by the caller can be confusing for other people reading your code.

                  <小时>

                  作为记录,Apple 已发布 Transitioning到 ARC 发行说明,他们在其中声明:

                  您不能为属性指定以 newcopy 开头的名称.

                  You cannot give a property a name that begins with new or copy.

                  他们已经被告知他们的陈述不太准确:罪魁祸首是 getter 方法名称,而不是属性名称.

                  They’ve already been notified that their statement is not quite accurate: the culprit is the getter method name, not the property name.

                  2015 年 1 月 17 日我刚刚注意到一个 最近对 Clang 的提交建议上面的选项 3(使用 objc_method_family(none)),包括一个修复它,用于属性名称与特殊方法系列前缀之一匹配的一般情况.Xcode 最终可能会包含此更改.

                  Edit 17 Jan 2015: I’ve just noticed a recent commit to Clang that suggests option 3 above (using objc_method_family(none)), including a fix-it, for the general case where a property name matches one of the special method family prefixes. Xcode will likely incorporate this change eventually.

                  这篇关于语义问题:属性的合成 getter 遵循 Cocoa 命名约定以返回“拥有"对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                6. 上一篇:试图在视图控制器之间传递数据 下一篇:NSManagedObjectContext 的 performBlock: 是做什么用的?

                  相关文章

                  最新文章

                7. <i id='mCRWv'><tr id='mCRWv'><dt id='mCRWv'><q id='mCRWv'><span id='mCRWv'><b id='mCRWv'><form id='mCRWv'><ins id='mCRWv'></ins><ul id='mCRWv'></ul><sub id='mCRWv'></sub></form><legend id='mCRWv'></legend><bdo id='mCRWv'><pre id='mCRWv'><center id='mCRWv'></center></pre></bdo></b><th id='mCRWv'></th></span></q></dt></tr></i><div id='mCRWv'><tfoot id='mCRWv'></tfoot><dl id='mCRWv'><fieldset id='mCRWv'></fieldset></dl></div>

                    <tfoot id='mCRWv'></tfoot>
                  1. <small id='mCRWv'></small><noframes id='mCRWv'>

                      <bdo id='mCRWv'></bdo><ul id='mCRWv'></ul>
                    <legend id='mCRWv'><style id='mCRWv'><dir id='mCRWv'><q id='mCRWv'></q></dir></style></legend>