Skip to content

Commit

Permalink
Copy the value to an ivar backed by a copy property (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
maicki authored and rahul-malik committed Aug 8, 2017
1 parent 0d50564 commit 116b818
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Examples/Cocoa/Sources/objc/Board.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"name"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_name = value;
self->_name = [value copy];
}
self->_boardDirtyProperties.BoardDirtyPropertyName = 1;
}
Expand All @@ -64,7 +64,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"id"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_identifier = value;
self->_identifier = [value copy];
}
self->_boardDirtyProperties.BoardDirtyPropertyIdentifier = 1;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"description"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_descriptionText = value;
self->_descriptionText = [value copy];
}
self->_boardDirtyProperties.BoardDirtyPropertyDescriptionText = 1;
}
Expand All @@ -113,7 +113,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
NSMutableDictionary *result0 = [NSMutableDictionary dictionaryWithCapacity:items0.count];
[items0 enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key0, id _Nonnull obj0, __unused BOOL * _Nonnull stop0){
if (obj0 != nil && obj0 != (id)kCFNull) {
result0[key0] = obj0;
result0[key0] = [obj0 copy];
}
}];
self->_creator = result0;
Expand Down
12 changes: 6 additions & 6 deletions Examples/Cocoa/Sources/objc/Pin.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"note"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_note = value;
self->_note = [value copy];
}
self->_pinDirtyProperties.PinDirtyPropertyNote = 1;
}
Expand All @@ -75,7 +75,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
NSMutableDictionary *result0 = [NSMutableDictionary dictionaryWithCapacity:items0.count];
[items0 enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key0, id _Nonnull obj0, __unused BOOL * _Nonnull stop0){
if (obj0 != nil && obj0 != (id)kCFNull) {
result0[key0] = obj0;
result0[key0] = [obj0 copy];
}
}];
self->_media = result0;
Expand All @@ -96,7 +96,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"description"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_descriptionText = value;
self->_descriptionText = [value copy];
}
self->_pinDirtyProperties.PinDirtyPropertyDescriptionText = 1;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
NSMutableDictionary *result0 = [NSMutableDictionary dictionaryWithCapacity:items0.count];
[items0 enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key0, id _Nonnull obj0, __unused BOOL * _Nonnull stop0){
if (obj0 != nil && obj0 != (id)kCFNull) {
result0[key0] = obj0;
result0[key0] = [obj0 copy];
}
}];
self->_attribution = result0;
Expand All @@ -146,7 +146,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"color"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_color = value;
self->_color = [value copy];
}
self->_pinDirtyProperties.PinDirtyPropertyColor = 1;
}
Expand All @@ -164,7 +164,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"id"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_identifier = value;
self->_identifier = [value copy];
}
self->_pinDirtyProperties.PinDirtyPropertyIdentifier = 1;
}
Expand Down
10 changes: 5 additions & 5 deletions Examples/Cocoa/Sources/objc/User.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"last_name"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_lastName = value;
self->_lastName = [value copy];
}
self->_userDirtyProperties.UserDirtyPropertyLastName = 1;
}
Expand All @@ -64,7 +64,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"id"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_identifier = value;
self->_identifier = [value copy];
}
self->_userDirtyProperties.UserDirtyPropertyIdentifier = 1;
}
Expand All @@ -73,7 +73,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"first_name"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_firstName = value;
self->_firstName = [value copy];
}
self->_userDirtyProperties.UserDirtyPropertyFirstName = 1;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"username"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_username = value;
self->_username = [value copy];
}
self->_userDirtyProperties.UserDirtyPropertyUsername = 1;
}
Expand All @@ -118,7 +118,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
__unsafe_unretained id value = modelDictionary[@"bio"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_bio = value;
self->_bio = [value copy];
}
self->_userDirtyProperties.UserDirtyPropertyBio = 1;
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/Core/ObjectiveCInitExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ extension ObjCModelRenderer {

return schemas.map(loop)
default:
return ["\(propertyToAssign) = \(rawObjectName);"]
switch schema.memoryAssignmentType() {
case .copy:
return ["\(propertyToAssign) = [\(rawObjectName) copy];"]
default:
return ["\(propertyToAssign) = \(rawObjectName);"]
}
}
}

Expand Down

0 comments on commit 116b818

Please sign in to comment.