NSMutableArray更改为副本,从而导致父NSMutableArray中的更改(NSMutableArray changes to the copy causing changes in the parent NSMutableArray as well)

我有一个NSMutableArray是我在我的一个视图控制器中使用的委托。

所以在viewDidLoad中,我像这样制作了一个NSMutableArray的可变副本

@implementation ItemsViewController{
    AppDelegate *mydelegate;
    NSMutableArray* allItems;
}

在viewDidLoad中

allItems = [mydelegate.array mutableCopy];

现在我在allItems中做出的任何变化MutableArray也会导致我的mydelegate.array发生变化。 难道我做错了什么?

委托中的我的数组也定义如下

@property (nonatomic, strong) NSMutableArray *array;

I have a NSMutableArray is my delegate that I am using in one of my view controllers as well.

So in viewDidLoad I make a mutable copy of my NSMutableArray like this

@implementation ItemsViewController{
    AppDelegate *mydelegate;
    NSMutableArray* allItems;
}

In viewDidLoad

allItems = [mydelegate.array mutableCopy];

Now whatever changes I make in my allItems MutableArray also cause changes in my mydelegate.array. Am I doing something wrong?

Also my array in the delegate is defined as follows

@property (nonatomic, strong) NSMutableArray *array;

原文:https://stackoverflow.com/questions/19785427
2022-11-15 15:11

满意答案

分区外连接可以帮助填写日历数据。 它类似于交叉连接,但对于非平凡的表大小可能表现更好。

交叉连接将连接集合A中的每一行与集合B中的每一行。

分区外连接将连接集合A中的每一行与集合B中的每个已定义子集。

以下示例仅根据您提供的计划数据生成日期范围。 因此,第14和第15不会出现,但这很容易修复。

with schedules as
(
    --Schedule data.
    select 'bottle washer' position, 'Fred'   name, date '2013-01-02' startdate, date '2013-01-05' enddate from dual union all
    select 'bottle washer' position, 'Barney' name, date '2013-01-04' startdate, date '2013-01-07' enddate from dual union all
    select 'bottle washer' position, 'Betty'  name, date '2013-01-10' startdate, null              enddate from dual union all
    select 'bottle washer' position, 'Wilma'  name, date '2013-01-12' startdate, date '2013-01-13' enddate from dual union all
    select 'cook'          position, 'Bilbo'  name, date '2013-01-01' startdate, date '2013-01-03' enddate from dual union all
    select 'cook'          position, 'Frodo'  name, date '2013-01-05' startdate, date '2013-01-08' enddate from dual union all
    select 'cook'          position, 'Bilbo'  name, date '2013-01-07' startdate, null              enddate from dual
),
dates as
(
    --Date range, based on schedule data.
    select first_startdate + level - 1 the_date
    from
    (
        select min(startdate) first_startdate
            ,(max(enddate) - min(startdate))+1 date_diff
        from schedules
    )
    connect by level <= date_diff
)
--Count of staff working per position, per day.
select position, the_date, count(schedules.startdate) staffing
from dates
left join schedules partition by (position)
    on dates.the_date between schedules.startdate
        and nvl(schedules.enddate, date '9999-12-31')
group by position, the_date
order by position, the_date;

A partition outer join can help fill in calendar data. It is similar to a cross join but may perform much better with non-trivial table sizes.

A cross join will join every row in set A with every row in set B.

A partition outer join will join every row in set A with every defined subset in set B.

The example below generates the date range only based on the schedule data you provided. Therefore the 14th and 15th do not show up, but that can be easy to fix.

with schedules as
(
    --Schedule data.
    select 'bottle washer' position, 'Fred'   name, date '2013-01-02' startdate, date '2013-01-05' enddate from dual union all
    select 'bottle washer' position, 'Barney' name, date '2013-01-04' startdate, date '2013-01-07' enddate from dual union all
    select 'bottle washer' position, 'Betty'  name, date '2013-01-10' startdate, null              enddate from dual union all
    select 'bottle washer' position, 'Wilma'  name, date '2013-01-12' startdate, date '2013-01-13' enddate from dual union all
    select 'cook'          position, 'Bilbo'  name, date '2013-01-01' startdate, date '2013-01-03' enddate from dual union all
    select 'cook'          position, 'Frodo'  name, date '2013-01-05' startdate, date '2013-01-08' enddate from dual union all
    select 'cook'          position, 'Bilbo'  name, date '2013-01-07' startdate, null              enddate from dual
),
dates as
(
    --Date range, based on schedule data.
    select first_startdate + level - 1 the_date
    from
    (
        select min(startdate) first_startdate
            ,(max(enddate) - min(startdate))+1 date_diff
        from schedules
    )
    connect by level <= date_diff
)
--Count of staff working per position, per day.
select position, the_date, count(schedules.startdate) staffing
from dates
left join schedules partition by (position)
    on dates.the_date between schedules.startdate
        and nvl(schedules.enddate, date '9999-12-31')
group by position, the_date
order by position, the_date;

相关问答

更多

在SQL中获取日期范围(Get Date Ranges in SQL)

