From a20b549dcbc89ea99f0686292d36f76890396eb8 Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Sun, 13 Oct 2013 15:03:08 -0400 Subject: [PATCH] Basics of API use. --- FRP.xcodeproj/project.pbxproj | 12 +++++ FRP/FRP-Prefix.pch | 1 + FRP/FRPAppDelegate.h | 2 + FRP/FRPAppDelegate.m | 14 +++++- FRP/FRPCell.h | 13 +++++ FRP/FRPCell.m | 31 ++++++++++++ FRP/FRPGalleryViewController.h | 15 ++++++ FRP/FRPGalleryViewController.m | 89 ++++++++++++++++++++++++++++++++++ Podfile | 1 + Podfile.lock | 88 +++++++++++++++++++++++++++++++++ 10 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 FRP/FRPCell.h create mode 100644 FRP/FRPCell.m create mode 100644 FRP/FRPGalleryViewController.h create mode 100644 FRP/FRPGalleryViewController.m diff --git a/FRP.xcodeproj/project.pbxproj b/FRP.xcodeproj/project.pbxproj index 65faf1a..d531517 100644 --- a/FRP.xcodeproj/project.pbxproj +++ b/FRP.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 2826EB375D254DDD8DE6EAA8 /* libPods-FRP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */; }; + 5EBC599E180B247500B683A7 /* FRPCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC599D180B247500B683A7 /* FRPCell.m */; }; 5EBE2AF5180B07D0007B6BF3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AF4180B07D0007B6BF3 /* Foundation.framework */; }; 5EBE2AF7180B07D0007B6BF3 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AF6180B07D0007B6BF3 /* CoreGraphics.framework */; }; 5EBE2AF9180B07D0007B6BF3 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AF8180B07D0007B6BF3 /* UIKit.framework */; }; @@ -21,6 +22,7 @@ 5EBE2B16180B07D0007B6BF3 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AFA180B07D0007B6BF3 /* CoreData.framework */; }; 5EBE2B1E180B07D0007B6BF3 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5EBE2B1C180B07D0007B6BF3 /* InfoPlist.strings */; }; 5EBE2B20180B07D0007B6BF3 /* FRPTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBE2B1F180B07D0007B6BF3 /* FRPTests.m */; }; + 5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -34,6 +36,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 5EBC599C180B247500B683A7 /* FRPCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPCell.h; sourceTree = ""; }; + 5EBC599D180B247500B683A7 /* FRPCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPCell.m; sourceTree = ""; }; 5EBE2AF1180B07D0007B6BF3 /* FRP.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FRP.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5EBE2AF4180B07D0007B6BF3 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 5EBE2AF6180B07D0007B6BF3 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -51,6 +55,8 @@ 5EBE2B1B180B07D0007B6BF3 /* FRPTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "FRPTests-Info.plist"; sourceTree = ""; }; 5EBE2B1D180B07D0007B6BF3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 5EBE2B1F180B07D0007B6BF3 /* FRPTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FRPTests.m; sourceTree = ""; }; + 5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPGalleryViewController.h; sourceTree = ""; }; + 5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPGalleryViewController.m; sourceTree = ""; }; 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FRP.a"; sourceTree = BUILT_PRODUCTS_DIR; }; CF6C5FA73F5F4703A3C7C4C0 /* Pods-FRP.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FRP.xcconfig"; path = "Pods/Pods-FRP.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -119,6 +125,10 @@ children = ( 5EBE2B05180B07D0007B6BF3 /* FRPAppDelegate.h */, 5EBE2B06180B07D0007B6BF3 /* FRPAppDelegate.m */, + 5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */, + 5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */, + 5EBC599C180B247500B683A7 /* FRPCell.h */, + 5EBC599D180B247500B683A7 /* FRPCell.m */, 5EBE2B0B180B07D0007B6BF3 /* Images.xcassets */, 5EBE2AFD180B07D0007B6BF3 /* Supporting Files */, ); @@ -285,7 +295,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5EBC599E180B247500B683A7 /* FRPCell.m in Sources */, 5EBE2B03180B07D0007B6BF3 /* main.m in Sources */, + 5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */, 5EBE2B07180B07D0007B6BF3 /* FRPAppDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/FRP/FRP-Prefix.pch b/FRP/FRP-Prefix.pch index e7a80d6..1429c0c 100644 --- a/FRP/FRP-Prefix.pch +++ b/FRP/FRP-Prefix.pch @@ -19,6 +19,7 @@ // Pods #import #import <500px-iOS-api/PXAPI.h> +#import // App Delegate #import "FRPAppDelegate.h" diff --git a/FRP/FRPAppDelegate.h b/FRP/FRPAppDelegate.h index 5c6fb85..c39e011 100644 --- a/FRP/FRPAppDelegate.h +++ b/FRP/FRPAppDelegate.h @@ -12,4 +12,6 @@ @property (strong, nonatomic) UIWindow *window; +@property (nonatomic, readonly) PXAPIHelper *apiHelper; + @end diff --git a/FRP/FRPAppDelegate.m b/FRP/FRPAppDelegate.m index 6c7aaf8..11cbe5e 100644 --- a/FRP/FRPAppDelegate.m +++ b/FRP/FRPAppDelegate.m @@ -8,13 +8,23 @@ #import "FRPAppDelegate.h" -@implementation FRPAppDelegate +#import "FRPGalleryViewController.h" +@interface FRPAppDelegate () + +@property (nonatomic, strong) PXAPIHelper *apiHelper; + +@end + +@implementation FRPAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + self.apiHelper = [[PXAPIHelper alloc] initWithHost:nil consumerKey:@"DC2To2BS0ic1ChKDK15d44M42YHf9gbUJgdFoF0m" consumerSecret:@"i8WL4chWoZ4kw9fh3jzHK7XzTer1y5tUNvsTFNnB"]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - // Override point for customization after application launch. + self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[FRPGalleryViewController alloc] init]]; + self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; diff --git a/FRP/FRPCell.h b/FRP/FRPCell.h new file mode 100644 index 0000000..c41fb6a --- /dev/null +++ b/FRP/FRPCell.h @@ -0,0 +1,13 @@ +// +// FRPCell.h +// FRP +// +// Created by Ash Furrow on 10/13/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +#import + +@interface FRPCell : UICollectionViewCell + +@end diff --git a/FRP/FRPCell.m b/FRP/FRPCell.m new file mode 100644 index 0000000..ec389aa --- /dev/null +++ b/FRP/FRPCell.m @@ -0,0 +1,31 @@ +// +// FRPCell.m +// FRP +// +// Created by Ash Furrow on 10/13/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +#import "FRPCell.h" + +@implementation FRPCell + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code + } + return self; +} + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect +{ + // Drawing code +} +*/ + +@end diff --git a/FRP/FRPGalleryViewController.h b/FRP/FRPGalleryViewController.h new file mode 100644 index 0000000..7db866f --- /dev/null +++ b/FRP/FRPGalleryViewController.h @@ -0,0 +1,15 @@ +// +// FRPGalleryViewController.h +// FRP +// +// Created by Ash Furrow on 10/13/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +#import + +@interface FRPGalleryViewController : UICollectionViewController + +-(id)init; + +@end diff --git a/FRP/FRPGalleryViewController.m b/FRP/FRPGalleryViewController.m new file mode 100644 index 0000000..6d3d0ec --- /dev/null +++ b/FRP/FRPGalleryViewController.m @@ -0,0 +1,89 @@ +// +// FRPGalleryViewController.m +// FRP +// +// Created by Ash Furrow on 10/13/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +#import "FRPGalleryViewController.h" +#import "FRPCell.h" + +static NSString *CellIdentifier = @"Cell"; + +@interface FRPGalleryViewController () + +@property (nonatomic, strong) NSArray *photosArray; + +@end + +@implementation FRPGalleryViewController + +- (id)init +{ + UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; + + self = [super initWithCollectionViewLayout:flowLayout]; + if (!self) return nil; + + flowLayout.itemSize = CGSizeMake(145, 145); + flowLayout.minimumInteritemSpacing = 10; + flowLayout.minimumLineSpacing = 10; + flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10); + + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // Configure self + self.title = @"Popular on 500px"; + + // Configure view + [self.collectionView registerClass:[FRPCell class] forCellWithReuseIdentifier:CellIdentifier]; + + // Reactive Stuff + @weakify(self); + [RACObserve(self, photosArray) subscribeNext:^(id x) { + @strongify(self); + + [self.collectionView reloadData]; + }]; + + [self loadPopularPhotos]; +} + +#pragma mark - Private Methods + +-(void)loadPopularPhotos { + NSURLRequest *request = [AppDelegate.apiHelper urlRequestForPhotoFeature:PXAPIHelperPhotoFeaturePopular resultsPerPage:100 page:1 photoSizes:PXPhotoModelSizeThumbnail sortOrder:PXAPIHelperSortOrderRating except:PXPhotoModelCategoryNude]; + + [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + if (data) { + id results = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + + self.photosArray = results[@"photos"]; + } + else { + NSLog(@"Couldn't fetch from 500px: %@", connectionError); + } + }]; +} + +#pragma mark - UICollectionViewDataSource Methods + +-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { + return self.photosArray.count; +} + +-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { + FRPCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; + + cell.backgroundColor = [UIColor purpleColor]; + + return cell; +} + +@end diff --git a/Podfile b/Podfile index 30e5bef..2050725 100644 --- a/Podfile +++ b/Podfile @@ -3,6 +3,7 @@ platform :ios, "7.0" target "FRP" do pod 'ReactiveCocoa', '2.1' +pod 'libextobjc', '0.3' pod '500px-iOS-api', '1.0.4' end diff --git a/Podfile.lock b/Podfile.lock index a3d8225..842e756 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,5 +1,90 @@ PODS: - 500px-iOS-api (1.0.4) + - libextobjc (0.3): + - libextobjc/EXTADT + - libextobjc/EXTAnnotation + - libextobjc/EXTAspect + - libextobjc/EXTBlockMethod + - libextobjc/EXTBlockTarget + - libextobjc/EXTConcreteProtocol + - libextobjc/EXTDispatchObject + - libextobjc/EXTFinalMethod + - libextobjc/EXTKeyPathCoding + - libextobjc/EXTMaybe + - libextobjc/EXTMixin + - libextobjc/EXTMultimethod + - libextobjc/EXTMultiObject + - libextobjc/EXTNil + - libextobjc/EXTPassthrough + - libextobjc/EXTPrivateMethod + - libextobjc/EXTProtocolCategory + - libextobjc/EXTSafeCategory + - libextobjc/EXTScope + - libextobjc/EXTSelectorChecking + - libextobjc/EXTSwizzle + - libextobjc/EXTSynthesize + - libextobjc/EXTTuple + - libextobjc/EXTVarargs + - libextobjc/NSInvocation+EXT + - libextobjc/NSMethodSignature+EXT + - libextobjc/RuntimeExtensions + - libextobjc/UmbrellaHeader + - libextobjc/EXTADT (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTAnnotation (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTAspect (0.3): + - libextobjc/RuntimeExtensions + - libffi + - libextobjc/EXTBlockMethod (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTBlockTarget (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTConcreteProtocol (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTDispatchObject (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTFinalMethod (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTKeyPathCoding (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTMaybe (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTMixin (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTMultimethod (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTMultiObject (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTNil (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTPassthrough (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTPrivateMethod (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTProtocolCategory (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTSafeCategory (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTScope (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTSelectorChecking (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTSwizzle (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTSynthesize (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTTuple (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/EXTVarargs (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/NSInvocation+EXT (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/NSMethodSignature+EXT (0.3): + - libextobjc/RuntimeExtensions + - libextobjc/RuntimeExtensions (0.3) + - libextobjc/UmbrellaHeader (0.3) + - libffi (3.0.13) - ReactiveCocoa (2.1): - ReactiveCocoa/Core - ReactiveCocoa/no-arc @@ -9,10 +94,13 @@ PODS: DEPENDENCIES: - 500px-iOS-api (= 1.0.4) + - libextobjc (= 0.3) - ReactiveCocoa (= 2.1) SPEC CHECKSUMS: 500px-iOS-api: fde71ddd4a05f06b94b8ec7c29bbcd2e589b7e70 + libextobjc: 820a79dbbbc498611e04fffd07d2d52a5588e7ac + libffi: 64ef39353e747bb2b25e1026afd96a157bf9231c ReactiveCocoa: b686fa735c28c2dc7311fbd2f0895b4d4ae07360 COCOAPODS: 0.25.0