使用@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
最满意答案
这显示了每个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%确 ...
-
MySQL查询平均值(MySQL Query for averages)[2023-04-17]
这显示了每个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 ...