【iOS】Autosynthesized property警告解决方案
来源:互联网 发布:公众号小说收费源码 编辑:程序博客网 时间:2024/06/06 09:19
warning:
Autosynthesized property 'myTimer' will use synthesized instance variable '_myTimer', not existing instance variable 'myTimer'.
我所有在@synthesize 里的变量或者说在@property里面的变量都有这个警告。
Autosynthesized property 'myTimer' will use synthesized instance variable '_myTimer', not existing instance variable 'myTimer'.
我所有在@synthesize 里的变量或者说在@property里面的变量都有这个警告。
在我的.h 文件中我声明了一个成员变量NSTimer *myTimer,同时声明属性
#import <UIKit/UIKit.h>@interface ViewController : UIViewController{ NSTimer *myTimer;}@property (weak,nonatomic) NSTimer *myTimer;@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *mActivityIndicatorView;@property (weak, nonatomic) IBOutlet UIProgressView *progressView;- (IBAction)startToMove:(id)sender;- (IBAction)downloadProgress:(id)sender;@end
并在.m file文件未合成属性时出现
和成熟性 出现如下问题
解决方案:
使用@property定义变量ivar无非三种情况
1)没有合成@synthesized ,则系统会通过Autosynthesized合成一个_ivar
2)如果使用@synthesized ivar;则声称的变量为ivar
3)如果使用@synthesized ivar = _ivar;则声明的变量为_ivar。
如果使用self.ivar则三种定义方法都可以,因为self.ivar是调用的getter方法。
最后,目前Apple推荐的定义方法是第3)种。而且无需在@interface里面再定义变量
最后.m文件
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController@synthesize myTimer=_myTimer;- (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.}- (IBAction)startToMove:(id)sender { if ([self.mActivityIndicatorView isAnimating]) { [self.mActivityIndicatorView stopAnimating]; }else{ [self.mActivityIndicatorView startAnimating]; }}- (IBAction)downloadProgress:(id)sender { myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(download) userInfo:nil repeats:YES];}- (void)download{ self.progressView.progress=self.progressView.progress+0.1; if (self.progressView.progress==1.0) { [myTimer invalidate]; UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"download completed!" message:@" " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil,nil]; [alert show]; }}@end
0 0
- 【iOS】Autosynthesized property警告解决方案
- Autosynthesized property 警告的消除
- IOS开发过程常见警告解决方案归纳总结
- 【iOS开发】一些常见的警告解决方案(更新中。。。)
- IOS警告:Property access result unused - getters should not be used for side effects
- ios 警告
- IOS property
- IOS @property
- IOS @property
- IOS @property
- ios property
- IOS @property
- ios -- @property
- ios -- @property
- ios property
- iOS @property
- 【已解决】iOS程序出现警告:ARC Semantic Issue,Assigning retained object to unsafe property;object will be releas
- 几种非代码警告的解决方案
- Ext3.2 布局——column layout
- RMQ (Range Minimum/Maximum Query)算法
- Android利用百度定位SDK获取当前城市位置
- GetObject
- 4.1函数定义和调用
- 【iOS】Autosynthesized property警告解决方案
- Android中listview内容较多时拖动不流畅问题
- 【Watir Webdriver】自动化上传照片到百度相册
- leetcode Next Permutation
- 混淆的艺术-(苍井空变凤姐)Proguard源码分析(三)Proguard配置解析~上
- 添加文件到Sdcard出现Failed to push selection: Invalid argument问题
- 4.2 函数形参、实参、默认参数
- poj 3100 (zoj 2818)||ZOJ 2829 ||ZOJ 1938 (poj 2249)
- UITableView 滚动流程性优化