Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified NSThreadExample/.DS_Store
Binary file not shown.
7 changes: 6 additions & 1 deletion NSThreadExample/NSThreadExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = PT;
LastUpgradeCheck = 0500;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = KiloApp;
TargetAttributes = {
F48BF748177045A10082371C = {
Expand Down Expand Up @@ -331,6 +331,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -392,6 +393,7 @@
GCC_PREFIX_HEADER = "NSThreadExample/NSThreadExample-Prefix.pch";
INFOPLIST_FILE = "NSThreadExample/NSThreadExample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -406,6 +408,7 @@
GCC_PREFIX_HEADER = "NSThreadExample/NSThreadExample-Prefix.pch";
INFOPLIST_FILE = "NSThreadExample/NSThreadExample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -427,6 +430,7 @@
"$(inherited)",
);
INFOPLIST_FILE = "NSThreadExampleTests/NSThreadExampleTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand All @@ -445,6 +449,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NSThreadExample/NSThreadExample-Prefix.pch";
INFOPLIST_FILE = "NSThreadExampleTests/NSThreadExampleTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand Down
2 changes: 1 addition & 1 deletion NSThreadExample/NSThreadExample/NSThreadExample-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.kiloapp.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 4 additions & 0 deletions NSThreadExample/NSThreadExample/PTAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void mainRunLoopObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activi
CFStringRef mode = CFRunLoopCopyCurrentMode(CFRunLoopGetMain());
NSLog(@"Current main thread run loop mode: %@", (__bridge NSString *)mode);

CFRelease(mode);

CFArrayRef modeArray = CFRunLoopCopyAllModes(CFRunLoopGetMain());
if (CFArrayGetCount(modeArray) > 0)
{
Expand All @@ -26,6 +28,8 @@ void mainRunLoopObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activi
NSLog(@"Main thread run loop has mode: %@", (__bridge NSString *)mode);
}
}

CFRelease(modeArray);
}

@interface PTAppDelegate()
Expand Down
2 changes: 1 addition & 1 deletion NSThreadExample/NSThreadExample/PTCFRunLoopThread.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ - (void)main
{
[self cancel];
}
NSLog(@"exit run loop.........: %ld", result);
NSLog(@"exit run loop.........: %zd", result);
}
NSLog(@"finishing thread.........");
}
Expand Down
18 changes: 10 additions & 8 deletions NSThreadExample/NSThreadExample/PTInputSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@

@implementation RunLoopSource

- (id)init
- (instancetype)init
{
CFRunLoopSourceContext context = {0, (__bridge void *)(self), NULL, NULL, NULL, NULL, NULL,
&RunLoopSourceScheduleRoutine,
RunLoopSourceCancelRoutine,
RunLoopSourcePerformRoutine};

runLoopSource = CFRunLoopSourceCreate(NULL, 0, &context);
commands = [[NSMutableArray alloc] init];
if (self = [super init]) {
CFRunLoopSourceContext context = {0, (__bridge void *)(self), NULL, NULL, NULL, NULL, NULL,
&RunLoopSourceScheduleRoutine,
RunLoopSourceCancelRoutine,
RunLoopSourcePerformRoutine};

runLoopSource = CFRunLoopSourceCreate(NULL, 0, &context);
commands = [[NSMutableArray alloc] init];
}

return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.kiloapp.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = PT;
LastUpgradeCheck = 0500;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = KiloApp;
TargetAttributes = {
F44D2A6117798A5C00B48C77 = {
Expand Down Expand Up @@ -338,6 +338,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -396,6 +397,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NSURLConnectionExample/NSURLConnectionExample-Prefix.pch";
INFOPLIST_FILE = "NSURLConnectionExample/NSURLConnectionExample-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -409,6 +411,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NSURLConnectionExample/NSURLConnectionExample-Prefix.pch";
INFOPLIST_FILE = "NSURLConnectionExample/NSURLConnectionExample-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -430,6 +433,7 @@
"$(inherited)",
);
INFOPLIST_FILE = "NSURLConnectionExampleTests/NSURLConnectionExampleTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand All @@ -448,6 +452,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NSURLConnectionExample/NSURLConnectionExample-Prefix.pch";
INFOPLIST_FILE = "NSURLConnectionExampleTests/NSURLConnectionExampleTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.kiloapp.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.kiloapp.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ @interface PTOperationDownloader()
@property(nonatomic, readwrite, retain) NSMutableData* responseData;
@property(nonatomic, readwrite, retain) NSURLConnection* connection;
@property(nonatomic, readwrite, assign) NSTimeInterval timeoutInterval;
@property(nonatomic, readwrite, copy) completionBlock completionBlock;
@property(nonatomic, readwrite, copy) completionBlock customCompletionBlock;
@property(nonatomic, readwrite, retain) NSError *error;
@property(atomic, readwrite, assign) BOOL finished;
@property(atomic, readwrite, assign) BOOL executing;
@property(atomic, readwrite, assign) BOOL customFinished;
@property(atomic, readwrite, assign) BOOL customExecuting;
@property(nonatomic, readwrite, strong) NSRecursiveLock *lock;
@end

Expand Down Expand Up @@ -63,7 +63,7 @@ - (void)setCompletionBlockWithSuccess:(void (^)(id responseData))success
{
[self.lock lock];
__weak typeof(self) weakSelf = self;
self.completionBlock = ^ {
self.customCompletionBlock = ^ {
if (weakSelf.error) {
if (failure) {
failure(weakSelf.error);
Expand Down Expand Up @@ -100,14 +100,14 @@ - (void)start
if ([self isCancelled])
{
[self willChangeValueForKey:@"isFinished"];
self.finished = YES;
self.customFinished = YES;
[self didChangeValueForKey:@"isFinished"];
return;
}

[self willChangeValueForKey:@"isExecuting"];
[self performSelector:@selector(operationDidStart) onThread:[[self class] networkThread] withObject:nil waitUntilDone:NO];
self.executing = YES;
self.customExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
[self.lock unlock];
}
Expand All @@ -134,8 +134,8 @@ - (void)operationDidFinish
[self willChangeValueForKey:@"isFinished"];
[self willChangeValueForKey:@"isExecuting"];

self.executing = NO;
self.finished = YES;
self.customExecuting = NO;
self.customFinished = YES;

[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];
Expand Down Expand Up @@ -185,7 +185,7 @@ - (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLRespo
self.error = error;
self.connection = nil;
self.responseData = nil;
self.completionBlock();
self.customCompletionBlock();
}
}

Expand All @@ -198,7 +198,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)aConnection
{
NSLog(@"connectionDidFinishLoading in main thread?: %d", [NSThread isMainThread]);
self.connection = nil;
self.completionBlock();
self.customCompletionBlock();
[self operationDidFinish];
}

Expand All @@ -207,7 +207,7 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
self.connection = nil;
self.responseData = nil;
self.error = error;
self.completionBlock();
self.customCompletionBlock();
[self operationDidFinish];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)toggleButton
downloadWithURL:[NSURL URLWithString:URLString]
timeoutInterval:15
success:^(id responseData){
NSLog(@"get data size: %d", [(NSData *)responseData length]);
NSLog(@"get data size: %zd", [(NSData *)responseData length]);
NSLog(@"success block in main thread?: %d", [NSThread isMainThread]);
}
failure:^(NSError *error){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.kiloapp.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down