Skip to content

Commit 1dead48

Browse files
committed
nullability for properties
1 parent 7736cd0 commit 1dead48

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Templates/ObjC/Base/SharedObjC.template.tt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,14 @@ private string GetStaticBaseObject()
241241

242242
private string GeneratePropertyDeclarationLine(OdcmProperty prop)
243243
{
244-
return "@property (nonatomic, setter=" + GetObjCPropertySetter(prop) + ":, getter=" + GetObjCPropertyGetter(prop) + ") " + GetObjCTypeForVarDeclaration(prop) + " " + GetObjCProperty(prop) + ";";
244+
if(prop.IsNullable==true)
245+
{
246+
return "@property (nullable, nonatomic, setter=" + GetObjCPropertySetter(prop) + ":, getter=" + GetObjCPropertyGetter(prop) + ") " + GetObjCTypeForVarDeclaration(prop) + " " + GetObjCProperty(prop) + ";";
247+
}
248+
else
249+
{
250+
return "@property (nonnull, nonatomic, setter=" + GetObjCPropertySetter(prop) + ":, getter=" + GetObjCPropertyGetter(prop) + ") " + GetObjCTypeForVarDeclaration(prop) + " " + GetObjCProperty(prop) + ";";
251+
}
245252
}
246253

247254
private void PropertyGetterImplementation(OdcmProperty prop)
@@ -252,6 +259,17 @@ private void PropertyGetterImplementation(OdcmProperty prop)
252259
<#+
253260
if(IsObjCTypeSameAsJsonType(prop.Projection.Type))
254261
{
262+
#>
263+
<#+
264+
if(prop.IsNullable==true)
265+
{
266+
#>
267+
if([[NSNull null] isEqual:self.dictionary[@"<#=prop.Name#>"]])
268+
{
269+
return nil;
270+
}
271+
<#+
272+
}
255273
#>
256274
return self.dictionary[@"<#=prop.Name#>"];
257275
<#+
@@ -280,6 +298,7 @@ private void PropertyGetterImplementation(OdcmProperty prop)
280298
}
281299
#>
282300
}
301+
283302
<#+
284303
}
285304

@@ -304,6 +323,7 @@ private void PropertySetterImplementation(OdcmProperty prop)
304323
}
305324
#>
306325
}
326+
307327
<#+
308328
}
309329
#>

0 commit comments

Comments
 (0)