Skip to content

Commit a8b648a

Browse files
committed
Entity collection properties to use NSArray instead of MSCollection
1 parent 970e496 commit a8b648a

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

Templates/ObjC/Base/SharedObjC.template.tt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private string GetObjCTypeIdentifier(OdcmObject o, bool getUnderlyingType=false)
2929
OdcmProperty prop=(OdcmProperty)o;
3030
if(prop.IsCollection && !getUnderlyingType)
3131
{
32-
return GetStaticCollectionObject();
32+
return @"NSArray";
3333
}
3434

3535
return GetObjCTypeIdentifier(prop.Type,getUnderlyingType);
@@ -113,7 +113,7 @@ private string GetJsonToObjCExpressionConversion(string expr,OdcmProperty prop)
113113
if(prop.Type is OdcmEntityClass || prop.Type is OdcmMediaClass || prop.Type is OdcmComplexClass)
114114
{
115115
return String.Format(
116-
@"[[{0} alloc] initWithDictionary: {1} ]",
116+
@"[[{0} alloc] initWithDictionary: {1}]",
117117
GetObjCTypeIdentifier(prop,true),
118118
expr);
119119
}
@@ -169,23 +169,21 @@ private string GetHydratedIVarFromDictionary(OdcmProperty prop)
169169
if(prop.IsCollection)
170170
{
171171
return String.Format(@"
172-
NSMutableArray *{0}Collection = [NSMutableArray array];
173-
NSArray *{0}s = self.dictionary[@""{1}""];
172+
NSMutableArray *{0}Result = [NSMutableArray array];
173+
NSArray *{0} = self.dictionary[@""{1}""];
174174

175-
if ([{0}s isKindOfClass:[NSArray class]]){{
176-
for (id {0} in {0}s){{
177-
[{0}Collection addObject:{2}];
178-
}}
175+
if ([{0} isKindOfClass:[NSArray class]]){{
176+
for (id {2} in {0}){{
177+
[{0}Result addObject:{3}];
178+
}}
179179
}}
180180

181-
if ([{0}Collection count] > 0){{
182-
_{0} = [[{3} alloc] initWithArray:{0}Collection nextLink:self.dictionary[@""@nextLink""] additionalData:self.dictionary];
183-
}}
181+
_{0} = {0}Result;
184182
",
185183
GetObjCProperty(prop),
186184
prop.Name,
187-
GetJsonToObjCExpressionConversion(GetObjCProperty(prop), prop),
188-
GetStaticCollectionObject());
185+
prop.Type.Name.ToLowerFirstChar(),
186+
GetJsonToObjCExpressionConversion(prop.Type.Name.ToLowerFirstChar(), prop));
189187
}
190188

191189
return String.Format(@"_{0} = {1};",GetObjCProperty(prop),GetHydratedPropertyFromDictionary(prop));

Templates/ObjC/Models/ComplexType.h.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var baseEntity = entity.Base;
99
<#=writer.GetImportsClass(entity.Properties)#>
1010

1111
#import "<#=GetObjCTypeIdentifier(baseEntity)#>.h"
12-
#import "<#=GetStaticCollectionObject()#>.h"
1312

1413
@interface <#=GetObjCTypeIdentifier(entity)#> : <#=GetObjCTypeIdentifier(baseEntity)#>
1514

Templates/ObjC/Models/EntityType.h.tt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ var entity = host.CurrentType.AsOdcmClass();
66
var baseEntity = entity.Base;
77

88
IEnumerable<string> extraClasses = null;
9-
if (entity.Properties.Any(prop => prop.IsCollection))
10-
{
11-
extraClasses = new List<string> { GetStaticCollectionObject() };
12-
}
139
#>
1410
<#=writer.GetImportsClass(entity.Properties, extraClasses:extraClasses)#>
1511

1612
#import "<#=GetObjCTypeIdentifier(baseEntity)#>.h"
17-
#import "<#=GetStaticCollectionObject()#>.h"
1813

1914
@interface <#=GetObjCTypeIdentifier(entity)#> : <#=GetObjCTypeIdentifier(baseEntity)#>
2015

@@ -33,7 +28,7 @@ foreach(var prop in entity.Properties.Where(prop => GetObjCTypeIdentifier(prop)!
3328
<#
3429
}
3530

36-
foreach (var prop in entity.Properties.Where(prop => prop.IsCollection && !prop.LongDescriptionContains("not-enumerable")))
31+
foreach (var prop in entity.Properties.Where(prop => prop.IsCollection && prop.LongDescriptionContains("enumerable")))
3732
{
3833
#>
3934
- (<#=GetObjCTypeForVarDeclaration(prop,true)#>) <#=GetObjCProperty(prop)#>:(NSInteger)index;

Templates/ObjC/Models/EntityType.m.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ foreach(var prop in entity.Properties.Where(prop => GetObjCTypeIdentifier(prop)!
6666
PropertySetterImplementation(prop);
6767
}
6868

69-
foreach(var prop in entity.Properties.Where(prop => prop.IsCollection && !prop.LongDescriptionContains("not-enumerable")))
69+
foreach(var prop in entity.Properties.Where(prop => prop.IsCollection && prop.LongDescriptionContains("enumerable")))
7070
{
7171
#>
7272
- (<#=GetObjCTypeForVarDeclaration(prop,true)#>) <#=GetObjCProperty(prop)#>:(NSInteger)index
7373
{
7474
<#=GetObjCTypeForVarDeclaration(prop,true)#> <#=GetObjCProperty(prop)#> = nil;
75-
if (self.<#=GetObjCProperty(prop)#>.value){
76-
<#=GetObjCProperty(prop)#> = self.<#=GetObjCProperty(prop)#>.value[index];
75+
if (self.<#=GetObjCProperty(prop)#>) {
76+
<#=GetObjCProperty(prop)#> = self.<#=GetObjCProperty(prop)#>[index];
7777
}
7878
return <#=GetObjCProperty(prop)#>;
7979
}

Templates/ObjC/Requests/EntityCollectionRequest.h.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if (innerEntityType.Equals(propName))
3030

3131
typedef void (^<#=innerEntityType#>CompletionHandler)(<#=innerEntityType#> *response, NSError *error);
3232

33-
typedef void (^<#=propName + collectionNamer#>CompletionHandler)(<#=writer.GetStaticCodePrefix() + "Collection"#> *response, <#=propRequest#> *nextRequest, NSError *error);
33+
typedef void (^<#=propName + collectionNamer#>CompletionHandler)(<#=writer.GetStaticCodePrefix()#>Collection *response, <#=propRequest#> *nextRequest, NSError *error);
3434

3535
@interface <#=propRequest#> : <#=writer.GetStaticCodePrefix()#>CollectionRequest
3636

0 commit comments

Comments
 (0)