Permalink
Browse files

Learning about callbacks

  • Loading branch information...
1 parent 25081fb commit 848a0ba779864c4d1e9b8f3730faf074756cca52 Ryan Blunden committed Jan 14, 2013
@@ -0,0 +1,243 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 4158527EE89FE3E9202DD47A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 41585D6DC56622D024492D4B /* main.m */; };
+ 415852B10301FBA45E31A10E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4158542C5565D9628D6AA371 /* Foundation.framework */; };
+ 41585301B0AACBAE911732A9 /* Logger.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4158531CFEAFA991F129B180 /* Logger.h */; };
+ 41585EBB0CDB5F048F436CF0 /* Logger.m in Sources */ = {isa = PBXBuildFile; fileRef = 4158523072CFF75742443E98 /* Logger.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ 4158505566FD4C84A2D2B794 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ 41585301B0AACBAE911732A9 /* Logger.h in CopyFiles */,
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ 4158523072CFF75742443E98 /* Logger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Logger.m; sourceTree = "<group>"; };
+ 415852C11A961ADF7CB4E81E /* Callbacks */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Callbacks; sourceTree = BUILT_PRODUCTS_DIR; };
+ 4158531CFEAFA991F129B180 /* Logger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logger.h; sourceTree = "<group>"; };
+ 4158542C5565D9628D6AA371 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 41585C0ADBF731A746A00BEB /* Callbacks-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Callbacks-Prefix.pch"; sourceTree = "<group>"; };
+ 41585D6DC56622D024492D4B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 415858B7332465939E5E6D44 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 415852B10301FBA45E31A10E /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 415858FECE2375403A77A0C8 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 4158542C5565D9628D6AA371 /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 41585CA9B1F5454F97CB4C0A /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 41585C0ADBF731A746A00BEB /* Callbacks-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ 41585D5CCA18230CD3ACB38C /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 415852C11A961ADF7CB4E81E /* Callbacks */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 41585ED2BB8483C31578C0D5 /* Callbacks */ = {
+ isa = PBXGroup;
+ children = (
+ 41585D6DC56622D024492D4B /* main.m */,
+ 41585CA9B1F5454F97CB4C0A /* Supporting Files */,
+ 4158523072CFF75742443E98 /* Logger.m */,
+ 4158531CFEAFA991F129B180 /* Logger.h */,
+ );
+ path = Callbacks;
+ sourceTree = "<group>";
+ };
+ 41585FBC6D2EE7D9B12EDB5C = {
+ isa = PBXGroup;
+ children = (
+ 41585D5CCA18230CD3ACB38C /* Products */,
+ 415858FECE2375403A77A0C8 /* Frameworks */,
+ 41585ED2BB8483C31578C0D5 /* Callbacks */,
+ );
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 41585432AF2E83C3ECD96503 /* Callbacks */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 41585E40221970BE35612447 /* Build configuration list for PBXNativeTarget "Callbacks" */;
+ buildPhases = (
+ 415851412F057B62A08681EA /* Sources */,
+ 415858B7332465939E5E6D44 /* Frameworks */,
+ 4158505566FD4C84A2D2B794 /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = Callbacks;
+ productName = Callbacks;
+ productReference = 415852C11A961ADF7CB4E81E /* Callbacks */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 415854B5E354B7F366F35051 /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = 415857FFFE18C619B7ADEA2F /* Build configuration list for PBXProject "Callbacks" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 41585FBC6D2EE7D9B12EDB5C;
+ productRefGroup = 41585D5CCA18230CD3ACB38C /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 41585432AF2E83C3ECD96503 /* Callbacks */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 415851412F057B62A08681EA /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 4158527EE89FE3E9202DD47A /* main.m in Sources */,
+ 41585EBB0CDB5F048F436CF0 /* Logger.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ 415850DAF3AFB51F59861A3A /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Callbacks/Callbacks-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+ 415853EB41FC854B37A659B1 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Callbacks/Callbacks-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ 41585AE05601920E8F1693C1 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.8;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ 41585FB6E023ABE7D72AB903 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.8;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 415857FFFE18C619B7ADEA2F /* Build configuration list for PBXProject "Callbacks" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 41585FB6E023ABE7D72AB903 /* Release */,
+ 41585AE05601920E8F1693C1 /* Debug */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 41585E40221970BE35612447 /* Build configuration list for PBXNativeTarget "Callbacks" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 415850DAF3AFB51F59861A3A /* Release */,
+ 415853EB41FC854B37A659B1 /* Debug */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 415854B5E354B7F366F35051 /* Project object */;
+}
@@ -0,0 +1,8 @@
+//
+// Prefix header for all source files of the 'Callbacks' target in the 'Callbacks' project
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+
+#endif
@@ -0,0 +1,18 @@
+//
+// Created by rblunden on 1/13/13.
+//
+// To change the template use AppCode | Preferences | File Templates.
+//
+
+
+#import <Foundation/Foundation.h>
+
+
+NSMutableData *incomingData;
+@interface Logger : NSObject {
+}
+
+- (void)sayOuch:(NSTimer *)t;
+
+- (void)zoneChange:(NSNotification *)note;
+@end
@@ -0,0 +1,43 @@
+//
+// Created by rblunden on 1/13/13.
+//
+// To change the template use AppCode | Preferences | File Templates.
+//
+
+
+#import "Logger.h"
+
+
+@implementation Logger
+
+- (void)helloChap:(NSTimer *)t {
+ NSLog(@"Hello chap.");
+}
+
+// Called each time a chunk of data arrives
+- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
+ NSLog(@"Received %lu bytes", [data length]);
+
+ // Create a mutable data if it doesn't already exist
+ if (!incomingData) {
+ incomingData = [[NSMutableData alloc] init];
+ }
+
+ [incomingData appendData:data];
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
+ NSLog(@"Got it all");
+
+ NSString *string = [[NSString alloc] initWithData:incomingData encoding:NSUTF8StringEncoding];
+ incomingData = nil;
+ NSLog(@"string has %lu characters", [string length]);
+
+ // Uncomment next line to see file contents
+ NSLog(@"The whole string is %@", string);
+}
+
+- (void)zoneChange:(NSNotification *)note {
+ NSLog(@"The system time zone has changed");
+}
+@end
View
@@ -0,0 +1,37 @@
+//
+// main.m
+// Callbacks
+//
+// Created by Ryan Blunden on 01/13/13.
+// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "Logger.h"
+
+int main(int argc, const char *argv[]) {
+
+ @autoreleasepool {
+ Logger *logger = [[Logger alloc] init];
+
+ // Helper objects - Here is a helper object that conforms to a protocol
+ NSURL *url = [NSURL URLWithString:@"http://www.gutenberg.org/cache/epub/205/pg205.txt"];
+ NSURLRequest *request = [NSURLRequest requestWithURL:url];
+ __unused NSURLConnection *fetchConn = [[NSURLConnection alloc] initWithRequest:request
+ delegate:logger
+ startImmediately:YES];
+
+ // Notifications using default notification center
+ [[NSNotificationCenter defaultCenter] addObserver:logger selector:@selector(zoneChange:) name:NSSystemTimeZoneDidChangeNotification object:nil];
+
+ // Target-action - When something happens, send this message to this object
+ __unused NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0
+ target:logger
+ selector:@selector(helloChap:)
+ userInfo:nil
+ repeats:YES];
+ [[NSRunLoop currentRunLoop] run];
+ }
+
+ return 0;
+}

0 comments on commit 848a0ba

Please sign in to comment.