diff --git a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj index acfe4ce..fd75074 100644 --- a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj @@ -119,9 +119,7 @@ children = ( F8129C311591073C009BFE23 /* AFTwitterAPIClient.h */, F8129C251591073C009BFE23 /* AFTwitterAPIClient.m */, - F8129C261591073C009BFE23 /* Controllers */, F8129C291591073C009BFE23 /* Models */, - F8129C2E1591073C009BFE23 /* Views */, F8129C061591061B009BFE23 /* Supporting Files */, ); name = Classes; @@ -139,14 +137,6 @@ name = "Supporting Files"; sourceTree = ""; }; - F8129C261591073C009BFE23 /* Controllers */ = { - isa = PBXGroup; - children = ( - ); - name = Controllers; - path = Classes/Controllers; - sourceTree = SOURCE_ROOT; - }; F8129C291591073C009BFE23 /* Models */ = { isa = PBXGroup; children = ( @@ -159,14 +149,6 @@ path = Classes/Models; sourceTree = SOURCE_ROOT; }; - F8129C2E1591073C009BFE23 /* Views */ = { - isa = PBXGroup; - children = ( - ); - name = Views; - path = Classes/Views; - sourceTree = SOURCE_ROOT; - }; F8129C4C15910901009BFE23 /* Vendor */ = { isa = PBXGroup; children = ( diff --git a/Example/AppDelegate.m b/Example/AppDelegate.m index 15cc02e..3feb742 100644 --- a/Example/AppDelegate.m +++ b/Example/AppDelegate.m @@ -33,8 +33,8 @@ @synthesize navigationController = _navigationController; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 diskCapacity:1024 * 1024 * 5 diskPath:nil]; -[NSURLCache setSharedURLCache:URLCache]; + NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 diskCapacity:1024 * 1024 * 5 diskPath:nil]; + [NSURLCache setSharedURLCache:URLCache]; [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; @@ -55,6 +55,7 @@ #else #import "Tweet.h" +#import "User.h" @implementation AppDelegate @@ -62,6 +63,9 @@ @synthesize tweetsArrayController = _tweetsArrayController; - (void)applicationDidFinishLaunching:(NSNotification *)notification { + NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 diskCapacity:1024 * 1024 * 5 diskPath:nil]; + [NSURLCache setSharedURLCache:URLCache]; + [self.window makeKeyAndOrderFront:self]; [Tweet publicTimelineTweetsWithBlock:^(NSArray *tweets) { diff --git a/Example/Classes/Models/User.h b/Example/Classes/Models/User.h index 744dc13..5f9f45c 100644 --- a/Example/Classes/Models/User.h +++ b/Example/Classes/Models/User.h @@ -30,4 +30,8 @@ - (id)initWithAttributes:(NSDictionary *)attributes; +#if __MAC_OS_X_VERSION_MIN_REQUIRED +@property (nonatomic, strong) NSImage *profileImage; +#endif + @end diff --git a/Example/Classes/Models/User.m b/Example/Classes/Models/User.m index 6d8dcdb..7c0d0a9 100644 --- a/Example/Classes/Models/User.m +++ b/Example/Classes/Models/User.m @@ -21,12 +21,16 @@ // THE SOFTWARE. #import "User.h" +#import "AFImageRequestOperation.h" + +@interface User () ++ (NSOperationQueue *)sharedProfileImageRequestOperationQueue; +@end @implementation User { @private - NSUInteger _userID; - __strong NSString *_username; __strong NSString *_profileImageURLString; + __strong AFImageRequestOperation *_profileImageRequestOperation; } @synthesize userID = _userID; @@ -49,4 +53,39 @@ return [NSURL URLWithString:_profileImageURLString]; } +#if __MAC_OS_X_VERSION_MIN_REQUIRED + +@synthesize profileImage = _profileImage; + ++ (NSOperationQueue *)sharedProfileImageRequestOperationQueue { + static NSOperationQueue *_sharedProfileImageRequestOperationQueue = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _sharedProfileImageRequestOperationQueue = [[NSOperationQueue alloc] init]; + [_sharedProfileImageRequestOperationQueue setMaxConcurrentOperationCount:8]; + }); + + return _sharedProfileImageRequestOperationQueue; +} + +- (NSImage *)profileImage { + if (!_profileImage && !_profileImageRequestOperation) { + _profileImageRequestOperation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:self.profileImageURL] success:^(NSImage *image) { + self.profileImage = image; + + _profileImageRequestOperation = nil; + }]; + + [_profileImageRequestOperation setCacheResponseBlock:^NSCachedURLResponse *(NSURLConnection *connection, NSCachedURLResponse *cachedResponse) { + return [[NSCachedURLResponse alloc] initWithResponse:cachedResponse.response data:cachedResponse.data userInfo:cachedResponse.userInfo storagePolicy:NSURLCacheStorageAllowed]; + }]; + + [[[self class] sharedProfileImageRequestOperationQueue] addOperation:_profileImageRequestOperation]; + } + + return _profileImage; +} + +#endif + @end diff --git a/Example/MainMenu.xib b/Example/MainMenu.xib index dcded69..5d713ef 100644 --- a/Example/MainMenu.xib +++ b/Example/MainMenu.xib @@ -22,6 +22,7 @@ NSImageCell NSTableView NSTableCellView + IBNSLayoutConstraint NSCustomObject NSView NSWindowTemplate @@ -168,7 +169,7 @@ _NSAppleMenu - + File @@ -176,12 +177,12 @@ submenuAction: - + File YES - - + + New n 1048576 @@ -189,8 +190,8 @@ - - + + Open… o 1048576 @@ -198,20 +199,20 @@ - - + + Open Recent 2147483647 submenuAction: - + Open Recent YES - - + + Clear Menu 1048576 @@ -223,8 +224,8 @@ _NSRecentDocumentsMenu - - + + YES YES @@ -233,8 +234,8 @@ - - + + Close w 1048576 @@ -242,8 +243,8 @@ - - + + Save s 1048576 @@ -251,8 +252,8 @@ - - + + Save As… S 1048576 @@ -260,16 +261,16 @@ - - + + Revert to Saved 2147483647 - - + + YES YES @@ -278,8 +279,8 @@ - - + + Page Setup… P 1048576 @@ -287,8 +288,8 @@ - - + + Print… p 1048576 @@ -383,10 +384,10 @@ _NSMainMenu - 15 + 4111 2 {{60, 295}, {331, 500}} - 1954021376 + 1954022400 AFNetworking Mac Example NSWindow @@ -411,10 +412,10 @@ 256 - {373, 498} + {331, 498} - + _NS:1197 YES @@ -426,7 +427,7 @@ YES - 320 + 321 70 10000 @@ -491,8 +492,8 @@ MC41AA - 70 - 373325824 + 85 + 381714432 1 @@ -503,7 +504,7 @@ 1 - {{1, 1}, {373, 498}} + {{1, 1}, {331, 498}} @@ -513,7 +514,7 @@ 6 System controlBackgroundColor - + 3 MC42NjY2NjY2NjY3AA @@ -546,7 +547,7 @@ 0.99732620320855614 - {375, 500} + {{-1, 0}, {333, 500}} @@ -555,7 +556,7 @@ - QSAAAEEgAABCoAAAQqAAAA + QSAAAEEgAABCvgAAQr4AAA {331, 500} @@ -671,7 +672,7 @@ print: - + 632 @@ -679,7 +680,7 @@ performClose: - + 634 @@ -687,7 +688,7 @@ saveDocumentAs: - + 637 @@ -695,7 +696,7 @@ runPageLayout: - + 638 @@ -703,7 +704,7 @@ saveDocument: - + 639 @@ -711,7 +712,7 @@ revertDocumentToSaved: - + 640 @@ -719,7 +720,7 @@ newDocument: - + 635 @@ -727,7 +728,7 @@ clearRecentDocuments: - + 636 @@ -735,7 +736,7 @@ openDocument: - + 633 @@ -774,20 +775,20 @@ textField - + 274 YES - - + + 266 - {{84, 50}, {236, 17}} - - + {{84, 65}, {237, 17}} + + {250, 750} YES - + 67239488 272631808 Username @@ -796,14 +797,14 @@ 14 16 - - + + 6 System controlColor - + - + 6 System controlTextColor @@ -811,8 +812,8 @@ - - + + 268 YES @@ -826,12 +827,12 @@ NeXT TIFF v4.0 pasteboard type - {{14, 7}, {56, 56}} - - + {{14, 21}, {56, 56}} + + _NS:9 YES - + 130560 33554432 _NS:9 @@ -842,46 +843,46 @@ YES - - + + 268 - {{84, 10}, {236, 34}} - + {{84, 3}, {236, 56}} + _NS:9 {250, 750} YES - + 67239424 272629760 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad mi. LucidaGrande - 13 + 11 16 _NS:9 - - - + + + - {{5, 5}, {320, 70}} - + {{5, 5}, {321, 85}} + - + 580 value: objectValue.user.username - - + + - - + + value: objectValue.user.username value objectValue.user.username @@ -892,12 +893,28 @@ - value: objectValue.text - - + value: objectValue.user.profileImage + + - - + + + value: objectValue.user.profileImage + value + objectValue.user.profileImage + 2 + + + 829 + + + + value: objectValue.text + + + + + value: objectValue.text value objectValue.text @@ -944,7 +961,7 @@ - + @@ -1084,6 +1101,70 @@ YES + + + 10 + 0 + + 10 + 1 + + 0.0 + + 1000 + 5 + 22 + 2 + + + + + 6 + 0 + + 6 + 1 + + -1 + + 1000 + 8 + 29 + 3 + + + + + 5 + 0 + + 5 + 1 + + -1 + + 1000 + 8 + 29 + 3 + + + + + 3 + 0 + + 3 + 1 + + 0.0 + + 1000 + 3 + 9 + 3 + + @@ -1152,7 +1233,7 @@ YES - + @@ -1173,157 +1254,492 @@ 577 - + YES - - - + + + + + 3 + 0 + + 3 + 1 + + 26 + + 1000 + 9 + 40 + 3 + + + + + + 5 + 0 + + 5 + 1 + + 17 + + 1000 + 3 + 9 + 3 + + + + + 3 + 0 + + 3 + 1 + + 11 + + 1000 + 3 + 9 + 3 + + + + + 6 + 0 + + 6 + 1 + + 3 + + 1000 + 9 + 40 + 3 + + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + 9 + 40 + 2 + + + + + 3 + 0 + + 3 + 1 + + 3 + + 1000 + 8 + 29 + 3 + + + + + 9 + 0 + + 9 + 1 + + 0.0 + + 1000 + 9 + 40 + 2 + + + + + 5 + 0 + + 5 + 1 + + 87 + + 1000 + 9 + 40 + 3 + + + + + 5 + 0 + + 5 + 1 + + 87 + + 1000 + 9 + 40 + 3 + + 578 - + YES - + + + + 8 + 0 + + 0 + 1 + + 17 + + 1000 + 3 + 9 + 1 + + - + 579 - - + + 594 - + YES - + + + + 8 + 0 + + 0 + 1 + + 50 + + 1000 + 9 + 40 + 1 + + + + + 7 + 0 + + 0 + 1 + + 50 + + 1000 + 3 + 9 + 1 + + - + 595 - - + + 596 - + YES - + + + + 8 + 1 + + 0 + 1 + + 34 + + 1000 + 9 + 40 + 1 + + + + + 8 + 0 + + 0 + 1 + + 56 + + 1000 + 3 + 9 + 1 + + + + + 7 + 0 + + 0 + 1 + + 230 + + 652 + 9 + 40 + 1 + + - + 597 - - + + 617 - + YES - + 618 - + YES - - - - - - - - - - - + + + + + + + + + + + - + 622 - - + + 623 - - + + 624 - - + + 625 - - + + 626 - - + + 627 - - + + 628 - - + + 629 - - + + 619 - - + + 621 - + YES - + - + 630 - + YES - + - + 631 - - + + 620 - - + + + + + 694 + + + + + 702 + + + + + 714 + + + + + 732 + + + + + 813 + + + + + 814 + + + + + 816 + + + + + 824 + + + + + 836 + + + + + 837 + + + + + 838 + + + + + 839 + + + + + 840 + + + + + 841 + + + + + 842 + + + + + 843 + + + + + 844 + + + + + 845 + + + + + 846 + + @@ -1351,6 +1767,7 @@ 371.IBPluginDependency 371.IBWindowTemplateEditedContentRect 371.NSWindowTemplate.visibleAtLaunch + 372.IBNSViewMetadataConstraints 372.IBPluginDependency 420.IBPluginDependency 490.IBPluginDependency @@ -1358,6 +1775,7 @@ 492.IBPluginDependency 494.IBPluginDependency 5.IBPluginDependency + 537.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints 537.IBPluginDependency 538.IBPluginDependency 540.IBPluginDependency @@ -1370,12 +1788,19 @@ 555.IBPluginDependency 56.IBPluginDependency 57.IBPluginDependency + 577.IBNSViewMetadataConstraints 577.IBPluginDependency + 578.IBNSViewMetadataConstraints + 578.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints 578.IBPluginDependency 579.IBPluginDependency 58.IBPluginDependency + 594.IBNSViewMetadataConstraints + 594.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints 594.IBPluginDependency 595.IBPluginDependency + 596.IBNSViewMetadataConstraints + 596.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints 596.IBPluginDependency 597.IBPluginDependency 617.IBPluginDependency @@ -1393,6 +1818,25 @@ 629.IBPluginDependency 630.IBPluginDependency 631.IBPluginDependency + 694.IBPluginDependency + 702.IBPluginDependency + 714.IBPluginDependency + 732.IBPluginDependency + 813.IBPluginDependency + 814.IBPluginDependency + 816.IBPluginDependency + 824.IBPluginDependency + 836.IBPluginDependency + 837.IBPluginDependency + 838.IBPluginDependency + 839.IBPluginDependency + 840.IBPluginDependency + 841.IBPluginDependency + 842.IBPluginDependency + 843.IBPluginDependency + 844.IBPluginDependency + 845.IBPluginDependency + 846.IBPluginDependency 92.IBPluginDependency @@ -1417,6 +1861,13 @@ com.apple.InterfaceBuilder.CocoaPlugin {{380, 496}, {480, 360}} + + YES + + + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1424,6 +1875,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1433,12 +1885,61 @@ YES - + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + YES + + + + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + + YES + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + YES + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + YES + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1477,7 +1978,7 @@ - 640 + 847 @@ -1522,6 +2023,14 @@ ./Classes/AppDelegate.h + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + 0 @@ -1547,5 +2056,6 @@ {50, 50} + YES diff --git a/Example/main.m b/Example/main.m index c94460c..44bc3d6 100644 --- a/Example/main.m +++ b/Example/main.m @@ -1,10 +1,23 @@ -// -// main.m -// AFNetworking-Mac-Example -// -// Created by Mattt Thompson on 12/06/19. -// Copyright (c) 2012年 __MyCompanyName__. All rights reserved. -// +// main.m +// Copyright (c) 2012 Mattt Thompson (http://mattt.me/) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. #if __IPHONE_OS_VERSION_MIN_REQUIRED #import