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
最满意答案
分区外连接可以帮助填写日历数据。 它类似于交叉连接,但对于非平凡的表大小可能表现更好。
交叉连接将连接集合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;
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在SQL中获取日期范围(Get Date Ranges in SQL)[2023-09-10]
您的范围似乎是由连续日期定义的。 您可以通过减去增加的数字来分配组 - 通过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 group ... -
select distinct rgid,start_month,end_month from tbl_app_ranges; select distinct rgid,start_month,end_month from tbl_app_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: select e. ...
-
这在SQL中是什么样的方法,它确实存在?(What kind of approach is this in SQL, it actually exists? Is it viable/good pratice?)[2021-11-14]
我们只使用一个表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上创建触发器来 ... -
分区外连接可以帮助填写日历数据。 它类似于交叉连接,但对于非平凡的表大小可能表现更好。 交叉连接将连接集合A中的每一行与集合B中的每一行。 分区外连接将连接集合A中的每一行与集合B中的每个已定义子集。 以下示例仅根据您提供的计划数据生成日期范围。 因此,第14和第15不会出现,但这很容易修复。 with schedules as ( --Schedule data. select 'bottle washer' position, 'Fred' name, date '2013-01-0 ...
-
这是一个开始,我认为这是沿着正确的方向......唯一剩下的就是增加比率。 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 C ...
-
将所有日期的列表放在第一位,然后将数据留在数据中,而使用case表达式则更好, coalesce()就是另一种选择。 这应该确保所有想要的月/年显示: SELECT tmpsalestbl.PartNumber AS partnumber , tmp_date_array.CreateDateMonth AS createdatemonth , tmp_date_array.CreateDateYear AS createda ...
-
SQL Server 2012具有lag()和累积和函数,这使得编写此类查询更加容易。 我们的想法是找到每个序列中的第一个。 然后取第一个标志的累积总和来识别每个组。 这是代码: select MemberId, Diagnosis, min(ServiceDate) as EpisodeStartDate, max(ServiceStartDate) as EpisodeEndDate from (select t.*, sum(ServiceStartFlag) over (partiti ...