
Cocoa Maker 7 - Libraries and Frameworks
Apr 13, 2010
Radio and PodcastLive Radio & Podcasts
James ( MrGeckosMedia.com ), joined by, Noah ( RockntheSweater.com ), and Karl, explains how file managing works in c and cocoa. 7:49 Example code from episode. Files C Example <Foundation/Foundation.h> BOOL file_e...
Cocoa Maker 5 - File Management is an episode from Cocoa Maker by Mr. Gecko. James ( MrGeckosMedia.com ), joined by, Noah ( RockntheSweater.com ), and Karl, explains how file managing works in c and cocoa. 7:49 Example code from episode. Fi...
This episode belongs to Cocoa Maker.
Use the player on this page to stream the episode online.
Published Mar 20, 2010, audio available.
James ( MrGeckosMedia.com ), joined by, Noah ( RockntheSweater.com ), and Karl, explains how file managing works in c and cocoa. 7:49 Example code from episode. Files C Example <Foundation/Foundation.h> BOOL file_exist(const char *fileName) { FILE *file = fopen(fileName, "r"); if (file) { fclose(file); return YES; } return NO; } int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; const char *ourFile = [[@"~/Desktop/file.txt" stringByExpandingTildeInPath] UTF8String]; FILE *file; if (!file_exist(ourFile)) { file = fopen(ourFile, "w"); time_t currTime = time(NULL); fprintf(file, "%s: We just made this file.\n", ctime(&currTime)); } else { file = fopen(ourFile, "a"); } time_t currTime = time(NULL); fprintf(file, "%s: Here is a new line in this file.\n", ctime(&currTime)); fclose(file); [pool drain]; return 0; } Files Cocoa Exmaple <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSFileManager *manager = [NSFileManager defaultManager]; NSString *ourFile = [@"~/Desktop/file.txt" stringByExpandingTildeInPath]; NSFileHandle *file; if (![manager fileExistsAtPath:ourFile]) { [manager createFileAtPath:ourFile contents:nil attributes:nil]; file = [NSFileHandle fileHandleForWritingAtPath:ourFile]; [file writeData:[[NSString stringWithFormat:@"%@: Here is a new file.\n", [NSDate date]] dataUsingEncoding:NSUTF8StringEncoding]]; } else { file = [NSFileHandle fileHandleForWritingAtPath:ourFile]; [file seekToEndOfFile]; } [file writeData:[[NSString stringWithFormat:@"%@: Here is a new line.\n", [NSDate date]] dataUsingEncoding:NSUTF8StringEncoding]]; [file closeFile]; [pool drain]; return 0; } Keynote used in this Episode Keynote in PDF Format
You can listen to Cocoa Maker 5 - File Management online on Radio and Podcast. Open the player on this page to stream the available audio.
Cocoa Maker 5 - File Management is an episode from Cocoa Maker by Mr. Gecko.
The episode duration depends on the source podcast feed and may not always be available.
This episode was published on Mar 20, 2010.
Yes. Use the heart button on the episode page to add it to your favorite episodes list.
Yes. This page shows related episodes from Cocoa Maker when more episodes are available from the podcast feed.
You can listen to Cocoa Maker 5 - File Management on this page when the episode audio is available from the podcast feed.
Cocoa Maker 5 - File Management is from Cocoa Maker by Mr. Gecko.
Published Mar 20, 2010