Error解决:Property's synthesized getter follows Cocoa naming convention for returning 'owned'
在项目中定义了以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:
Renaming that property:
@property (strong, nonatomic) NSString *theNewTitle;
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;
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 thenone
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;
@endNote 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
orcopy
.
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's synthesized getter follows Cocoa naming convention for returning 'owned'的更多相关文章
- 小胖说事24-----property's synthesized getter follows Cocoa naming convention for returning 'owned' objec
今天在给类的属性命名的时候,用了newValue.就给报错:property's synthesized getter follows Cocoa naming convention for retu ...
- error: property's synthesized getter follows Cocoa naming convention for returning 'owned' objects
出现这样的情况,主要是属性名中包括 keyword. You can solve this by: Renaming that property: @property (strong, nonato ...
- Property's synthesized getter follows Cocoa naming convention for returning
Property's synthesized getter follows Cocoa naming convention for returning. 今天早上在整理代码的时候发现了如上警告. ...
- JSON: Property 'xxx' has no getter method的解决办法
在使用JSONArray.fromObject时候出现JSONException:Property 'xxx' has no getter method. 解决办法:设置bean为public属性即可 ...
- JSON: property "xxx" has no getter method in class "..."
Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Pro ...
- eclipse maven update error 解决方法
eclipse maven update error 解决方法 本来真不想写这篇博文的,但是eclipse和maven真的是太操蛋了,动不动就出了一些乱七八糟的问题,记录一下.希望公司能早 ...
- Ubuntu 16.04 LTS 下安装MATLAB2015b 以及Matlab system error解决办法
下载MATLAB2015b破解版 操作系统:Ubuntu 16.o4 LTS 程序文件:Matlab2015b-glnxa64破解版 解压提取文件:在ubuntu系统下可以直接提取压缩文件,得到三个文 ...
- ibatis-java.lang.RuntimeException: Error setting property 'setFileSize'
ibatis查询问题: ibatis-java.lang.RuntimeException: Error setting property 'setFileSize'
- Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExce
Error setting property values ; nested exception is org.springframework.beans.NotWritablePropertyExc ...
随机推荐
- HBase的集群搭建(1、3、5节点都适用)
见 5 hbase-shell + hbase的java api
- HTML简单入门
- Java攻城狮学习路线 - 基本结构 标准文档:www.w3.org <!DOCTYPE html> <html> <head> <meta charse ...
- VHDL之concurrent之block
1 Simple BLOCK The simple block represents only a way of partitioning the code. It allows concurrent ...
- 三维重建:多点透视cvSolvePNP的替代函数(Code)
在调试JNI程序时,所有的Shell都已经加载完成,而唯一真正核心的cv::SolvePnP却不能在JNI里面获得通行证,经过反复测试都不能运行,因此只能忍痛舍弃,自行编写一个具有相 ...
- 我的web前端自学之路-心得篇:我为什么要学习web前端?
时光如流水,转眼间,自己已经是大三的学长了,看着一个个学弟学妹,心中有种莫名的感觉,很怀念大学的前两年时光,但也很憧憬着自己的未来,自己将要去经历很多从未经历的事.我是我们学校信科院的一名学生,在编程 ...
- 我的C++笔记(数据的共享与保护)
*数据的共享与保护: * .作用域: * 作用域是一个标识符在程序正文中有效的区域.C++中标识符的作用域有函数原型作用域.局部作用域(块作用域).类作用域和命名空间作用域. * ().函数原型作用域 ...
- (转) OpenLayers3基础教程——OL3 介绍control
http://blog.csdn.net/gisshixisheng/article/details/46761535 概述: 本文讲述的是Ol3中的control的介绍和应用. OL2和OL3 co ...
- 前端工具gulp
最近在写一个新的项目,用到了新框架,主要是:react+webpack.里面还用到了一个前端工具——gulp. gulp在项目里的作用是打包静态资源.编译less,压缩css等.js并不在处理之列(不 ...
- 【转载】Jsp页面传Json数据到服务端,转对象或集合进行数据处理
需求:1.将页面数据带到服务端并转成对象,2.将页面的集合数据带到服务端转List实现:用ajax请求传递数据,数据格式为json JS方法: testJsonMethod = function(){ ...
- PAT_A1034#Head of a Gang
Source: PAT A1034 Head of a Gang (30 分) Description: One way that the police finds the head of a gan ...