Commit 93460a07 by Brent Gulanowski

Merge pull request #122 from Shopify/task/model-management

Add support for managed models
parents 922d7a64 05cc85b4
......@@ -175,11 +175,9 @@
@implementation BUYDirtyTracked
+ (void)initialize
+ (BOOL)tracksDirtyProperties
{
if (self == [BUYDirtyTracked class]) {
[self trackDirtyProperties];
}
return YES;
}
@end
......
//
// BUYObserverTests.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <XCTest/XCTest.h>
#import "BUYObserver.h"
@interface Target : NSObject
@property (nonatomic) NSString *name;
@property (nonatomic) NSNumber *number;
@property (nonatomic) NSDate *date;
@end
@implementation Target
@end
@interface BUYObserverTests : XCTestCase
@end
@implementation BUYObserverTests
- (void)test {
NSArray *properties = @[@"name", @"number", @"date"];
Target *target = [[Target alloc] init];
BUYObserver *observer = [BUYObserver observeProperties:properties ofObject:target];
XCTAssertEqualObjects(observer.observedProperties, properties);
XCTAssertEqualObjects(observer.changedProperties, [NSSet set]);
target.name = @"Name";
XCTAssertEqualObjects(observer.changedProperties, [NSSet setWithObject:@"name"]);
target.number = @10;
target.date = [NSDate date];
NSSet *expected = [NSSet setWithObjects:@"name", @"number", @"date", nil];
XCTAssertEqualObjects(observer.changedProperties, expected);
[observer reset];
XCTAssertEqualObjects(observer.changedProperties, [NSSet set]);
__weak Target *weakTarget = target;
[observer cancel];
XCTAssertEqualObjects(observer.changedProperties, nil);
XCTAssertEqualObjects(observer.object, nil);
target = nil;
XCTAssertEqual(weakTarget, nil);
}
@end
......@@ -40,12 +40,7 @@
numberHandler = [[NSDecimalNumberHandler alloc] initWithRoundingMode:NSRoundBankers scale:12 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
});
NSDecimalNumber *decimalNumber = [valueFromJSON buy_decimalNumber];
if (decimalNumber == nil) {
NSLog(@"Could not create decimal value: %@", valueFromJSON);
}
return [decimalNumber decimalNumberByRoundingAccordingToBehavior:numberHandler];
return [[valueFromJSON buy_decimalNumber] decimalNumberByRoundingAccordingToBehavior:numberHandler];
}
- (NSDecimalNumber*)buy_decimalNumberAsNegative
......
......@@ -43,10 +43,8 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[];
#import <Buy/BUYCustomer.h>
#import <Buy/BUYDiscount.h>
#import <Buy/BUYGiftCard.h>
#import <Buy/BUYImageLink.h>
#import <Buy/BUYLineItem.h>
#import <Buy/BUYClient.h>
#import <Buy/BUYClient+Customers.h>
#import <Buy/BUYImage.h>
#import <Buy/BUYMaskedCreditCard.h>
#import <Buy/BUYOption.h>
#import <Buy/BUYOptionValue.h>
......@@ -59,7 +57,14 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[];
#import <Buy/BUYApplePayAdditions.h>
#import <Buy/BUYApplePayHelpers.h>
#import <Buy/BUYClient.h>
#import <Buy/BUYClient+Customers.h>
#import <Buy/BUYError.h>
#import <Buy/BUYManagedObject.h>
#import <Buy/BUYModelManager.h>
#import <Buy/BUYModelManagerProtocol.h>
#import <Buy/BUYObjectProtocol.h>
#import <Buy/BUYObserver.h>
#import <Buy/BUYPaymentButton.h>
#import <Buy/BUYProductViewController.h>
......
//
// BUYManagedObject.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <CoreData/CoreData.h>
#import <Buy/BUYObject.h>
#if defined CORE_DATA_PERSISTENCE
#define BUYCachedObject BUYManagedObject
/**
* This is the base class for all Shopify persistent model objects.
* This class takes care of convertion .json responses into
* the associated subclass.
*
* You will generally not need to interact with this class directly.
*/
@interface BUYManagedObject : NSManagedObject<BUYObject>
- (nonnull instancetype)init NS_UNAVAILABLE;
@end
#else
#define BUYCachedObject BUYObject
/**
* Key-value coding API defined in NSManagedObject which is used by mogenerator generated accessors.
* When persistence is not implemented, will/didAccess do nothing; primitive KVC maps to normal KVC.
*/
@interface BUYObject (BUYManagedObjectConformance)
- (void)willAccessValueForKey:(nonnull NSString *)key;
- (void)didAccessValueForKey:(nonnull NSString *)key;
- (nullable id)primitiveValueForKey:(nonnull NSString *)key;
- (void)setPrimitiveValue:(nullable id)value forKey:(nonnull NSString *)key;
@end
#endif
//
// BUYManagedObject.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYManagedObject.h"
#import "NSDictionary+BUYAdditions.h"
#import "NSException+BUYAdditions.h"
#import "NSEntityDescription+BUYAdditions.h"
#import "NSPropertyDescription+BUYAdditions.h"
#import <CoreData/CoreData.h>
#if defined CORE_DATA_PERSISTENCE
@interface NSManagedObjectContext (BUYPersistence)
@property (nonatomic, strong) BUYModelManager *modelManager;
@end
@implementation BUYManagedObject
- (NSDictionary *)JSONEncodedProperties
{
return self.entity.JSONEncodedProperties;
}
+ (BOOL)isPersistentClass
{
return YES;
}
+ (BOOL)tracksDirtyProperties
{
return NO;
}
+ (NSPredicate *)fetchPredicateWithJSON:(NSDictionary *)JSONDictionary
{
return JSONDictionary[@"id"] ? [NSPredicate predicateWithFormat:@"identifier = %@", JSONDictionary[@"id"]] : nil;
}
+ (NSString *)entityName
{
@throw BUYAbstractMethod();
}
- (BUYModelManager *)modelManager
{
return self.managedObjectContext.modelManager;
}
- (NSDictionary *)JSONDictionary
{
// JSON generation starts in `-buy_JSONForObject`.
// Both persistent and transient objects go through this interface.
return [self.entity buy_JSONForObject:self];
}
- (void)setJSONDictionary:(NSDictionary *)JSONDictionary
{
// JSON parsing starts in `-buy_updateObject:withJSON:`.
// Both persistent and transient objects go through this interface.
[self.entity buy_updateObject:self withJSON:JSONDictionary];
}
- (NSDictionary *)jsonDictionaryForCheckout
{
return self.JSONDictionary;
}
@end
#else
@implementation BUYObject (BUYManagedObjectConformance)
- (void)willAccessValueForKey:(NSString *)key {}
- (void)didAccessValueForKey:(NSString *)key {}
- (id)primitiveValueForKey:(NSString *)key
{
return [self valueForKey:key];
}
- (void)setPrimitiveValue:(id)value forKey:(NSString *)key
{
[self setValue:value forKey:key];
}
@end
#endif
//
// BUYModelManager.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#import <Buy/BUYObject.h>
#import <Buy/BUYModelManagerProtocol.h>
/**
* A basic implementation of the BUYModelManager interface that does no caching. New objects are created using alloc/init.
* Provides empty implementations of all the caching methods.
*/
@interface BUYModelManager : NSObject<BUYModelManager>
/**
* The managed object model describes all the model entities. See the Core Data documentation for more details.
*/
@property (nonatomic, strong, readonly) NSManagedObjectModel *model;
/**
*
* @param model The Core Data managed object model for your given model. Should be the Buy model.
*
* @return A new model manager object.
*/
- (instancetype)initWithManagedObjectModel:(NSManagedObjectModel *)model NS_DESIGNATED_INITIALIZER;
/**
* Convenience initializer. Instantiates a model using the -mergedModelFromBundles: method and the Buy.framework as the bundle.
*/
+ (instancetype)modelManager;
@end
//
// BUYModelManager.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYModelManager.h"
#import "BUYDateTransformer.h"
#import "BUYDeliveryRangeTransformer.h"
#import "BUYFlatCollectionTransformer.h"
#import "NSArray+BUYAdditions.h"
#import "NSEntityDescription+BUYAdditions.h"
#import "NSPropertyDescription+BUYAdditions.h"
// Custom value transformer names
NSString * const BUYPublicationsDateTransformerName = @"BUYPublicationsDate";
// Structured value transformer names
NSString * const BUYDeliveryRangeTransformerName = @"BUYDeliveryRange";
NSString * const BUYFlatArrayTransformerName = @"BUYFlatArray";
NSString * const BUYProductTagsTransformerName = @"BUYProductTags";
NSString * const BUYPublicationsDateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ";
@interface BUYModelManager ()
@property (nonatomic, strong) NSManagedObjectModel *model;
@end
@implementation BUYModelManager
+ (void)initialize
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// specialty type transformers
[NSValueTransformer setValueTransformer:[BUYDateTransformer dateTransformerWithFormat:BUYPublicationsDateFormat] forName:BUYPublicationsDateTransformerName];
// specialty collection transformers
[NSValueTransformer setValueTransformer:[[BUYDeliveryRangeTransformer alloc] init] forName:BUYDeliveryRangeTransformerName];
[NSValueTransformer setValueTransformer:[BUYFlatCollectionTransformer arrayTransformer] forName:BUYFlatArrayTransformerName];
[NSValueTransformer setValueTransformer:[BUYFlatCollectionTransformer setTransformerWithSeparator:@", "] forName:BUYProductTagsTransformerName];
});
}
- (instancetype)init
{
return [self initWithManagedObjectModel:[NSManagedObjectModel mergedModelFromBundles:@[[NSBundle bundleForClass:[self class]]]]];
}
- (instancetype)initWithManagedObjectModel:(NSManagedObjectModel *)model
{
self = [super init];
if (self) {
self.model = model;
}
return self;
}
+ (instancetype)modelManager
{
return [[self alloc] init];
}
- (NSEntityDescription *)buy_entityWithName:(NSString *)entityName
{
return [self.model entitiesByName][entityName];
}
- (id<BUYObject>)buy_objectWithEntityName:(NSString *)entityName JSONDictionary:(NSDictionary *)JSON
{
NSEntityDescription *entity = [self buy_entityWithName:entityName];
Class cls = entity.managedObjectClass;
return [[cls alloc] initWithModelManager:self JSONDictionary:JSON];
}
- (NSArray<id<BUYObject>> *)buy_objectsWithEntityName:(NSString *)entityName JSONArray:(NSArray *)JSON
{
NSEntityDescription *entity = [self.model entitiesByName][entityName];
Class cls = entity.managedObjectClass;
return [JSON buy_map:^id(NSDictionary *JSONDictionary) {
return [[cls alloc] initWithModelManager:self JSONDictionary:JSONDictionary];
}];
}
- (id<BUYObject>)buy_objectWithEntityName:(NSString *)entityName identifier:(NSNumber *)identifier
{
return nil;
}
- (NSArray<id<BUYObject>> *)buy_objectsWithEntityName:(NSString *)entityName identifiers:(NSArray *)identifiers
{
return @[];
}
- (BOOL)buy_purgeObject:(id<BUYObject>)object error:(NSError *__autoreleasing *)error
{
return YES;
}
- (void)buy_refreshCacheForObject:(id<BUYObject>)object
{
}
- (BOOL)buy_purgeObjectsWithEntityName:(NSString *)entityName matchingPredicate:(NSPredicate *)predicate
{
return YES;
}
@end
......@@ -26,6 +26,8 @@
#import <CoreData/CoreData.h>
@protocol BUYObject;
/**
* A protocol for defining an object that can store and retrieve model objects from a data store or other cache.
*/
......
......@@ -26,6 +26,8 @@
#import <Foundation/Foundation.h>
#import <Buy/BUYObjectProtocol.h>
/**
* This is the base class for all Shopify model objects.
* This class takes care of convertion .json responses into
......@@ -33,7 +35,7 @@
*
* You will generally not need to interact with this class directly.
*/
@interface BUYObject : NSObject
@interface BUYObject : NSObject<BUYObject>
/**
* The identifier of any Shopify model object.
......@@ -59,6 +61,5 @@
- (NSSet *)dirtyProperties;
- (void)markPropertyAsDirty:(NSString *)property;
- (void)markAsClean;
+ (void)trackDirtyProperties;
@end
//
// BUYObject.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYObject.h"
#import "BUYModelManagerProtocol.h"
#import "BUYObserver.h"
#import "BUYRuntime.h"
#import "NSDictionary+BUYAdditions.h"
#import "NSException+BUYAdditions.h"
#import "NSEntityDescription+BUYAdditions.h"
@interface BUYObject ()
@property (nonatomic, readwrite, weak) id<BUYModelManager> modelManager;
@property (nonatomic) BUYObserver *dirtyObserver;
@end
@implementation BUYObject
#pragma mark - Deprecated
- (instancetype)init
{
return [self initWithDictionary:nil];
}
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
{
return [self initWithModelManager:nil JSONDictionary:dictionary];
}
+ (NSArray *)convertJSONArray:(NSArray*)json block:(void (^)(id obj))createdBlock
{
NSMutableArray *objects = [[NSMutableArray alloc] init];
for (NSDictionary *jsonObject in json) {
BUYObject *obj = [[self alloc] initWithDictionary:jsonObject];
[objects addObject:obj];
if (createdBlock) {
createdBlock(obj);
}
}
return objects;
}
+ (NSArray *)convertJSONArray:(NSArray*)json
{
return [self convertJSONArray:json block:nil];
}
+ (instancetype)convertObject:(id)object
{
BUYObject *convertedObject = nil;
if (!(object == nil || [object isKindOfClass:[NSNull class]])) {
convertedObject = [[self alloc] initWithDictionary:object];
}
return convertedObject;
}
#pragma mark - Dirty Property Tracking
- (BOOL)isDirty
{
return [self.dirtyObserver hasChanges];
}
- (NSSet *)dirtyProperties
{
return self.dirtyObserver.changedProperties;
}
- (void)markPropertyAsDirty:(NSString *)property
{
[self.dirtyObserver markPropertyChanged:property];
}
- (void)markAsClean
{
[self.dirtyObserver reset];
}
- (BOOL)isEqual:(id)object
{
if (self == object) return YES;
if (![object isKindOfClass:self.class]) return NO;
BOOL same = ([self.identifier isEqual:((BUYObject*)object).identifier]);
return same;
}
- (NSUInteger)hash
{
NSUInteger hash = [self.identifier hash];
return hash;
}
- (void)trackDirtyProperties:(NSArray *)properties
{
self.dirtyObserver = [BUYObserver observeProperties:properties ofObject:self];
}
#pragma mark - Dynamic JSON Serialization
+ (NSArray *)propertyNames
{
static NSMutableDictionary *namesCache;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
namesCache = [NSMutableDictionary dictionary];
});
NSString *className = NSStringFromClass(self);
NSArray *names = namesCache[className];
if (names == nil) {
NSMutableSet *allNames = [class_getBUYProperties(self) mutableCopy];
[allNames removeObject:NSStringFromSelector(@selector(dirtyObserver))];
names = [allNames allObjects];
namesCache[className] = names;
}
return names;
}
+ (NSEntityDescription *)entity
{
@throw BUYAbstractMethod();
}
+ (NSString *)entityName
{
@throw BUYAbstractMethod();
}
- (NSDictionary *)JSONEncodedProperties
{
return self.entity.JSONEncodedProperties;
}
- (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager JSONDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
self.modelManager = modelManager;
[self updateWithDictionary:dictionary];
if ([[self class] tracksDirtyProperties]) {
[self trackDirtyProperties:[[self class] propertyNames]];
}
}
return self;
}
- (void)updateWithDictionary:(NSDictionary *)dictionary
{
_identifier = dictionary[@"id"];
[self markAsClean];
}
- (NSDictionary *)jsonDictionaryForCheckout
{
return self.JSONDictionary;
}
+ (NSPredicate *)fetchPredicateWithJSON:(NSDictionary *)JSONDictionary
{
return nil;
}
+ (BOOL)isPersistentClass
{
return NO;
}
+ (BOOL)tracksDirtyProperties
{
return NO;
}
- (NSEntityDescription *)entity
{
return [self.modelManager buy_entityWithName:[[self class] entityName]];
}
- (NSDictionary *)JSONDictionary
{
// JSON generation starts in `-buy_JSONForObject`.
// Both persistent and transient objects go through this interface.
return [self.entity buy_JSONForObject:self];
}
- (void)setJSONDictionary:(NSDictionary *)JSONDictionary
{
// JSON parsing starts in `-buy_updateObject:withJSON:`.
// Both persistent and transient objects go through this interface.
if ([JSONDictionary count]) {
[self.entity buy_updateObject:self withJSON:JSONDictionary];
}
}
@end
//
// BUYObject.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYObject.h"
#import "BUYRuntime.h"
#import <objc/runtime.h>
#import <objc/message.h>
namespace shopify
{
namespace mobilebuysdk
{
/**
* Creates and returns a block that is used as the setter method for the persisted subclasses
* The method implementation calls through to its superclasses implementation and then marks
* the attribute as dirty.
*/
template <typename T>
id attribute_setter(NSString *propertyName, SEL selector)
{
id setterBlock = ^ void (id _self, T value) {
// we need to cast objc_msgSend so that the compiler inserts proper type information for the passed in value
// not doing so results in strange behaviour (for example, floats never get set)
void (*typed_objc_msgSend)(id, SEL, T) = (void (*)(id, SEL, T))objc_msgSend;
typed_objc_msgSend(_self, selector, value);
[_self markPropertyAsDirty:propertyName];
};
return setterBlock;
}
}
}
@implementation BUYObject {
NSMutableSet *_dirtyProperties;
}
- (instancetype)init
{
return [self initWithDictionary:nil];
}
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
_dirtyProperties = [[NSMutableSet alloc] init];
[self updateWithDictionary:dictionary];
[self markAsClean];
}
return self;
}
- (void)updateWithDictionary:(NSDictionary *)dictionary
{
_identifier = dictionary[@"id"];
}
+ (NSArray *)convertJSONArray:(NSArray*)json block:(void (^)(id obj))createdBlock
{
NSMutableArray *objects = [[NSMutableArray alloc] init];
for (NSDictionary *jsonObject in json) {
BUYObject *obj = [[self alloc] initWithDictionary:jsonObject];
[objects addObject:obj];
if (createdBlock) {
createdBlock(obj);
}
}
return objects;
}
+ (NSArray *)convertJSONArray:(NSArray*)json
{
return [self convertJSONArray:json block:nil];
}
+ (instancetype)convertObject:(id)object
{
BUYObject *convertedObject = nil;
if (!(object == nil || [object isKindOfClass:[NSNull class]])) {
convertedObject = [[self alloc] initWithDictionary:object];
}
return convertedObject;
}
#pragma mark - Dirty Property Tracking
- (BOOL)isDirty
{
return [_dirtyProperties count] > 0;
}
- (NSSet *)dirtyProperties
{
return [NSSet setWithSet:_dirtyProperties];
}
- (void)markPropertyAsDirty:(NSString *)property
{
[_dirtyProperties addObject:property];
}
- (void)markAsClean
{
[_dirtyProperties removeAllObjects];
}
+ (id)setterBlockForSelector:(SEL)selector property:(NSString *)property typeEncoding:(const char *)typeEncoding
{
id setterBlock;
switch (typeEncoding[0]) {
case '@': // object
{
setterBlock = shopify::mobilebuysdk::attribute_setter<id>(property, selector);
break;
}
case 'B': // C++ style bool/_Bool
{
setterBlock = shopify::mobilebuysdk::attribute_setter<bool>(property, selector);
break;
}
case 'c': // char
{
setterBlock = shopify::mobilebuysdk::attribute_setter<char>(property, selector);
break;
}
case 'C': // unsigned char
{
setterBlock = shopify::mobilebuysdk::attribute_setter<unsigned char>(property, selector);
break;
}
case 'i': // int
{
setterBlock = shopify::mobilebuysdk::attribute_setter<int>(property, selector);
break;
}
case 'I': // unsigned int
{
setterBlock = shopify::mobilebuysdk::attribute_setter<unsigned int>(property, selector);
break;
}
case 's': // short
{
setterBlock = shopify::mobilebuysdk::attribute_setter<short>(property, selector);
break;
}
case 'S': // unsigned short
{
setterBlock = shopify::mobilebuysdk::attribute_setter<unsigned short>(property, selector);
break;
}
case 'l': // long
{
setterBlock = shopify::mobilebuysdk::attribute_setter<long>(property, selector);
break;
}
case 'L': // unsigned long
{
setterBlock = shopify::mobilebuysdk::attribute_setter<unsigned long>(property, selector);
break;
}
case 'q': // long long
{
setterBlock = shopify::mobilebuysdk::attribute_setter<long long>(property, selector);
break;
}
case 'Q': // unsigned long long
{
setterBlock = shopify::mobilebuysdk::attribute_setter<unsigned long long>(property, selector);
break;
}
case 'f': // float
{
setterBlock = shopify::mobilebuysdk::attribute_setter<float>(property, selector);
break;
}
case 'd': // double
{
setterBlock = shopify::mobilebuysdk::attribute_setter<double>(property, selector);
break;
}
}
return setterBlock;
}
+ (void)wrapProperty:(NSString *)property
{
SEL setter = NSSelectorFromString([NSString stringWithFormat:@"set%@:", [NSString stringWithFormat:@"%@%@",[[property substringToIndex:1] uppercaseString], [property substringFromIndex:1]]]);
//Get the setter. don't worry about readonly properties as they're irrelevant for dirty tracking
if (setter && [self instancesRespondToSelector:setter]) {
Method setterMethod = class_getInstanceMethod(self, setter);
IMP setterImpl = method_getImplementation(setterMethod);
NSMethodSignature *methodSignature = [self instanceMethodSignatureForSelector:setter];
if ([methodSignature numberOfArguments] == 3) {
const char *typeEncoding = [methodSignature getArgumentTypeAtIndex:2];
SEL newSetter = NSSelectorFromString([NSString stringWithFormat:@"buy_%@", NSStringFromSelector(setter)]);
id setterBlock = [self setterBlockForSelector:newSetter property:property typeEncoding:typeEncoding];
if (setterBlock) {
//Create 'buy_setX:' that uses the existing implementation
class_addMethod(self, newSetter, setterImpl, method_getTypeEncoding(setterMethod));
//Create a new impmlementation
IMP newImpl = imp_implementationWithBlock(setterBlock);
//Then attach that implementation to 'setX:'. This way calling 'setX:' calls our implementation, and 'buy_setX:' calls the original implementation.
class_replaceMethod(self, setter, newImpl, method_getTypeEncoding(setterMethod));
}
}
}
}
+ (void)trackDirtyProperties
{
NSSet *properties = class_getBUYProperties(self);
for (NSString *property in properties) {
if ([property length] > 0) {
[self wrapProperty:property];
}
}
}
- (BOOL)isEqual:(id)object
{
if (self == object) return YES;
if (![object isKindOfClass:self.class]) return NO;
BOOL same = ([self.identifier isEqual:((BUYObject*)object).identifier]);
return same;
}
- (NSUInteger)hash
{
NSUInteger hash = [self.identifier hash];
return hash;
}
@end
//
// BUYObserver.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Foundation/Foundation.h>
@interface BUYObserver : NSObject
@property (nonatomic, readonly) NSObject *object;
@property (nonatomic, readonly) NSArray *observedProperties;
@property (nonatomic, readonly) NSSet *changedProperties;
@property (nonatomic, readonly) BOOL hasChanges;
- (instancetype)init NS_UNAVAILABLE;
- (void)markPropertyChanged:(NSString *)property;
- (void)reset;
- (void)cancel;
+ (instancetype)observeProperties:(NSArray<NSString *> *)properties ofObject:(id)object;
@end
//
// BUYObserver.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYObserver.h"
static void * kBUYObserverContext = &kBUYObserverContext;
@interface BUYObserver ()
@property (nonatomic) NSObject *object;
@property (nonatomic) NSArray *observedProperties;
@end
@implementation BUYObserver {
NSMutableSet *_changedProperties;
}
- (instancetype)initWithObject:(id)object properties:(NSArray<NSString *> *)properties
{
self = [super init];
if (self) {
self.object = object;
self.observedProperties = properties;
_changedProperties = [NSMutableSet set];
[self startObserving];
}
return self;
}
- (void)dealloc
{
[self stopObserving];
}
#pragma mark - Accessors
- (NSSet *)changedProperties
{
return [_changedProperties copy];
}
- (void)addChangedPropertiesObject:(NSString *)object
{
[_changedProperties addObject:object];
}
- (void)removeChangedProperties:(NSSet *)objects
{
[_changedProperties minusSet:objects];
}
#pragma mark - Key Value Observing
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
if (context == kBUYObserverContext) {
[self markPropertyChanged:keyPath];
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)startObserving
{
for (NSString *property in _observedProperties) {
[_object addObserver:self forKeyPath:property options:0 context:kBUYObserverContext];
}
}
- (void)stopObserving
{
for (NSString *property in _observedProperties) {
[_object removeObserver:self forKeyPath:property];
}
}
#pragma mark - BUYObserver
- (void)markPropertyChanged:(NSString *)property
{
[self addChangedPropertiesObject:property];
}
- (BOOL)hasChanges
{
return _changedProperties.count > 0;
}
- (void)reset {
[self removeChangedProperties:[_changedProperties copy]];
}
- (void)cancel {
[self reset];
[self stopObserving];
_changedProperties = nil;
_observedProperties = nil;
_object = nil;
}
+ (instancetype)observeProperties:(NSArray<NSString *> *)properties ofObject:(id)object
{
return [[self alloc] initWithObject:object properties:properties];
}
@end
......@@ -24,7 +24,7 @@
// THE SOFTWARE.
//
@import Foundation;
#import <Foundation/Foundation.h>
@protocol BUYSerializable <NSObject>
......
//
// BUYImage.h
// BUYImageLink.h
// Mobile Buy SDK
//
// Created by Shopify.
......@@ -29,7 +29,7 @@
/**
* Products are easier to sell if customers can see pictures of them, which is why there are product images.
*/
@interface BUYImage : BUYObject
@interface BUYImageLink : BUYObject
/**
* Specifies the location of the product image.
......
//
// BUYImage.m
// BUYImageLink.m
// Mobile Buy SDK
//
// Created by Shopify.
......@@ -24,10 +24,10 @@
// THE SOFTWARE.
//
#import "BUYImage.h"
#import "BUYImageLink.h"
#import "NSDateFormatter+BUYAdditions.h"
@implementation BUYImage
@implementation BUYImageLink
- (void)updateWithDictionary:(NSDictionary *)dictionary
{
......
......@@ -27,7 +27,7 @@
#import "BUYObject.h"
@class BUYProductVariant;
@class BUYImage;
@class BUYImageLink;
@class BUYOption;
/**
......@@ -67,9 +67,9 @@
@property (nonatomic, readonly, copy) NSArray<BUYProductVariant *> *variants;
/**
* A list of BUYImage objects, each one representing an image associated with the product.
* A list of BUYImageLink objects, each one representing an image associated with the product.
*/
@property (nonatomic, readonly, copy) NSArray<BUYImage *> *images;
@property (nonatomic, readonly, copy) NSArray<BUYImageLink *> *images;
/**
* Custom product property names like "Size", "Color", and "Material".
......
......@@ -24,7 +24,7 @@
// THE SOFTWARE.
//
#import "BUYImage.h"
#import "BUYImageLink.h"
#import "BUYOption.h"
#import "BUYProduct.h"
#import "BUYProductVariant.h"
......@@ -45,7 +45,7 @@
_variants = [BUYProductVariant convertJSONArray:dictionary[@"variants"] block:^(BUYProductVariant *variant) {
variant.product = self;
}];
_images = [BUYImage convertJSONArray:dictionary[@"images"]];
_images = [BUYImageLink convertJSONArray:dictionary[@"images"]];
_options = [BUYOption convertJSONArray:dictionary[@"options"]];
_htmlDescription = [dictionary buy_objectForKey:@"body_html"];
_available = [dictionary[@"available"] boolValue];
......
......@@ -28,13 +28,6 @@
@implementation BUYShop
+ (void)initialize
{
if (self == [BUYShop class]) {
[self trackDirtyProperties];
}
}
- (void)updateWithDictionary:(NSDictionary *)dictionary
{
[super updateWithDictionary:dictionary];
......
//
// _<$managedObjectClassName$>.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Buy/_<$managedObjectClassName$>.h>
@interface <$managedObjectClassName$> : _<$managedObjectClassName$> {}
@end
//
// _<$managedObjectClassName$>.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "<$managedObjectClassName$>.h"
@implementation <$managedObjectClassName$>
@end
//
// _<$managedObjectClassName$>.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to <$managedObjectClassName$>.h instead.
#import <Buy/BUYManagedObject.h>
<$if hasAdditionalHeaderFile$>
#import "<$additionalHeaderFileName$>"
<$endif$>
#import "BUYModelManager.h"
<$if noninheritedAttributes.@count > 0$>
extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Attribute.name$>;<$endforeach do$>
} <$managedObjectClassName$>Attributes;
<$endif$>
<$if noninheritedRelationships.@count > 0$>
extern const struct <$managedObjectClassName$>Relationships {<$foreach Relationship noninheritedRelationships do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Relationship.name$>;<$endforeach do$>
} <$managedObjectClassName$>Relationships;
<$endif$>
<$if noninheritedFetchedProperties.@count > 0$>
extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach FetchedProperty noninheritedFetchedProperties do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$FetchedProperty.name$>;<$endforeach do$>
} <$managedObjectClassName$>FetchedProperties;
<$endif$>
<$if hasUserInfoKeys$>
extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userInfoKeyValues do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$UserInfo.key$>;<$endforeach do$>
} <$managedObjectClassName$>UserInfo;
<$endif$>
<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
<$endforeach do$><$foreach Attribute noninheritedAttributes do$>
<$if Attribute.hasTransformableAttributeType$>
<$if Attribute.objectAttributeTransformableProtocols$><$foreach Protocol Attribute.objectAttributeTransformableProtocols do$>@protocol <$Protocol$>;
<$endforeach do$><$else$>@class <$Attribute.objectAttributeClassName$>;<$endif$><$endif$>
<$endforeach do$>
@class <$managedObjectClassName$>;
@interface BUYModelManager (<$managedObjectClassName$>Inserting)
- (NSArray<<$managedObjectClassName$> *> *)all<$name$>Objects;
- (<$managedObjectClassName$> *)fetch<$name$>WithIdentifierValue:(int64_t)identifier;
- (<$managedObjectClassName$> *)insert<$name$>WithJSONDictionary:(NSDictionary *)dictionary;
- (NSArray<<$managedObjectClassName$> *> *)insert<$name$>sWithJSONArray:(NSArray <NSDictionary *> *)array;
@end
<$if userInfo.documentation$>
/**
* <$userInfo.documentation$><$if userInfo.discussion$>
*
* <$userInfo.discussion$><$endif$>
*/<$endif$>
@interface _<$managedObjectClassName$> : <$customSuperentity$>
+ (NSString *)entityName;
<$foreach Attribute noninheritedAttributes do$>
<$if Attribute.userInfo.documentation$>
/**
* <$Attribute.userInfo.documentation$><$if Attribute.userInfo.discussion$>
*
* <$Attribute.userInfo.discussion$><$endif$>
*/<$endif$><$if Attribute.hasDefinedAttributeType$><$if TemplateVar.arc$><$if Attribute.isReadonly$>
@property (nonatomic, strong, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
@property (nonatomic, strong) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$endif$>
<$else$><$if Attribute.isReadonly$>
@property (nonatomic, retain, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
@property (nonatomic, retain) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$endif$><$endif$>
<$if Attribute.hasScalarAttributeType$>
<$if Attribute.isReadonly$>
@property (atomic, readonly) <$Attribute.scalarAttributeType$> <$Attribute.name$>Value;
- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value;
<$else$>
@property (atomic) <$Attribute.scalarAttributeType$> <$Attribute.name$>Value;
- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value;
- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_;
<$endif$><$endif$><$endif$>
<$endforeach do$>
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.userInfo.documentation$>
/**
* <$Relationship.userInfo.documentation$><$if Relationship.userInfo.discussion$>
*
* <$Relationship.userInfo.discussion$><$endif$>
*/<$endif$><$if Relationship.isToMany$><$if TemplateVar.arc$>
@property (nonatomic, strong) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;<$else$>
@property (nonatomic, retain) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
<$endif$>
- (<$Relationship.mutableCollectionClassName$> *)<$Relationship.name$>Set;
<$else$>
<$if TemplateVar.arc$>
@property (nonatomic, strong) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
<$else$>
@property (nonatomic, retain) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
<$endif$><$endif$>
<$endforeach do$>
<$foreach FetchedProperty noninheritedFetchedProperties do$>
<$if FetchedProperty.userInfo.documentation$>
/**
* <$FetchedProperty.userInfo.documentation$><$if FetchedProperty.userInfo.documentation$>
*
* <$FetchedProperty.userInfo.discussion$><$endif$>
*/<$endif$>
@property (nonatomic, readonly) NSArray *<$FetchedProperty.name$>;
<$endforeach do$>
<$if TemplateVar.frc$>
#if TARGET_OS_IPHONE
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
- (NSFetchedResultsController *)new<$Relationship.name.initialCapitalString$>FetchedResultsControllerWithSortDescriptors:(NSArray *)sortDescriptors;
<$endif$>
<$endforeach do$>
#endif
<$endif$>
@end
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
@interface _<$managedObjectClassName$> (<$Relationship.name.initialCapitalString$>CoreDataGeneratedAccessors)
<$if Relationship.isOrdered$>
- (void)insertObject:(<$Relationship.destinationEntity.managedObjectClassName$> *)value in<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx;
- (void)removeObjectFrom<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx;
- (void)insert<$Relationship.name.initialCapitalString$>:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)remove<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectIn<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx withObject:(<$Relationship.destinationEntity.managedObjectClassName$> *)value;
- (void)replace<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes with<$Relationship.name.initialCapitalString$>:(NSArray *)values;
<$endif$>
@end
<$endif$>
<$endforeach do$>
@interface _<$managedObjectClassName$> (CoreDataGeneratedPrimitiveAccessors)
<$foreach Attribute noninheritedAttributesSansType do$>
<$if Attribute.hasDefinedAttributeType$>
- (<$Attribute.objectAttributeType$>)primitive<$Attribute.name.initialCapitalString$>;
- (void)setPrimitive<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>)value;
<$endif$>
<$endforeach do$>
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
- (<$Relationship.mutableCollectionClassName$> *)primitive<$Relationship.name.initialCapitalString$>;
- (void)setPrimitive<$Relationship.name.initialCapitalString$>:(<$Relationship.mutableCollectionClassName$> *)value;
<$else$>
- (<$Relationship.destinationEntity.managedObjectClassName$> *)primitive<$Relationship.name.initialCapitalString$>;
- (void)setPrimitive<$Relationship.name.initialCapitalString$>:(<$Relationship.destinationEntity.managedObjectClassName$> *)value;
<$endif$>
<$endforeach do$>
@end
//
// _<$managedObjectClassName$>.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to <$managedObjectClassName$>.m instead.
#import "_<$managedObjectClassName$>.h"
<$if noninheritedAttributes.@count > 0$>
const struct <$managedObjectClassName$>Attributes <$managedObjectClassName$>Attributes = {<$foreach Attribute noninheritedAttributes do$>
.<$Attribute.name$> = @"<$Attribute.name$>",<$endforeach do$>
};
<$endif$>
<$if noninheritedRelationships.@count > 0$>
const struct <$managedObjectClassName$>Relationships <$managedObjectClassName$>Relationships = {<$foreach Relationship noninheritedRelationships do$>
.<$Relationship.name$> = @"<$Relationship.name$>",<$endforeach do$>
};
<$endif$>
<$if noninheritedFetchedProperties.@count > 0$>
const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassName$>FetchedProperties = {<$foreach FetchedProperty noninheritedFetchedProperties do$>
.<$FetchedProperty.name$> = @"<$FetchedProperty.name$>",<$endforeach do$>
};
<$endif$>
<$if hasUserInfoKeys$>
const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserInfo = {<$foreach UserInfo userInfoKeyValues do$>
.<$UserInfo.key$> = @"<$UserInfo.value$>",<$endforeach do$>
};
<$endif$>
@implementation _<$managedObjectClassName$>
+ (NSString *)entityName {
return @"<$name$>";
}
+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$if Attribute.hasScalarAttributeType$>
if ([key isEqualToString:@"<$Attribute.name$>Value"]) {
NSSet *affectingKey = [NSSet setWithObject:@"<$Attribute.name$>"];
keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
return keyPaths;
}<$endif$><$endif$><$endforeach do$>
return keyPaths;
}
#if defined CORE_DATA_PERSISTENCE<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$>
- (<$Attribute.objectAttributeType$>)<$Attribute.name$> {
[self willAccessValueForKey:@"<$Attribute.name$>"];
id value = [self primitiveValueForKey:@"<$Attribute.name$>"];
[self didAccessValueForKey:@"<$Attribute.name$>"];
return value;
}
<$if ! Attribute.isReadonly$>
- (void)set<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>)value_ {
[self willChangeValueForKey:@"<$Attribute.name$>"];
[self setPrimitiveValue:value_ forKey:@"<$Attribute.name$>"];
[self didChangeValueForKey:@"<$Attribute.name$>"];
}
<$endif$><$endif$><$endforeach do$>
#endif
<$foreach Attribute noninheritedAttributes do$>
<$if Attribute.hasDefinedAttributeType$>
<$if Attribute.hasScalarAttributeType$>
- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value {
NSNumber *result = [self <$Attribute.name$>];
return [result <$Attribute.scalarAccessorMethodName$>];
}
<$if ! Attribute.isReadonly$>
- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_ {
[self set<$Attribute.name.initialCapitalString$>:<$if TemplateVar.literals$>@(value_)<$else$>[NSNumber <$Attribute.scalarFactoryMethodName$>value_]<$endif$>];
}
<$endif$>
<$endif$>
<$endif$>
<$endforeach do$>
<$foreach Relationship noninheritedRelationships do$>
#if defined CORE_DATA_PERSISTENCE
@dynamic <$Relationship.name$>;
#endif
<$if Relationship.isToMany$>
- (<$Relationship.mutableCollectionClassName$> *)<$Relationship.name$>Set {
[self willAccessValueForKey:@"<$Relationship.name$>"];
<$if Relationship.jr_isOrdered$>
<$Relationship.mutableCollectionClassName$> *result = (<$Relationship.mutableCollectionClassName$> *)[self mutableOrderedSetValueForKey:@"<$Relationship.name$>"];
<$else$>
<$Relationship.mutableCollectionClassName$> *result = (<$Relationship.mutableCollectionClassName$> *)[self mutableSetValueForKey:@"<$Relationship.name$>"];
<$endif$>
[self didAccessValueForKey:@"<$Relationship.name$>"];
return result;
}
<$endif$>
<$endforeach do$>
<$foreach FetchedProperty noninheritedFetchedProperties do$>
@dynamic <$FetchedProperty.name$>;
<$endforeach do$>
<$if TemplateVar.frc$>
#if TARGET_OS_IPHONE
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
- (NSFetchedResultsController *)new<$Relationship.name.initialCapitalString$>FetchedResultsControllerWithSortDescriptors:(NSArray *)sortDescriptors {
NSFetchRequest *fetchRequest = [NSFetchRequest new];
<$if !TemplateVar.arc$>[fetchRequest autorelease];<$endif$>
fetchRequest.entity = [NSEntityDescription entityForName:@"<$Relationship.destinationEntity.name$>" inManagedObjectContext:self.managedObjectContext];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"<$Relationship.inverseRelationship.name$> <$if Relationship.inverseRelationship.isToMany$>CONTAINS<$else$>==<$endif$> %@", self];
fetchRequest.sortDescriptors = sortDescriptors;
<$if indexedNoninheritedAttributes.@count > 0$>
NSArray *indexedIDs = [NSArray arrayWithObjects:<$foreach Attribute indexedNoninheritedAttributes do$>self.<$Attribute.name$>, <$endforeach do$>nil];
NSString *cacheName = [NSString stringWithFormat:@"mogenerator.<$managedObjectClassName$>.%@.<$Relationship.name$>.%@", indexedIDs, sortDescriptors];
<$endif$>
return [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:<$if indexedNoninheritedAttributes.@count > 0$>cacheName<$else$>nil<$endif$>];
}
<$endif$>
<$endforeach do$>
#endif
<$endif$>
@end
#pragma mark -
@implementation BUYModelManager (<$managedObjectClassName$>Inserting)
- (<$managedObjectClassName$> *)insert<$name$>WithJSONDictionary:(NSDictionary *)dictionary
{
return (<$managedObjectClassName$> *)[self buy_objectWithEntityName:@"<$name$>" JSONDictionary:dictionary];
}
- (NSArray<<$managedObjectClassName$> *> *)insert<$name$>sWithJSONArray:(NSArray <NSDictionary *> *)array
{
return (NSArray<<$managedObjectClassName$> *> *)[self buy_objectsWithEntityName:@"<$name$>" JSONArray:array];
}
- (NSArray<<$managedObjectClassName$> *> *)all<$name$>Objects
{
return (NSArray<<$managedObjectClassName$> *> *)[self buy_objectsWithEntityName:@"<$name$>" identifiers:nil];
}
- (<$managedObjectClassName$> *)fetch<$name$>WithIdentifierValue:(int64_t)identifier
{
return (<$managedObjectClassName$> *)[self buy_objectWithEntityName:@"<$name$>" identifier:@(identifier)];
}
@end
//
// _<$managedObjectClassName$>.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Buy/_<$managedObjectClassName$>.h>
@interface <$managedObjectClassName$> : _<$managedObjectClassName$> {}
@end
//
// _<$managedObjectClassName$>.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "<$managedObjectClassName$>.h"
@implementation <$managedObjectClassName$>
@end
//
// _<$managedObjectClassName$>.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to <$managedObjectClassName$>.h instead.
<$if hasCustomSuperentity$><$if hasSuperentity$>#import <Buy/<$customSuperentity$>.h>
<$else$><$if hasCustomBaseCaseImport$>#import <$baseClassImport$><$else$>#import "<$customSuperentity$>.h"<$endif$><$endif$><$endif$>
<$if hasAdditionalHeaderFile$>
#import "<$additionalHeaderFileName$>"
<$endif$>
#import <Buy/BUYModelManager.h>
<$if noninheritedAttributes.@count > 0$>
extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Attribute.name$>;<$endforeach do$>
} <$managedObjectClassName$>Attributes;
<$endif$>
<$if noninheritedRelationships.@count > 0$>
extern const struct <$managedObjectClassName$>Relationships {<$foreach Relationship noninheritedRelationships do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Relationship.name$>;<$endforeach do$>
} <$managedObjectClassName$>Relationships;
<$endif$>
<$if noninheritedFetchedProperties.@count > 0$>
extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach FetchedProperty noninheritedFetchedProperties do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$FetchedProperty.name$>;<$endforeach do$>
} <$managedObjectClassName$>FetchedProperties;
<$endif$>
<$if hasUserInfoKeys$>
extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userInfoKeyValues do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$UserInfo.key$>;<$endforeach do$>
} <$managedObjectClassName$>UserInfo;
<$endif$>
<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
<$endforeach do$>
<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasTransformableAttributeType$><$if Attribute.objectAttributeTransformableProtocols$>
<$foreach Protocol Attribute.objectAttributeTransformableProtocols do$>@protocol <$Protocol$>;
<$endforeach do$><$else$>
@class <$Attribute.objectAttributeClassName$>;<$endif$><$endif$>
<$endforeach do$>
@class <$managedObjectClassName$>;
@interface BUYModelManager (<$managedObjectClassName$>Inserting)
- (NSArray<<$managedObjectClassName$> *> *)all<$name$>Objects;
- (<$managedObjectClassName$> *)fetch<$name$>WithIdentifierValue:(int64_t)identifier;
- (<$managedObjectClassName$> *)insert<$name$>WithJSONDictionary:(NSDictionary *)dictionary;
- (NSArray<<$managedObjectClassName$> *> *)insert<$name$>sWithJSONArray:(NSArray <NSDictionary *> *)array;
@end
<$if userInfo.documentation$>
/**
* <$userInfo.documentation$><$if userInfo.discussion$>
*
* <$userInfo.discussion$><$endif$>
*/<$endif$>
@interface _<$managedObjectClassName$> : <$customSuperentity$>
+ (NSString *)entityName;
<$foreach Attribute noninheritedAttributes do$>
<$if Attribute.userInfo.documentation$>
/**
* <$Attribute.userInfo.documentation$><$if Attribute.userInfo.discussion$>
*
* <$Attribute.userInfo.discussion$><$endif$>
*/<$endif$><$if Attribute.hasDefinedAttributeType$><$if TemplateVar.arc$><$if Attribute.isReadonly$>
@property (nonatomic, strong, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
@property (nonatomic, strong) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$endif$>
<$else$>
<$if Attribute.isReadonly$>
@property (nonatomic, retain, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
@property (nonatomic, retain) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$endif$>
<$endif$>
<$if Attribute.hasScalarAttributeType$>
<$if Attribute.isReadonly$>
@property (atomic, readonly) <$Attribute.scalarAttributeType$> <$Attribute.name$>Value;
- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value;
<$else$>
@property (atomic) <$Attribute.scalarAttributeType$> <$Attribute.name$>Value;
- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value;
- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_;
<$endif$><$endif$><$endif$>
<$endforeach do$>
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.userInfo.documentation$>
/**
* <$Relationship.userInfo.documentation$><$if Relationship.userInfo.discussion$>
*
* <$Relationship.userInfo.discussion$><$endif$>
*/<$endif$><$if Relationship.isToMany$><$if TemplateVar.arc$>
@property (nonatomic, strong) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
<$else$>
@property (nonatomic, retain) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
<$endif$>
- (<$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set;
<$else$><$if TemplateVar.arc$>
@property (nonatomic, strong) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
<$else$>
@property (nonatomic, retain) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
<$endif$><$endif$>
<$endforeach do$>
<$foreach FetchedProperty noninheritedFetchedProperties do$>
<$if FetchedProperty.userInfo.documentation$>
/**
* <$FetchedProperty.userInfo.documentation$><$if FetchedProperty.userInfo.discussion$>
*
* <$FetchedProperty.userInfo.discussion$><$endif$>
*/<$endif$>
@property (nonatomic, readonly) NSArray *<$FetchedProperty.name$>;
<$endforeach do$>
<$if TemplateVar.frc$>
#if TARGET_OS_IPHONE
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
- (NSFetchedResultsController *)new<$Relationship.name.initialCapitalString$>FetchedResultsControllerWithSortDescriptors:(NSArray *)sortDescriptors;
<$endif$>
<$endforeach do$>
#endif
<$endif$>
@end
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
@interface _<$managedObjectClassName$> (<$Relationship.name.initialCapitalString$>CoreDataGeneratedAccessors)
<$if Relationship.isOrdered$>
- (void)insertObject:(<$Relationship.destinationEntity.managedObjectClassName$>*)value in<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx;
- (void)removeObjectFrom<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx;
- (void)insert<$Relationship.name.initialCapitalString$>:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)remove<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectIn<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx withObject:(<$Relationship.destinationEntity.managedObjectClassName$>*)value;
- (void)replace<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes with<$Relationship.name.initialCapitalString$>:(NSArray *)values;
<$endif$>
@end
<$endif$>
<$endforeach do$>
......@@ -46,11 +46,9 @@
@implementation BUYCheckout
+ (void)initialize
+ (BOOL)tracksDirtyProperties
{
if (self == [BUYCheckout class]) {
[self trackDirtyProperties];
}
return YES;
}
- (instancetype)initWithCart:(BUYCart *)cart
......
......@@ -30,7 +30,7 @@
@class BUYProductViewFooter;
@class BUYGradientView;
@class BUYTheme;
@class BUYImage;
@class BUYImageLink;
@class BUYProduct;
/**
......
......@@ -32,7 +32,7 @@
#import "BUYProductVariantCell.h"
#import "BUYProductDescriptionCell.h"
#import "BUYProductHeaderCell.h"
#import "BUYImage.h"
#import "BUYImageLink.h"
#import "BUYImageView.h"
#import "BUYProduct.h"
#import "BUYProductViewErrorView.h"
......@@ -225,7 +225,7 @@
page = (int)(self.productViewHeader.collectionView.contentOffset.x / self.productViewHeader.collectionView.frame.size.width);
}
[self.productViewHeader setCurrentPage:page];
BUYImage *image = images[page];
BUYImageLink *image = images[page];
[self.backgroundImageView setBackgroundProductImage:image];
}
}
......
......@@ -31,6 +31,7 @@
#import "BUYProduct+Options.h"
#import "BUYProductViewController.h"
#import "BUYImageKit.h"
#import "BUYImageLink.h"
#import "BUYProductView.h"
#import "BUYProductViewFooter.h"
#import "BUYProductHeaderCell.h"
......@@ -45,7 +46,6 @@
#import "BUYError.h"
#import "BUYShop.h"
#import "BUYShopifyErrorCodes.h"
#import "BUYImage.h"
CGFloat const BUYMaxProductViewWidth = 414.0; // We max out to the width of the iPhone 6+
CGFloat const BUYMaxProductViewHeight = 640.0;
......@@ -566,7 +566,7 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BUYProductImageCollectionViewCell *cell = (BUYProductImageCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
BUYImage *image = self.product.images[indexPath.row];
BUYImageLink *image = self.product.images[indexPath.row];
NSURL *url = [NSURL URLWithString:image.src];
[cell.productImageView loadImageWithURL:url completion:NULL];
[cell setContentOffset:self.productView.tableView.contentOffset];
......
......@@ -28,7 +28,7 @@
#import "BUYImageView.h"
#import "BUYGradientView.h"
#import "BUYProductImageCollectionViewCell.h"
#import "BUYImage.h"
#import "BUYImageLink.h"
#import "BUYProductVariant.h"
#import "BUYTheme.h"
#import "BUYTheme+Additions.h"
......@@ -206,7 +206,7 @@
{
[self setNumberOfPages:[images count]];
if (CGSizeEqualToSize(self.collectionView.contentSize, CGSizeZero) == NO) {
[images enumerateObjectsUsingBlock:^(BUYImage *image, NSUInteger i, BOOL *stop) {
[images enumerateObjectsUsingBlock:^(BUYImageLink *image, NSUInteger i, BOOL *stop) {
for (NSNumber *variantId in image.variantIds) {
if ([variantId isEqualToNumber:productVariant.identifier]) {
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
......
......@@ -27,7 +27,7 @@
@import UIKit;
@class BUYImageView;
@class BUYTheme;
@class BUYImage;
@class BUYImageLink;
/**
* A background for the product view that displays the currently displayed
......@@ -49,6 +49,6 @@
*
* @param image The currently displayed product or variant image
*/
- (void)setBackgroundProductImage:(BUYImage *)image;
- (void)setBackgroundProductImage:(BUYImageLink *)image;
@end
......@@ -27,7 +27,7 @@
#import "BUYProductViewHeaderBackgroundImageView.h"
#import "BUYTheme.h"
#import "BUYImageView.h"
#import "BUYImage.h"
#import "BUYImageLink.h"
#import "BUYTheme+Additions.h"
@interface BUYProductViewHeaderBackgroundImageView ()
......@@ -86,7 +86,7 @@
return self;
}
- (void)setBackgroundProductImage:(BUYImage *)image
- (void)setBackgroundProductImage:(BUYImageLink *)image
{
NSString *string = [image.src stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@".%@", [image.src pathExtension]] withString:[NSString stringWithFormat:@"_small.%@", [image.src pathExtension]]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", string]];
......
......@@ -44,7 +44,7 @@
#import "BUYCustomer.h"
#import "BUYDiscount.h"
#import "BUYGiftCard.h"
#import "BUYImage.h"
#import "BUYImageLink.h"
#import "BUYLineItem.h"
#import "BUYMaskedCreditCard.h"
#import "BUYOption.h"
......@@ -57,6 +57,11 @@
#import "BUYTaxLine.h"
#import "BUYError.h"
#import "BUYManagedObject.h"
#import "BUYModelManager.h"
#import "BUYModelManagerProtocol.h"
#import "BUYObjectProtocol.h"
#import "BUYObserver.h"
#import "BUYPaymentButton.h"
#import "BUYProductViewController.h"
......
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