使用@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

相关问答

更多

将返回多个平均值的SQL查询(SQL query that will return multiple averages)

你不能直接从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 ...

MySQL:同一查询中有两个移动平均线?(MySQL: Two moving averages in the same query?)

在达到平均值后,您将获得限制。 子查询的正确形式是: (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` 我不是...

MySQL查询平均值(MySQL Query for averages)

这显示了每个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 ...

MySQL,获取一周中所有日子的平均值(MySQL, get averages for all days of the week)

可能有太多解决方案,具体取决于业务逻辑以及您希望如何呈现它。 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 lib...

Sql查询查找过去值的平均值(Sql query to find averages of past values)

如果我正确理解您的问题,您希望对日和小时的所有组合运行上述查询。 此查询提供所有此类组合。 SELECT ds, LPAD (hrs, 2, '0') hrs FROM ( SELECT LEVEL ds FROM DUAL CONNECT BY LEVEL <= 7), ( SELECT LEVEL - 1 hrs FROM DUAL CONNECT ...

MySQL - 获得所有列平均值也具有“总”平均值(MySQL - get all column averages also with a 'total' average)

我相信这样做会: 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查询,基于条件的行平均值(Single MySQL query with row averages based on conditions)

是的,它可以在MySQL中完成。 我认为它甚至可以作为SELECT语句来做(但这将非常复杂,难以维护并且可能非常慢)。 既然您目前还不确定是否可以在MySQL中执行此操作并且在此处询问,我建议使用PHP实现解决方案可能会更好地利用您的时间 - 您可以从答案中剪切和粘贴代码,这可能会出现给出正确的结果,但您是否能够评估解决方案的细微差别? 你能在破裂时修好它吗? 升级它以适应新功能? 如果是我,我会使用MySQL程序将其实现为有限状态机 (实际上是3个FSM,每个条件一个)。 你没有说出满足条件时你...

Mysql优化查询:尝试获取子查询的平均值(Mysql Optimize Query: Trying to Get Average of Subquery)

第一个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 ) 我现在无法测试,我认为它也会起作用...

MySQL:获取计数和平均值[重复](MySQL: Get Counts and Averages [duplicate])

好吧,这是一个非常疯狂的猜测,你是在这个请求之后: 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...

MySQL查询获取每个月数据的平均值数组(MySQL query to get array of averages of each month's data)

获取您想要的部分日期(在您的情况下为年份和月份)并在此基础和货币上分组结果: 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...

相关文章

更多

could not find system property or JNDI

Thanks everyone!! Finally got a solution for this p ...

Cannot expose request attribute 'website' because of an existing model object of the same name 的解决方案

在使用springmvc+freemarker,有可能你会遇到以下异常(如:资源找不到重定向到404的 ...

mybatis There is no getter for property named 'xx' in 'class java.lang.String

用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no get ...

java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute 的解决方案

把后台管理系统重新写了一下,登录的时候提示,java.lang.IllegalArgumentExce ...

页面获取ACTION的属性,页面不能弹出JS

action定义一个属性,get set后 对属性赋值,值是JS,页面用&lt;s:property/ ...

移动设备类

&lt;?php/** * MIT License * =========== * * Permiss ...

Nutch Job failed异常

truncate(分段方式)的页面,nutch的默认设置是不处理这种方式的,需要修改conf/nutc ...

nutch + solr —— 搭建初探

一. 环境: apache-nutch-1.8 solr-4.7.0 二. nutch配置提示: 1. ...

[032] 微信公众帐号开发教程第8篇-文本消息中使用网页超链接(转)

本文主要介绍网页超链接的作用以及怎样在文本消息中使用网页超链接。 网页超链接的作用 我想但凡是熟悉HT ...

JavaMelody系统性能监控

JavaMelody的项目地址:https://code.google.com/p/javamelod ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本