您的范围似乎是由连续日期定义的。 您可以通过减去增加的数字来分配组 - 通过row_number() 。 剩下的就是聚合: select min(datetime) as range_start, max(datetime) as range_end from (select t.*, dateadd(day, - row_number() over (order by datetime), datetime) as grp from t ) t g...

如何使用Oracle SQL选择不同的日期范围(How to select distinct date ranges with Oracle SQL)

select distinct rgid,start_month,end_month from tbl_app_ranges; select distinct rgid,start_month,end_month from tbl_app_ranges;

如何编写带有2个日期范围的sql子查询(how to write sql subquery with 2 date ranges)

您可以使用exists子句执行此操作: select e.* from events e where exists (select 1 from events e2 where e2.name = e.name and year(e2.DateOfAttendence) = 2002 ); You can do this with an exists clause: sele...

这在SQL中是什么样的方法,它确实存在?(What kind of approach is this in SQL, it actually exists? Is it viable/good pratice?)

我们只使用一个表TRANSACTION_TYPE(ID PRIMARY KEY,NAME),例如: 现在,如果要限制对表的更新,可以使用以下查询来实现: GRANT SELECT,INSERT,DELETE ON TRANSACTION_TYPE TO Username; OR Deny UPDATE ON TRANSACTION_TYPE TO Username; 现在要保留插入和删除的历史记录,您可以通过在TRANSACTION_TYPE上创...

是否有一个很好的SQL方法来汇总带有日期范围块作为输入的表?(Is there a good SQL approach for summarizing a table with blocks of date ranges as input?)

分区外连接可以帮助填写日历数据。 它类似于交叉连接,但对于非平凡的表大小可能表现更好。 交叉连接将连接集合A中的每一行与集合B中的每一行。 分区外连接将连接集合A中的每一行与集合B中的每个已定义子集。 以下示例仅根据您提供的计划数据生成日期范围。 因此,第14和第15不会出现,但这很容易修复。 with schedules as ( --Schedule data. select 'bottle washer' position, 'Fred' name, date '2013...

总结同一SQL表上的两个条件(Summarizing two conditions on the same SQL table)

这是一个开始,我认为这是沿着正确的方向......唯一剩下的就是增加比率。 SELECT COMPANY_ID, NON_BILLABLE = SUM(CASE STATUS WHEN IN (0, 1) THEN 1 ELSE 0 END), BILLABLE = SUM(CASE STATUS WHEN IN (2, 3) THEN 1 ELSE 0 END) FROM TRANSACTIONS GROUP BY COMPANY_ID 编辑:符合标准。 SELECT ...

SQL - 总结每月销售数据(SQL - Summarizing Monthly Sales Data)

将所有日期的列表放在第一位,然后将数据留在数据中,而使用case表达式则更好, coalesce()就是另一种选择。 这应该确保所有想要的月/年显示: SELECT tmpsalestbl.PartNumber AS partnumber , tmp_date_array.CreateDateMonth AS createdatemonth , tmp_date_array.CreateDateYear AS cre...

SQL:在每个成员的多个开始和结束日期范围内识别不同的处理块(SQL: Identify distinct blocks of treatment over multiple start and end date ranges for each member)

SQL Server 2012具有lag()和累积和函数,这使得编写此类查询更加容易。 我们的想法是找到每个序列中的第一个。 然后取第一个标志的累积总和来识别每个组。 这是代码: select MemberId, Diagnosis, min(ServiceDate) as EpisodeStartDate, max(ServiceStartDate) as EpisodeEndDate from (select t.*, sum(ServiceStartFlag) over (pa...

相关文章

更多

CentOS 6.3 更改yum源,改为163源

安装软件时,出现以下错误 http://centos.ustc.edu.cn/centos/6.4/o ...

更改我的网页默认的暴风影音播放器

可以从根本上设置一下.开始→设置→控制面版→添加或删除程序→设定程序访问和默认值→选中[自定义&quo ...

eclipse的默认(打开)编辑器的更改

eclipse / MyEclipse JSP默认打开方式是 MyEclipse Visual JSP ...

HDFS的副本存放策略

HDFS作为Hadoop中的一个分布式文件系统,而且是专门为它的MapReduce设计,所以HDFS除 ...

android 随手记 仿微信的popwindow

/把文字控件添加监听,点击弹出自定义窗口 [java] view plain ...

Java泛型父类取得子类的泛型参数T的Class类型

import java.lang.reflect.ParameterizedType;import j ...

关于继承和static的小问题

今天帮同事写接口的时候,想到一个问题:现在有2个类 class parent{...} ,class ...

关于子类构造器中调用父类构造器的问题

public class Person{ private String name; public Pe ...

如何向一个页面中的两个iframe传值

现在有一个页面上面是一个iframe的报表 下面是一个iframe的图形 分别向两个iframe传 ...

spring 4.2已经不支持SimpleJdbcDaoSupport ,改用JdbcDaoSupport

好用的SimpleJdbcDaoSupport 及SimpleJdbcTemplate,已经在3.1中 ...

最新问答

更多

获取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}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本