在项目中定义了以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. Spring Boot (15) pom.xml设置

    继承spring-boot-parent 要成为一个spring boot项目,首先就必须在pom.xml中继承spring-boot-starter-parent,同时制定其版本 <paren ...

  2. Java接口中的成员变量为什么必须声明为public static final?

    我想对于每个Java程序员来说,接口都不陌生,接口中的方法也经常使用.而接口中的成员变量,就显得用得少一点,而对于成员变量为什么必须声明为public static final,可能就更不清楚了,而且 ...

  3. cookie/session在nodes中的实战

    cookie 和 session 众所周知,HTTP 是一个无状态协议,所以客户端每次发出请求时,下一次请求无法得知上一次请求所包含的状态数据,如何能把一个用户的状态数据关联起来呢? 比如在淘宝的某个 ...

  4. Deutsch lernen (04)

    1. streng a. 严厉的,严格的 streng gegen sich selbst und gegen andere sein streng auf Ordnung halten 2. ver ...

  5. C#遍历/反射 属性/字段

    public static string SortParam<T>(T t) { string tStr = string.Empty; if (t == null) { return s ...

  6. js document 触发按键事件

    // 键盘控制 var keyEvent = (function () { document.onkeydown = function (e) { if (e.keyCode === 38) { // ...

  7. 查看占用某端口的进程——netstat、findstr 的使用

    netstat   检验本机各端口的网络连接情况 -a 显示所有连接和侦听端口(如Windows共享服务 的135,445端口) -n 不进行IP地址到主机名的解析 -o 显示拥有的与每个连接关联的进 ...

  8. 【转】虚拟化(五):vsphere高可用群集与容错

    vsphere高级功能需要vcenter server和共享存储的支持才能实现.vsphere的高级功能有 vmotion.storage vmotion.vsphere HA.vsphere DRS ...

  9. Django MVC与MTV概念 Ajax、分页实现

     MVC与MTV概念 MTV与MVC(了解)        MTV模型(django):            M:模型层(models.py)            T:templates      ...

  10. lua_自己对“lua函数”知识点的总结

    lua_自己对“lua函数”知识点的总结 1.lua函数的定义 --lua中,函数都是function类型的对象.(1)其可以被比较 (2)其可以赋值给一个对象(3)可以传递给函数(4)可以从函数中返 ...