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

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;

相关问答

更多

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化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)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)