Last active
August 29, 2015 14:02
-
-
Save woodnathan/6e41c8800ac0fb4e5596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BSBook.h | |
// BookstoreApp | |
// | |
// Created by Nathan Wood on 17/06/2014. | |
// Copyright (c) 2014 Nathan Wood. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface BSBook : NSObject | |
+ (instancetype)bookWithTitle:(NSString *)title price:(float)price; | |
- (instancetype)initWithTitle:(NSString *)title price:(float)price; | |
@property (nonatomic, copy) NSString *title; | |
@property (nonatomic, assign) float price; | |
@property (nonatomic, strong) UIImage *image; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BSBook.m | |
// BookstoreApp | |
// | |
// Created by Nathan Wood on 17/06/2014. | |
// Copyright (c) 2014 Nathan Wood. All rights reserved. | |
// | |
#import "BSBook.h" | |
@implementation BSBook | |
+ (instancetype)bookWithTitle:(NSString *)title price:(float)price | |
{ | |
return [[self alloc] initWithTitle:title price:price]; | |
} | |
- (instancetype)initWithTitle:(NSString *)title price:(float)price | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
self.title = title; | |
self.price = price; | |
} | |
return self; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BSBookStore.h | |
// BookstoreApp | |
// | |
// Created by Nathan Wood on 17/06/2014. | |
// Copyright (c) 2014 Nathan Wood. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "BSAuthor.h" | |
#import "BSBook.h" | |
@class BSAuthor; | |
@interface BSBookStore : NSObject | |
- (instancetype)initWithTitle:(NSString *)title; | |
@property (nonatomic, copy) NSString *title; | |
@property (nonatomic, copy, readonly) NSArray *authors; | |
- (void)addAuthor:(BSAuthor *)author; | |
- (void)populate; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BSBookStore.m | |
// BookstoreApp | |
// | |
// Created by Nathan Wood on 17/06/2014. | |
// Copyright (c) 2014 Nathan Wood. All rights reserved. | |
// | |
#import "BSBookStore.h" | |
@interface BSBookStore () | |
@property (nonatomic, copy, readwrite) NSArray *authors; | |
@end | |
@implementation BSBookStore | |
- (instancetype)init | |
{ | |
return [self initWithTitle:@"My Book Store"]; | |
} | |
- (instancetype)initWithTitle:(NSString *)title | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
self.title = title; | |
self.authors = [[NSArray alloc] init]; | |
} | |
return self; | |
} | |
- (void)addAuthor:(BSAuthor *)author | |
{ | |
self.authors = [self.authors arrayByAddingObject:author]; | |
} | |
- (void)populate | |
{ | |
BSAuthor *rowling = [[BSAuthor alloc] initWithName:@"J.K. Rowling"]; | |
BSAuthor *martin = [[BSAuthor alloc] initWithName:@"George R.R. Martin"]; | |
BSAuthor *collins = [[BSAuthor alloc] initWithName:@"Suzanne Collins"]; | |
[rowling addBook:[BSBook bookWithTitle:@"The Philosopher's Stone" price:6.59]]; | |
[rowling addBook:[BSBook bookWithTitle:@"The Chamber of Secrets" price:6.64]]; | |
[rowling addBook:[BSBook bookWithTitle:@"The Prisoner of Azkaban" price:6.88]]; | |
[martin addBook:[BSBook bookWithTitle:@"A Game of Thrones" price:6.02]]; | |
[martin addBook:[BSBook bookWithTitle:@"A Dance with Dragons" price:6.02]]; | |
[martin addBook:[BSBook bookWithTitle:@"A Feast for Crows" price:6.02]]; | |
BSBook *hungerGames = [BSBook bookWithTitle:@"The Hunger Games" price:6.22]; | |
hungerGames.image = [UIImage imageNamed:@"hunger.jpeg"]; | |
[collins addBook:hungerGames]; | |
[collins addBook:[BSBook bookWithTitle:@"Catching Fire" price:7.32]]; | |
[collins addBook:[BSBook bookWithTitle:@"Mockingjay" price:8.06]]; | |
// Add the authors to our store | |
[self addAuthor:rowling]; | |
[self addAuthor:martin]; | |
[self addAuthor:collins]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment