Permalink
Browse files

Merge pull request #1 from meredian/macos_10_6.

Update for MasOS 10.6
  • Loading branch information...
Caged committed May 3, 2011
2 parents 6d61406 + 09e75bc commit 8361de09f04d28651f6e384bd3c7cad08c7422a0
@@ -14,6 +14,8 @@
@interface ConcurrentOperationTestAppDelegate : NSObject <SomeNetworkOperationDelegate, UIApplicationDelegate> {
UIWindow *window;
ConcurrentOperationTestViewController *viewController;
+
+ NSOperationQueue *queue;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@@ -22,30 +22,29 @@ @implementation ConcurrentOperationTestAppDelegate
@synthesize viewController;
-- (void)applicationDidFinishLaunching:(UIApplication *)application {
-
- NSOperationQueue *queue = [[NSOperationQueue alloc] init];
+- (void)applicationDidFinishLaunching:(UIApplication *)application {
+
+ queue = [[[NSOperationQueue alloc] init] retain];
[queue setMaxConcurrentOperationCount:3];
-
+
for(NSURL *url in [self urlFixtures]) {
- SomeNetworkOperation *op = [[SomeNetworkOperation alloc] init];
+ SomeNetworkOperation *op = [[[SomeNetworkOperation alloc] init] autorelease];
op.delegate = self;
op.urlToLoad = url;
[queue addOperation:op];
- [op release];
}
-
+
viewController.countLabel.text = @"Images Loaded: 0";
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
-- (void)didFinishLoad:(NSDictionary *)info
+- (void)didFinishLoad:(NSDictionary *)info
{
NSURL *url = [info valueForKey:@"url"];
totalImagesLoaded += 1;
viewController.countLabel.text = [NSString stringWithFormat:@"Images Loaded: %i/%i", totalImagesLoaded, [[self urlFixtures] count]];
-
+
NSLog(@"FINISHED LOADING URL:%@", url);
}
@@ -73,6 +72,7 @@ - (NSArray *)urlFixtures
- (void)dealloc {
+ [queue release];
[viewController release];
[window release];
[super dealloc];
@@ -48,15 +48,15 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
*/
- (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
+ // Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
-
- // Release any cached data, images, etc that aren't in use.
+
+ // Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
}
@@ -12,10 +12,10 @@
@interface SomeNetworkOperation : NSOperation {
id <SomeNetworkOperationDelegate>_delegate;
NSURL *_urlToLoad;
-
+
NSURLConnection *_connection;
NSMutableData *_responseData;
-
+
BOOL _isFinished;
BOOL _isExecuting;
}
@@ -17,11 +17,11 @@ @implementation SomeNetworkOperation
- (id)init
{
- if(self = [super init]) {
+ if((self = [super init])) {
_isExecuting = NO;
_isFinished = NO;
}
-
+
return self;
}
@@ -37,24 +37,37 @@ - (BOOL)isConcurrent {
- (void)start
{
+ if (![NSThread isMainThread])
+ {
+ [self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO];
+ return;
+ }
+
+ if ([self isCancelled]) {
+ [self willChangeValueForKey:@"isFinished"];
+ _isFinished = YES;
+ [self didChangeValueForKey:@"isFinished"];
+ return;
+ }
+
[self willChangeValueForKey:@"isExecuting"];
_isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
-
+
NSURLRequest *request = [NSURLRequest requestWithURL:self.urlToLoad cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
-
+
if(_connection) {
- _responseData = [[NSMutableData alloc] init];
+ _responseData = [[[NSMutableData alloc] init] retain];
} else {
[self finish];
- }
+ }
}
- (void)finish {
[_connection release];
_connection = nil;
-
+
[_responseData release];
_responseData = nil;
@@ -85,23 +98,22 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
-
+
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
-
+
[self finish];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
- UIImage *img = [[UIImage alloc] initWithData:_responseData];
+ UIImage *img = [[[UIImage alloc] initWithData:_responseData] autorelease];
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:img, @"img", _urlToLoad, @"url", nil];
-
+
if([_delegate respondsToSelector:@selector(didFinishLoad:)]) {
[_delegate performSelector:@selector(didFinishLoad:) withObject:info];
}
-
- [img release];
+
[self finish];
}
@end
@@ -141,7 +141,11 @@
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ConcurrentOperationTest" */;
compatibilityVersion = "Xcode 3.1";
+ developmentRegion = English;
hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
projectDirPath = "";
projectRoot = "";
@@ -188,7 +192,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ConcurrentOperationTest_Prefix.pch;
INFOPLIST_FILE = "ConcurrentOperationTest-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PRODUCT_NAME = ConcurrentOperationTest;
+ TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
@@ -200,7 +206,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ConcurrentOperationTest_Prefix.pch;
INFOPLIST_FILE = "ConcurrentOperationTest-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PRODUCT_NAME = ConcurrentOperationTest;
+ TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
};
@@ -212,8 +220,9 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.2;
PREBINDING = NO;
- SDKROOT = iphoneos3.0;
+ SDKROOT = iphoneos4.3;
};
name = Debug;
};
@@ -225,8 +234,9 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.2;
PREBINDING = NO;
- SDKROOT = iphoneos3.0;
+ SDKROOT = iphoneos4.3;
};
name = Release;
};
View
2 main.m
@@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
-
+
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];

0 comments on commit 8361de0

Please sign in to comment.