Skip to content

Commit

Permalink
Issue #523 (Unimplemented, Unmapped, Optional Protocol Properties cra…
Browse files Browse the repository at this point in the history
…sh MTLModel -validate:). Unimplemented, unmapped, optional protocol properties return MTLStoragePropertyNone from MTLModel +storageBehaviorForPropertyWithKeys:
  • Loading branch information
kevin-traansmission committed Jun 10, 2015
1 parent d236caa commit 853e569
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Mantle/MTLModel.m
Expand Up @@ -230,8 +230,12 @@ + (MTLPropertyStorage)storageBehaviorForPropertyWithKey:(NSString *)propertyKey
@onExit {
free(attributes);
};

if (attributes->readonly && attributes->ivar == NULL) {

Method getterMethod = class_getInstanceMethod(self.class, attributes->getter);
Method setterMethod = class_getInstanceMethod(self.class, attributes->setter);
if (!attributes->dynamic && attributes->ivar == NULL && getterMethod == NULL && setterMethod == NULL) {
return MTLPropertyStorageNone;
} else if (attributes->readonly && attributes->ivar == NULL) {
return MTLPropertyStorageNone;
} else {
return MTLPropertyStoragePermanent;
Expand Down
5 changes: 5 additions & 0 deletions MantleTests/MTLModelSpec.m
Expand Up @@ -190,4 +190,9 @@
});
});

it(@"should ignore optional protocol properties not implemented", ^{
expect(@([MTLOptionalPropertyModel storageBehaviorForPropertyWithKey:@"optionalProperty"])).to(equal(@(MTLPropertyStorageNone)));
});


QuickSpecEnd
12 changes: 12 additions & 0 deletions MantleTests/MTLTestModel.h
Expand Up @@ -154,3 +154,15 @@ extern const NSInteger MTLTestModelNameMissing;
@property (readwrite, nonatomic, assign) NSUInteger freshness;

@end


@protocol MTLOptionalPropertyProtocol

@optional
@property (readwrite, nonatomic, copy) NSString *optionalProperty;

@end

@interface MTLOptionalPropertyModel : MTLModel <MTLOptionalPropertyProtocol>

@end
4 changes: 4 additions & 0 deletions MantleTests/MTLTestModel.m
Expand Up @@ -462,3 +462,7 @@ - (NSString *)flavor {
}

@end

@implementation MTLOptionalPropertyModel

@end

0 comments on commit 853e569

Please sign in to comment.