Commit f33951e6 authored by NachoSoto's avatar NachoSoto

Objective-C generated classes copy collection types in constructor

This is a small follow up to #123. The `ObjcGenerator` was already correctly set up to automatically copy `NSString` instances to ensure that if an `NSMutableString` instance was passed instead, an immutable copy was created.
With this change the same is true for `NSSet`, `NSArray`, and `NSDictionary` properties.

Note that thanks to #123 this should not have a performance impact (neither memory or CPU), since at most only one copy will be made.
parent 268b0201
......@@ -187,6 +187,9 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
def checkMutable(tm: MExpr): Boolean = tm.base match {
case MOptional => checkMutable(tm.args.head)
case MString => true
case MList => true
case MSet => true
case MMap => true
case MBinary => true
case _ => false
}
......
......@@ -9,7 +9,7 @@
- (nonnull instancetype)initWithDatesById:(nonnull NSDictionary *)datesById
{
if (self = [super init]) {
_datesById = datesById;
_datesById = [datesById copy];
}
return self;
}
......
......@@ -9,7 +9,7 @@
- (nonnull instancetype)initWithMapList:(nonnull NSArray *)mapList
{
if (self = [super init]) {
_mapList = mapList;
_mapList = [mapList copy];
}
return self;
}
......
......@@ -10,8 +10,8 @@
imap:(nonnull NSDictionary *)imap
{
if (self = [super init]) {
_map = map;
_imap = imap;
_map = [map copy];
_imap = [imap copy];
}
return self;
}
......
......@@ -9,7 +9,7 @@
- (nonnull instancetype)initWithSetList:(nonnull NSArray *)setList
{
if (self = [super init]) {
_setList = setList;
_setList = [setList copy];
}
return self;
}
......
......@@ -9,7 +9,7 @@
- (nonnull instancetype)initWithList:(nonnull NSArray *)list
{
if (self = [super init]) {
_list = list;
_list = [list copy];
}
return self;
}
......
......@@ -10,8 +10,8 @@
iset:(nonnull NSSet *)iset
{
if (self = [super init]) {
_set = set;
_iset = iset;
_set = [set copy];
_iset = [iset copy];
}
return self;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment