在项目中定义了以new开头的textField。结果报错:

先看我的源代码:

#import <UIKit/UIKit.h>

@interface ResetPasswordViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@property (weak, nonatomic) IBOutlet UITextField *oldPasswordTextField;
<span style="color:#FF0000;">@property (weak, nonatomic) IBOutlet UITextField *newPasswordTextField;</span>
@property (weak, nonatomic) IBOutlet UITextField *confirmPasswordTextField;
@property (weak, nonatomic) IBOutlet UINavigationItem *navigationItem; @end

解决的方法:  最简单的方法是改我们定义属性的名字。不要以new、copy、alloc等关键词开头!!。

点击打开链接

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

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

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. Renaming that property:

    @property (strong, nonatomic) NSString *theNewTitle;
  2. 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;
  3. 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

    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.


For the record, Apple have published Transitioning to ARC Release Notes, in which they state:

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

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

Error解决:Property&#39;s synthesized getter follows Cocoa naming convention for returning &#39;owned&#39;的更多相关文章

  1. 小胖说事24-----property&#39;s synthesized getter follows Cocoa naming convention for returning &#39;owned&#39; objec

    今天在给类的属性命名的时候,用了newValue.就给报错:property's synthesized getter follows Cocoa naming convention for retu ...

  2. error: property&#39;s synthesized getter follows Cocoa naming convention for returning &#39;owned&#39; objects

    出现这样的情况,主要是属性名中包括  keyword. You can solve this by: Renaming that property: @property (strong, nonato ...

  3. Property's synthesized getter follows Cocoa naming convention for returning

    Property's synthesized getter follows Cocoa naming convention for returning.   今天早上在整理代码的时候发现了如上警告. ...

  4. JSON: Property 'xxx' has no getter method的解决办法

    在使用JSONArray.fromObject时候出现JSONException:Property 'xxx' has no getter method. 解决办法:设置bean为public属性即可 ...

  5. JSON: property "xxx" has no getter method in class "..."

    Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Pro ...

  6. eclipse maven update error 解决方法

    eclipse  maven  update error 解决方法     本来真不想写这篇博文的,但是eclipse和maven真的是太操蛋了,动不动就出了一些乱七八糟的问题,记录一下.希望公司能早 ...

  7. Ubuntu 16.04 LTS 下安装MATLAB2015b 以及Matlab system error解决办法

    下载MATLAB2015b破解版 操作系统:Ubuntu 16.o4 LTS 程序文件:Matlab2015b-glnxa64破解版 解压提取文件:在ubuntu系统下可以直接提取压缩文件,得到三个文 ...

  8. ibatis-java.lang.RuntimeException: Error setting property 'setFileSize'

    ibatis查询问题:      ibatis-java.lang.RuntimeException: Error setting property 'setFileSize'

  9. Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExce

    Error setting property values ; nested exception is org.springframework.beans.NotWritablePropertyExc ...

随机推荐

  1. 使用ZeppelinHub来存储和展示ZeppelinNoteBook

    0.序 说实在的这个功能太赞了 在一开始接触的时候不知道有这个功能,我尝试做一下配置,发现非常的棒. 棒的原因有两点: 可以在随时随地有互联网的地方访问自己的ZeppelinHub来查看Zeppeli ...

  2. 使用GetInvocationList对委托链进行更多的控制

    委托链中所有项都会被调用,因为委托类型的 Invoke 方法包含了对数组中的所有项进行遍历的代码.这是一个很简单的算法.尽管这个简单的算法足以应付很多情形,但也有它的局限性.例如,除了最后一个返回值, ...

  3. 使用Attiny 85开发板制作BadUSB

    什么是BadUSB?请查看:http://www.baike.com/wiki/BadUSB 或者看看腾讯这个视频!https://v.qq.com/x/page/l01425u2igw.html   ...

  4. fontSpider字蛛,好用的字体压缩工具教程

    一直觉得很多字体特别好看,但是那些好看的字体只能做在图片上不能用CSS样式去实现,作为一个会设计的前端,真心觉得很烦恼,有时候那些文字需要更换,修改起来非常麻烦,要到处去找源文件,找不到源文件还要尽力 ...

  5. 网上干货 ElasticSearch详解与优化设计

    https://blog.csdn.net/joez/article/details/52171199?locationNum=3&fps=1 分析得很好,需要仔细阅读 问题遗留点: Fiel ...

  6. Obsolete---标记方法 类过期

    最近做一个接口的修改,由于是很老的接口,不太了解外部有多少地方引用了它. 但是内部的方法由于业务发展已经不太适合现在的需求,想改又不该动.所以想到了如果设置为过期. Obsolete 属性将某个程序实 ...

  7. 域名转让(bcd.cn,tjcpda.com,jscpda.com,fjcpda.com)

    因本人工作有所调整,现对所拥有的域名全部转让,有需要者请与我联系,谢谢. bcd.cn tjcpda.com jscpda.com fjcpda.com 联系方式: QQ:1181608198 Ema ...

  8. 日期对话框(DatePickerDialog)和时间对话框(TimePickerDialog)

    效果图 布局 <Button android:id="@+id/btn_date" android:text="弹出日期选择对话框" android:la ...

  9. ASP.net获取当前url各种属性(文件名、参数、域名等)的方法

    假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=5&name=kelli "http://"是协议名 "www.te ...

  10. 【sqli-labs】 less33 GET- Bypass AddSlashes (GET型绕过addslashes() 函数的宽字节注入)

    和less32一样,对关键字符进行了添加\ 关于addslashes()函数 payload和less32一样 http://192.168.136.128/sqli-labs-master/Less ...