Commit 8f0a3e1f by Brent Gulanowski

Merge pull request #215 from Shopify/task/swift-support

Add typed collection for Swift support.
parents d0556ed6 4196047f
...@@ -27,10 +27,18 @@ ...@@ -27,10 +27,18 @@
#import "_BUYCart.h" #import "_BUYCart.h"
@class BUYProductVariant; @class BUYProductVariant;
@class BUYLineItem;
@interface BUYCart : _BUYCart {} @interface BUYCart : _BUYCart {}
/** /**
* Array of BUYCartLineItem objects in the cart
*
* These are different from BUYLineItem objects. The line item objects do include the BUYProductVariant.
*/
- (nonnull NSArray<BUYCartLineItem *> *)lineItemsArray;
/**
* Returns true if the cart is acceptable to send to Shopify. * Returns true if the cart is acceptable to send to Shopify.
*/ */
- (BOOL)isValid; - (BOOL)isValid;
......
...@@ -40,8 +40,13 @@ ...@@ -40,8 +40,13 @@
} }
return self; return self;
} }
#endif #endif
- (nonnull NSArray<BUYCartLineItem *> *)lineItemsArray
{
return self.lineItems.array;
}
- (BOOL)isValid - (BOOL)isValid
{ {
return [self.lineItems count] > 0; return [self.lineItems count] > 0;
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
@property (nonatomic, readonly) NSString *stringDescription; @property (nonatomic, readonly) NSString *stringDescription;
- (NSArray<BUYProduct *> *)productsArray;
/** /**
* Converts the BUYCollectionSort enum to an API-compatible string for the collection sort parameter * Converts the BUYCollectionSort enum to an API-compatible string for the collection sort parameter
* *
......
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
@synthesize stringDescription = _stringDescription; @synthesize stringDescription = _stringDescription;
- (NSArray<BUYProduct *> *)productsArray
{
return self.products.array;
}
- (void)updateStringDescription - (void)updateStringDescription
{ {
// Force early cache of this value to prevent spooky behaviour // Force early cache of this value to prevent spooky behaviour
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
@interface BUYOrder : _BUYOrder {} @interface BUYOrder : _BUYOrder {}
- (NSArray<BUYLineItem *> *)lineItemsArray;
@end @end
@interface BUYModelManager (BUYOrder) @interface BUYModelManager (BUYOrder)
......
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
@implementation BUYOrder @implementation BUYOrder
- (NSArray<BUYLineItem *> *)lineItemsArray
{
return self.lineItems.array;
}
- (NSArray *)formatIDsForLineItemsJSON:(NSArray<NSDictionary *> *)lineItems - (NSArray *)formatIDsForLineItemsJSON:(NSArray<NSDictionary *> *)lineItems
{ {
__block NSMutableArray<NSDictionary *> *mutableLineItems = [NSMutableArray array]; __block NSMutableArray<NSDictionary *> *mutableLineItems = [NSMutableArray array];
......
...@@ -33,6 +33,23 @@ ...@@ -33,6 +33,23 @@
@property (nonatomic, readonly, copy) NSDate *publishedAtDate; @property (nonatomic, readonly, copy) NSDate *publishedAtDate;
@property (nonatomic, readonly, copy) NSString *stringDescription; @property (nonatomic, readonly, copy) NSString *stringDescription;
/**
* An array of BUYImageLink objects, each one representing an image associated with the product.
*/
- (NSArray<BUYImageLink *> *)imagesArray;
/**
* Custom product property names like "Size", "Color", and "Material".
*
* An array of BUYOption objects. Products are based on permutations of these options. A product may have a maximum of 3 options. 255 characters limit each.
*/
- (NSArray<BUYOption *> *)optionsArray;
/**
* An array of BUYProductVariant objects, each one representing a slightly different version of the product.
*/
- (NSArray<BUYProductVariant *> *)variantsArray;
@end @end
@interface BUYProduct (Options) @interface BUYProduct (Options)
......
...@@ -58,6 +58,21 @@ ...@@ -58,6 +58,21 @@
return _stringDescription; return _stringDescription;
} }
- (NSArray<BUYImageLink *> *)imagesArray
{
return self.images.array;
}
- (NSArray<BUYOption *> *)optionsArray
{
return self.options.array;
}
- (NSArray<BUYProductVariant *> *)variantsArray
{
return self.variants.array;
}
@end @end
@implementation BUYProduct (Options) @implementation BUYProduct (Options)
......
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
- (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cart:(BUYCart *)cart; - (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cart:(BUYCart *)cart;
- (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cartToken:(NSString *)token; - (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cartToken:(NSString *)token;
- (NSArray<BUYGiftCard *> *)giftCardsArray;
- (NSArray<BUYCartLineItem *> *)lineItemsArray;
- (void)updateWithCart:(BUYCart *)cart; - (void)updateWithCart:(BUYCart *)cart;
- (BUYGiftCard *)giftCardWithIdentifier:(NSNumber *)identifier; - (BUYGiftCard *)giftCardWithIdentifier:(NSNumber *)identifier;
......
...@@ -66,7 +66,8 @@ ...@@ -66,7 +66,8 @@
[super setShippingRate:shippingRate]; [super setShippingRate:shippingRate];
self.shippingRateId = shippingRate.shippingRateIdentifier; self.shippingRateId = shippingRate.shippingRateIdentifier;
} }
-(void)setPartialAddresses:(NSNumber *)partialAddresses
- (void)setPartialAddresses:(NSNumber *)partialAddresses
{ {
if (partialAddresses.boolValue == NO) { if (partialAddresses.boolValue == NO) {
@throw [NSException exceptionWithName:@"partialAddress" reason:@"partialAddresses can only be set to true and should never be set to false on a complete address" userInfo:nil]; @throw [NSException exceptionWithName:@"partialAddress" reason:@"partialAddresses can only be set to true and should never be set to false on a complete address" userInfo:nil];
...@@ -74,6 +75,7 @@ ...@@ -74,6 +75,7 @@
[ super setPartialAddresses:partialAddresses]; [ super setPartialAddresses:partialAddresses];
} }
#pragma mark - Init -
/** /**
* We must initialize to-many relationships to ensure that * We must initialize to-many relationships to ensure that
...@@ -112,6 +114,20 @@ ...@@ -112,6 +114,20 @@
return self; return self;
} }
#pragma mark - Accessors -
- (NSArray<BUYGiftCard *> *)giftCardsArray
{
return self.giftCards.array;
}
- (NSArray<BUYCartLineItem *> *)lineItemsArray
{
return self.lineItems.array;
}
#pragma mark - Update -
- (void)updateWithCart:(BUYCart *)cart - (void)updateWithCart:(BUYCart *)cart
{ {
NSArray *lineItems = [[cart.lineItems array] buy_map:^id(BUYCartLineItem *cartLineItem) { NSArray *lineItems = [[cart.lineItems array] buy_map:^id(BUYCartLineItem *cartLineItem) {
...@@ -122,7 +138,7 @@ ...@@ -122,7 +138,7 @@
self.lineItems = [NSOrderedSet orderedSetWithArray:lineItems]; self.lineItems = [NSOrderedSet orderedSetWithArray:lineItems];
} }
#pragma mark - BUYObject #pragma mark - BUYObject -
- (NSDictionary *)JSONEncodedProperties - (NSDictionary *)JSONEncodedProperties
{ {
...@@ -139,7 +155,7 @@ ...@@ -139,7 +155,7 @@
return @{ @"checkout" : json }; return @{ @"checkout" : json };
} }
#pragma mark - Gift Card management #pragma mark - Gift Card management -
- (BUYGiftCard *)giftCardWithIdentifier:(NSNumber *)identifier - (BUYGiftCard *)giftCardWithIdentifier:(NSNumber *)identifier
{ {
......
...@@ -37,6 +37,11 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -37,6 +37,11 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) NSOrderedSet <id <BUYPaymentProvider>> *providers; @property (nonatomic, strong, readonly) NSOrderedSet <id <BUYPaymentProvider>> *providers;
/** /**
* The registered payment providers
*/
- (NSArray< id<BUYPaymentProvider> > *)providersArray;
/**
* Register a payment provider * Register a payment provider
* *
* @param paymentProvider a payment provider * @param paymentProvider a payment provider
......
...@@ -38,24 +38,16 @@ NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey = @"BUYPaym ...@@ -38,24 +38,16 @@ NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey = @"BUYPaym
@implementation BUYPaymentController @implementation BUYPaymentController
- (void)startCheckout:(BUYCheckout *)checkout withProviderType:(NSString *)typeIdentifier; #pragma mark - Accessors -
{
id <BUYPaymentProvider> provider = [self providerForType:typeIdentifier];
[provider startCheckout:checkout];
}
- (void)addPaymentProvider:(id <BUYPaymentProvider>)paymentProvider - (NSSet <id <BUYPaymentProvider>> *)providers
{ {
if ([self.mutableProviders containsObject:paymentProvider]) { return [self.mutableProviders copy];
NSLog(@"Payment provider %@ has already been added", paymentProvider.identifier);
}
[self.mutableProviders addObject:paymentProvider];
} }
- (NSSet <id <BUYPaymentProvider>> *)providers - (NSArray< id<BUYPaymentProvider> > *)providersArray
{ {
return [self.mutableProviders copy]; return self.mutableProviders.array;
} }
- (NSMutableOrderedSet *)mutableProviders - (NSMutableOrderedSet *)mutableProviders
...@@ -67,6 +59,23 @@ NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey = @"BUYPaym ...@@ -67,6 +59,23 @@ NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey = @"BUYPaym
return _mutableProviders; return _mutableProviders;
} }
#pragma mark - Tasks -
- (void)startCheckout:(BUYCheckout *)checkout withProviderType:(NSString *)typeIdentifier;
{
id <BUYPaymentProvider> provider = [self providerForType:typeIdentifier];
[provider startCheckout:checkout];
}
- (void)addPaymentProvider:(id <BUYPaymentProvider>)paymentProvider
{
if ([self.mutableProviders containsObject:paymentProvider]) {
NSLog(@"Payment provider %@ has already been added", paymentProvider.identifier);
}
[self.mutableProviders addObject:paymentProvider];
}
- (id <BUYPaymentProvider>)providerForType:(NSString *)type - (id <BUYPaymentProvider>)providerForType:(NSString *)type
{ {
for (id <BUYPaymentProvider> provider in self.mutableProviders) { for (id <BUYPaymentProvider> provider in self.mutableProviders) {
......
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