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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:29:57  来源:igfitidea点击:

Synthesis of weak property only allowed in arc or gc mode

iosobjective-c

提问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 IBOutletreferences in non-ARC code, replace your references to weakwith retain, instead. (It's a little confusing, but generally you use assignrather than weakin non-ARC code, but for IBOutletreferences, you use retain.)

如果您不使用 ARC,则不能使用weak. 对于IBOutlet非ARC代码引用,更换你的引用weakretain,来代替。(这有点令人困惑,但通常您在非 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 答案。

Properties and Instance Variables in Objective-C

Objective-C 中的属性和实例变量