【iOS開發筆記23/50】使用ARC時,如果不加strong,有時會給出警告


最近將代碼轉換成ARC內存管理方式,用Edit菜單中的Refactor可以完成自動轉換,還是非常方便,但馬上編譯后會給出警告。

assigning retained object to unsafe property, object will be released after assignment.

錯誤出現在對window和navController上。

@interface MyViewerAppDelegate : UIResponder <UIApplicationDelegate>
@property ( nonatomic) UIWindow *window;
//主窗口上要出現導航欄
@property ( nonatomic) UINavigationController *navController;
@end

按理說,默認是strong類型,不需要加上strong,但這時編譯器就是給出警告,所以為了不讓編譯器發出煩人的警告,還是手動把strong加上。

@interface MyViewerAppDelegate : UIResponder <UIApplicationDelegate>
@property ( nonatomic, strong) UIWindow *window;
//主窗口上要出現導航欄
@property ( nonatomic, strong) UINavigationController *navController;
@end


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM