Advertisement
Jacobhaha

BNRIStore.m

Apr 21st, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. //
  2. // BNRItemStore.m
  3. // Homepwner
  4. //
  5. //
  6.  
  7. #import "BNRItemStore.h"
  8. #import "BNRItem.h"
  9.  
  10.  
  11. @interface BNRItemStore ()
  12.  
  13.  
  14. @property (nonatomic) NSMutableArray *privateItems;
  15.  
  16.  
  17. @end
  18.  
  19.  
  20. @implementation BNRItemStore
  21.  
  22. + (instancetype) sharedStore {
  23.  
  24. static BNRItemStore *sharedStore;
  25.  
  26.  
  27. if (!sharedStore) {
  28. sharedStore = [[BNRItemStore alloc] initPrivate];
  29. }
  30.  
  31. return sharedStore;
  32. }
  33.  
  34.  
  35. - (instancetype) init {
  36. [NSException raise:@"Singleton" format:@"Use +[BNRItemStore sharedStore]"];
  37. return nil;
  38. }
  39.  
  40.  
  41. - (NSArray *) allItems {
  42. return [self.privateItems copy];
  43. }
  44.  
  45. - (NSArray *) expensiveItems {
  46. return [self.expensivePrivate copy];
  47. }
  48.  
  49. - (NSArray *) cheapItems {
  50. return [self.privateItems copy];
  51. }
  52.  
  53. - (instancetype) initPrivate{
  54. self = [super init]; // Call superclass's designated initializer
  55.  
  56.  
  57. if (self) {
  58. _privateItems = [[NSMutableArray alloc] init];
  59. }
  60.  
  61. return self;
  62. }
  63.  
  64.  
  65. - (BNRItem *) createItem {
  66. BNRItem *item = [BNRItem randomItem];
  67.  
  68. [self.privateItems addObject:item];
  69.  
  70. if (item.valueInDollars > 50) {
  71. [self.expensivePrivate addObject:item];
  72. }
  73.  
  74.  
  75. return item;
  76. }
  77.  
  78. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement