ios 弱属性的合成只允许在 arc 或 gc 模式下
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15150447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Synthesis of weak property only allowed in arc or gc mode
提问by Nik
Hey i just start ios programming today and i am facing this erro.
嘿,我今天刚开始 ios 编程,我正面临这个错误。
plz help me to remove this error
请帮我消除这个错误
plz suggest me some nice ios developer tutorial
请给我推荐一些不错的 ios 开发者教程
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *txtUsername;
@property (weak, nonatomic) IBOutlet UITextField *txtPassword;
- (IBAction)loginClicked:(id)sender;
- (IBAction)backgroundClick:(id)sender;
@end
采纳答案by nneonneo
If you're just starting off, you should just enable ARC. It will save you a lot of headaches, and it will resolve that issue.
如果你刚刚开始,你应该只启用 ARC。它将为您省去很多麻烦,并且可以解决该问题。
回答by Rob
If you're not using ARC, you cannot use weak
. For IBOutlet
references in non-ARC code, replace your references to weak
with retain
, instead. (It's a little confusing, but generally you use assign
rather than weak
in non-ARC code, but for IBOutlet
references, you use retain
.)
如果您不使用 ARC,则不能使用weak
. 对于IBOutlet
非ARC代码引用,更换你的引用weak
与retain
,来代替。(这有点令人困惑,但通常您在非 ARC 代码中使用assign
而不是weak
,但对于IBOutlet
引用,您使用retain
.)
Better yet, as nneonneo suggests, you should use ARC.
更好的是,正如 nneonneo 建议的那样,您应该使用 ARC。
回答by Only You
You can read this web page http://designthencode.com/scratch/to start learning iOS programming.
你可以阅读这个网页http://designthencode.com/scratch/开始学习 iOS 编程。
It is a very good introduction to many of the elements involved in writing an app for iPhone.
它很好地介绍了为 iPhone 编写应用程序所涉及的许多元素。
Refer this stackoverflow answer below for your issue with property declaration.
有关属性声明的问题,请参阅下面的此 stackoverflow 答案。