From cc49cd8d1c4081ffd6a05cb112beb0d03b497f12 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 19 Jan 2012 11:33:30 -0800 Subject: [PATCH] Major refactoring to Mac example code, removing a lot of code in favor of bindings --- .../Controllers/NearbySpotsController.h | 4 +- .../Controllers/NearbySpotsController.m | 41 +---- Mac Example/Classes/Models/Spot.h | 6 +- Mac Example/Classes/Models/Spot.m | 5 +- Mac Example/en.lproj/MainMenu.xib | 171 +++++++++++------- 5 files changed, 109 insertions(+), 118 deletions(-) diff --git a/Mac Example/Classes/Controllers/NearbySpotsController.h b/Mac Example/Classes/Controllers/NearbySpotsController.h index d70623f..d719337 100644 --- a/Mac Example/Classes/Controllers/NearbySpotsController.h +++ b/Mac Example/Classes/Controllers/NearbySpotsController.h @@ -23,8 +23,8 @@ #import #import -@interface NearbySpotsController : NSObject +@interface NearbySpotsController : NSObject -@property (strong) IBOutlet NSTableView *tableView; +@property (strong) NSArray *nearbySpots; @end diff --git a/Mac Example/Classes/Controllers/NearbySpotsController.m b/Mac Example/Classes/Controllers/NearbySpotsController.m index 9908531..d426bff 100644 --- a/Mac Example/Classes/Controllers/NearbySpotsController.m +++ b/Mac Example/Classes/Controllers/NearbySpotsController.m @@ -24,12 +24,8 @@ #import "Spot.h" -#import "AFImageRequestOperation.h" - @interface NearbySpotsController () -@property (strong) NSArray *nearbySpots; @property (strong) CLLocationManager *locationManager; -@property (strong) NSOperationQueue *imageOperationQueue; - (void)loadSpotsForLocation:(CLLocation *)location; @end @@ -37,8 +33,6 @@ @implementation NearbySpotsController @synthesize nearbySpots = _nearbySpots; @synthesize locationManager = _locationManager; -@synthesize imageOperationQueue = _imageOperationQueue; -@synthesize tableView = _tableView; - (id)init { self = [super init]; @@ -52,9 +46,6 @@ self.locationManager.delegate = self; self.locationManager.distanceFilter = 80.0; - self.imageOperationQueue = [[NSOperationQueue alloc] init]; - self.imageOperationQueue.maxConcurrentOperationCount = 8; - return self; } @@ -79,9 +70,7 @@ } else { return NSOrderedSame; } - }]; - - [self.tableView reloadData]; + }]; }]; } @@ -91,32 +80,4 @@ [self loadSpotsForLocation:newLocation]; } -#pragma mark - NSTableViewDataSource - -- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { - return [self.nearbySpots count]; -} - -// The following is what happens when a longtime iOS dev attempts to work with AppKit. I'm sure there's a _much_ better way to do this. -- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - Spot *spot = [self.nearbySpots objectAtIndex:row]; - - if ([[tableColumn dataCell] isMemberOfClass:[NSImageCell class]]) { - if (spot.image) { - return spot.image; - } else { - NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:spot.imageURLString]]; - AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:imageRequest success:^(NSImage *image) { - spot.image = image; - [tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]]; - }]; - [self.imageOperationQueue addOperation:operation]; - - return [NSImage imageNamed:@"placeholder-stamp.png"]; - } - } else { - return spot.name; - } -} - @end diff --git a/Mac Example/Classes/Models/Spot.h b/Mac Example/Classes/Models/Spot.h index 0530815..af5b4d5 100644 --- a/Mac Example/Classes/Models/Spot.h +++ b/Mac Example/Classes/Models/Spot.h @@ -26,15 +26,13 @@ @interface Spot : NSObject { @private NSString *_name; - NSString *_imageURLString; - NSImage *_image; + NSURL *_imageURL; NSNumber *_latitude; NSNumber *_longitude; } @property (strong) NSString *name; -@property (strong) NSString *imageURLString; -@property (strong) NSImage *image; +@property (strong) NSURL *imageURL; @property (strong) NSNumber *latitude; @property (strong) NSNumber *longitude; @property (readonly) CLLocation *location; diff --git a/Mac Example/Classes/Models/Spot.m b/Mac Example/Classes/Models/Spot.m index 43e2ab7..dc899a5 100644 --- a/Mac Example/Classes/Models/Spot.m +++ b/Mac Example/Classes/Models/Spot.m @@ -26,8 +26,7 @@ @implementation Spot @synthesize name = _name; -@synthesize imageURLString = _imageURLString; -@synthesize image = _image; +@synthesize imageURL = _imageURL; @synthesize latitude = _latitude; @synthesize longitude = _longitude; @dynamic location; @@ -39,7 +38,7 @@ } self.name = [attributes valueForKeyPath:@"name"]; - self.imageURLString = [attributes valueForKeyPath:@"image_url"]; + self.imageURL = [NSURL URLWithString:[attributes valueForKeyPath:@"image_url"]]; self.latitude = [attributes valueForKeyPath:@"lat"]; self.longitude = [attributes valueForKeyPath:@"lng"]; diff --git a/Mac Example/en.lproj/MainMenu.xib b/Mac Example/en.lproj/MainMenu.xib index de1165c..bddf394 100644 --- a/Mac Example/en.lproj/MainMenu.xib +++ b/Mac Example/en.lproj/MainMenu.xib @@ -1,28 +1,29 @@ - 0 - 11A511 - 1900 - 1138 - 566.00 + 1070 + 11C74 + 1938 + 1138.23 + 567.00 com.apple.InterfaceBuilder.CocoaPlugin - 1900 + 1938 YES - NSView + NSScroller + NSArrayController + NSMenuItem NSMenu NSScrollView - NSWindowTemplate - NSMenuItem - NSTableView NSTextFieldCell NSImageCell - NSTableColumn - NSScroller + NSTableView NSCustomObject + NSView + NSWindowTemplate + NSTableColumn YES @@ -278,6 +279,7 @@ 256 {373, 498} + _NS:1197 YES @@ -412,6 +414,7 @@ {{1, 1}, {373, 498}} + _NS:1195 @@ -423,6 +426,7 @@ -2147483392 {{224, 17}, {15, 102}} + _NS:1214 @@ -434,6 +438,8 @@ -2147483392 {{1, 526}, {374, 15}} + + _NS:1216 1 @@ -443,6 +449,7 @@ {375, 500} + _NS:1193 133682 @@ -454,9 +461,10 @@ {375, 500} + - {{0, 0}, {1920, 1178}} + {{0, 0}, {1440, 878}} {375, 222} {375, 1302} YES @@ -467,6 +475,15 @@ NSFontManager + + Spot + + YES + YES + YES + YES + YES + NearbySpotsController @@ -474,6 +491,30 @@ YES + + + terminate: + + + + 449 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + delegate + + + + 495 + performMiniaturize: @@ -490,14 +531,6 @@ 39 - - - orderFrontStandardAboutPanel: - - - - 142 - performZoom: @@ -530,14 +563,6 @@ 370 - - - terminate: - - - - 449 - showHelp: @@ -546,14 +571,6 @@ 493 - - - delegate - - - - 495 - window @@ -563,28 +580,52 @@ 532 - - tableView - - + + valueURL: arrangedObjects.imageURL + + + + + + valueURL: arrangedObjects.imageURL + valueURL + arrangedObjects.imageURL + 2 + - 550 + 562 - - dataSource - - + + value: arrangedObjects.name + + + + + + value: arrangedObjects.name + value + arrangedObjects.name + 2 + - 551 + 566 - - delegate - + + contentArray: nearbySpots + + + + + contentArray: nearbySpots + contentArray + nearbySpots + 2 + - 552 + 560 @@ -859,7 +900,12 @@ - 549 + 555 + + + + + 556 @@ -904,7 +950,8 @@ 543.IBPluginDependency 544.IBPluginDependency 546.IBPluginDependency - 549.IBPluginDependency + 555.IBPluginDependency + 556.IBPluginDependency 56.IBPluginDependency 57.IBPluginDependency 58.IBPluginDependency @@ -952,6 +999,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -966,7 +1014,7 @@ - 554 + 567 @@ -993,17 +1041,6 @@ NearbySpotsController NSObject - - tableView - NSTableView - - - tableView - - tableView - NSTableView - - IBProjectSource ./Classes/NearbySpotsController.h @@ -1013,10 +1050,6 @@ 0 IBCocoaFramework - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3