首页 \ 问答 \ 使用@property和'copy'属性分配NSMutableArray(assign NSMutableArray with @property and 'copy' attribute)

使用@property和'copy'属性分配NSMutableArray(assign NSMutableArray with @property and 'copy' attribute)

我正在关注官方教程你的第二个iOS应用程序:Storyboard ,它告诉我像这样声明一个属性masterBirdSightingList (只是一个特定的例子,不需要知道上下文):

@property (nonatomic, copy) NSMutableArray *masterBirdSightingList;

请注意,有一个属性副本 。 然后合成这个属性:

@synthesize masterBirdSightingList = _masterBirdSightingList;

接下来有一个让我困惑的init方法:

- (void)initializeDefaultDataList {
NSMutableArray *sightingList = [[NSMutableArray alloc] init];
self.masterBirdSightingList = sightingList;
[self addBirdSightingWithName:@"Pigeon" location:@"Everywhere"];
}

绝对是为空间分配了sightingList,然后将它分配给masterBirdSightingList属性。 但是,该属性具有复制属性。 这意味着实例变量_masterBirdSightingList将被分配给另一个空间以保存来自sightingList的东西。 为什么? 为什么不直接为属性分配空间,如下所示:

self.masterBirdSightingList = [[NSMutableArray alloc] init];

I'm following an official tutorial Your second iOS App:Storyboard and it told me to declare a property masterBirdSightingList like this(just a specific example and not necessary to know the context) :

@property (nonatomic, copy) NSMutableArray *masterBirdSightingList;

Note that there's an attribute copy. and then synthesize this property :

@synthesize masterBirdSightingList = _masterBirdSightingList;

And next there's one init method which made me confused :

- (void)initializeDefaultDataList {
NSMutableArray *sightingList = [[NSMutableArray alloc] init];
self.masterBirdSightingList = sightingList;
[self addBirdSightingWithName:@"Pigeon" location:@"Everywhere"];
}

Definitely sightingList is allocated for spaces and then it's assigned to the masterBirdSightingList property. The property has a copy attribute, though. it means the instance variable _masterBirdSightingList would be allocated for another space to preserve stuffs from sightingList. Why? Why not directly allocate space for the property like this :

self.masterBirdSightingList = [[NSMutableArray alloc] init];

原文:https://stackoverflow.com/questions/10724866
更新时间:2019-10-14 05:06

最满意答案

这显示了每个affyId的平均值:

SELECT affyId, AVG(level) AS average FROM Data GROUP BY affyId

这是每个exptId的平均值:

SELECT exptId, AVG(level) AS average FROM Data GROUP BY exptId

这是每个affyId中每个exptId的平均值:

SELECT affyId, exptId, AVG(level) AS average FROM Data GROUP BY exptId, affyId

This shows the average for every affyId:

SELECT affyId, AVG(level) AS average FROM Data GROUP BY affyId

This the average for every exptId:

SELECT exptId, AVG(level) AS average FROM Data GROUP BY exptId

and this the average for every exptId in every affyId:

SELECT affyId, exptId, AVG(level) AS average FROM Data GROUP BY exptId, affyId

相关问答

更多
  • 你不能直接从MySQL创建一个二维数组 - 但是,你可以在php中准备你的数据。 查询看起来有点像: SELECT user_id, question_id, AVG(rating_value) AS average_rating FROM ratings GROUP BY user_id, question_id ORDER BY user_id 像这样你应该得到如下结果: user_id | question_id | average_rating 1 | 1 ...
  • 在达到平均值后,您将获得限制。 子查询的正确形式是: (select avg(Positive) from (SELECT t2.`Positive` FROM `tbl_DATA_KeywordResults` as t2 WHERE t2.`DateTime` <= t1.`DateTime` ORDER BY t2.`DateTime` DESC LIMIT 96 ) t ) AS `DailyAverage` 我不是100%确 ...
  • 这显示了每个affyId的平均值: SELECT affyId, AVG(level) AS average FROM Data GROUP BY affyId 这是每个exptId的平均值: SELECT exptId, AVG(level) AS average FROM Data GROUP BY exptId 这是每个affyId中每个exptId的平均值: SELECT affyId, exptId, AVG(level) AS average FROM Data GROUP BY exptI ...
  • 可能有太多解决方案,具体取决于业务逻辑以及您希望如何呈现它。 1)将time字段分配到date和time ,然后按date分组: SELECT AVG(sz.occupied), AVG(sz.free), date, time FROM `hourly_cache` AS sz WHERE (sz.date >= '2017-01-01' AND sz.date < '2017-01-07') AND HOUR(sz.time) BETWEEN 8 AND 22 AND libID = ...
  • 如果我正确理解您的问题,您希望对日和小时的所有组合运行上述查询。 此查询提供所有此类组合。 SELECT ds, LPAD (hrs, 2, '0') hrs FROM ( SELECT LEVEL ds FROM DUAL CONNECT BY LEVEL <= 7), ( SELECT LEVEL - 1 hrs FROM DUAL CONNECT BY LE ...
  • 我相信这样做会: SELECT AVG(Load_transit) , AVG(load_standby) , (AVG(Load_transit) + AVG(load_standby))/2.0 FROM table AVG()函数处理NULL,因为它忽略它们,如果你想在你的分母中计算NULL行,你可以用COUNT(*)替换带有SUM() AVG() COUNT(*) ,即: SUM(load_transit)/COUNT(*) 关于可扩展性,如上所述手动列出它们可能是最简 ...
  • 是的,它可以在MySQL中完成。 我认为它甚至可以作为SELECT语句来做(但这将非常复杂,难以维护并且可能非常慢)。 既然您目前还不确定是否可以在MySQL中执行此操作并且在此处询问,我建议使用PHP实现解决方案可能会更好地利用您的时间 - 您可以从答案中剪切和粘贴代码,这可能会出现给出正确的结果,但您是否能够评估解决方案的细微差别? 你能在破裂时修好它吗? 升级它以适应新功能? 如果是我,我会使用MySQL程序将其实现为有限状态机 (实际上是3个FSM,每个条件一个)。 你没有说出满足条件时你应该做什么 ...
  • 第一个SELECT真的有必要吗? SELECT AVG(time) FROM ( SELECT UNIX_TIMESTAMP(max(datelast)) - UNIX_TIMESTAMP(min(datestart)) AS time FROM table WHERE product_id = 12394 AND datelast > '2011-04-13 00:26:59' GROUP BY id ) 我现在无法测试,我认为它也会起作用。 否则, ...
  • 好吧,这是一个非常疯狂的猜测,你是在这个请求之后: select COUNT(distinct pd.property_id) AS `Beginning Total File Count`, COUNT(pd.recv_dt) as `average days in inventory`, AVG(IF(pd.status = 'P', 1,0)) as `average days in pre-marketing`, AVG(IF(pd.status NOT IN('I','C'), 1,0)) as ...
  • 获取您想要的部分日期(在您的情况下为年份和月份)并在此基础和货币上分组结果: SELECT DATE_FORMAT(rate_date,'%M, %Y') AS rate_month,currency_pair,AVG(rate) AS avg_rate FROM historical_currencies_rate WHERE currency_pair='EUR-USD' GROUP BY DATE_FORMAT(rate_date,'%M, %Y'),currency_pair ORDER BY r ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)