如何做一个(非原子,强)财产的寿命在iOS的工作? [英] How does a (nonatomic, strong) property's lifespan work in iOS?

查看:146
本文介绍了如何做一个(非原子,强)财产的寿命在iOS的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个属性声明为: @属性(非原子,强)的NSArray * menuArr; @财产(强)的NSArray * menuArr; 并设置 viewDidLoad中此属性。多久设备的记得我已经存储在阵列中的信息?

Say I have a property declared as : @property (nonatomic, strong) NSArray *menuArr; OR @property (strong) NSArray *menuArr; and set this property in viewDidLoad. How long will the device "remember" the information I have stored in the array?

该酒店在声明和嵌入在一个navigationViewController本身就是一个TabBarViewController的第一个视图控制器的viewController设置。换句话说它的第一个视图,用户可以看到那么他们可以导航远离它和背部。

The property is declared and set in a viewController that is embedded in a navigationViewController that is itself the first view controller in a TabBarViewController. In other words its the first view the user sees then they may navigate away from it and back.

没有进入过的原子VS非原子辩论,我的问题是这样的。

Without getting into a debate over atomic vs nonatomic my question is this

难道一个属性(申报两种方式),生活在无限的iOS的环境或者它的寿命的因素,如时间的限制,内存使用情况在其他地方,关闭设备,等等

为了避免这种情况作为一个x和y的问题,这里就是为什么林问:

进出口工作在包括分为多个类别,每个类别的几个项目的菜单.....正如你所预料的菜单是一个应用程序。所有的菜单项被存储在parse.com。起初我在每个页面上做一个独立的PFQuery,一个类别页面上获得的类别,当用户选择一个类别一个新的页面被压和第二PFQuery了所选类别中的所有项目。这工作,但页面花了相当长一段时间来加载,大概10-15秒有时有没有真正的迹象表明,应用说好的只是冻结了。

Im working on an app that includes a menu broken up into multiple categories with several items in each category .....as you might expect a menu to be. All of the menu items are stored on parse.com. At first I was doing a separate PFQuery on each page, one on the categories page to get the categories, when user selects a category a new page is pushed and a second PFQuery got all the items in the chosen category. This worked but the pages took quite a while to load, probably 10-15 seconds sometimes with no real indication that the app hadnt just frozen up.

要解决这个问题,我决定运行一个PFQuery当应用程序的第一个视图中的 viewDidLoad中加载获得所有菜单项和排序扑进嵌套阵列包含的项目类别。然后,我在存储上的viewController属性菜单阵列。后来,当我去到菜单我有下面在它的 viewDidLoad中

To fix this I decided to run one PFQuery when the first view of the app is loaded in viewDidLoad getting all of the menu items and sorting the myself into nested arrays of categories containing items. I then store the menu array in a property on the viewController. Later, when I go to the menu I have the below in it's viewDidLoad:

//get e reference to the first view controller, the one that has the menu array 
FirstViewController *myVC1ref = (FirstViewController *)[[[self.navigationController.tabBarController.viewControllers objectAtIndex:0] viewControllers]  objectAtIndex:0];

//set thisviewController's `menuArr` property to point to the menuArr on the first viewController.

_menuArr=myVC1ref.menuArr;

我的理解是,这将创建一个指向原始数组,并不实际创建第二个阵列(请纠正我,如果我错了)。

My understanding is that this creates a pointer to the original array and does not actually create a second array (please correct me if Im wrong).

此方法需要大约10-15秒加载和排序的数组,有一次,但随后页面之间的导航是即时之后这是好多了。

This method takes about 10-15 seconds to load and sort the array that one time but then navigation between pages is instant after that which is much better.

我打算做查询的地方,看是否有菜单项已被更改,如果是的话重新下载和排序菜单。

I plan to do queries in places to see if any menu items have been changed and if so re-download and sort the menu.

但必须有一些限制,对吗?

So far in my testing the app seems to remember the info in the array just fine throughout the day with normal unrelated phone usage but there has to be some limits to that right?

推荐答案

您的应用程序的内存空间仍将只要你的应用程序的有效运行。该系统是不会从你下的任意可用内存了。怎么可能您的应用程序功能可能这样?类型和属性的属性,在这个水平上绝对没有任何关联。

Your app's memory space will remain valid as long as your app is running. The system is not going to arbitrarily free memory out from under you. How could your app possibly function like that? The type and attributes of the property have absolutely no relevance at this level.

一个低内存从系统的警告是,你的请求手动的释放内存,你不需要。该应用程序的内存要么是完全因为你离开它,或者移动到背景,然后被终止,一个空白的石板后。如果您有需要生存你的程序退出的数据,你需要做出规定,把它保存到磁盘并重新读取。

A low memory warning from the system is a request that you manually free up memory that you don't need. The app's memory will either be completely as you left it, or, after moving to the background and then being terminated, a blank slate. If you have data that needs to survive your program exiting, you need to make provisions to save it to disk and read it back.

iOS版<一个href=\"https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/State$p$pservation/State$p$pservation.html#//apple_ref/doc/uid/TP40007072-CH11-SW5\"相对=nofollow>确实有一些技巧,以preserve和恢复应用程序的状态,但仍然只适用于终止应用程序。

iOS does have some tricks to preserve and restore your app's state, but that still only applies to a terminated application.

这篇关于如何做一个(非原子,强)财产的寿命在iOS的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