• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Organizing A File Into Multiple Files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Organizing A File Into Multiple Files


  • Subject: Organizing A File Into Multiple Files
  • From: "Matthew Callis" <email@hidden>
  • Date: Tue, 9 Jan 2007 16:18:58 -0600

Hello!
I have a project that has grown far too large to maintain in one file like I
currently have it. I don't know the best way to do what I want without
making a whole lot of major changes, if possible. Right now it's one long
function, switched based on file extensions one after another. I would like
for each file extension to be in its own file so it's much easier to
maintain and make changes and add new ones.

The area I need broken up is structured like this:

for(i = 0; i < fileCount; i++){
   NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];

//    Break apart the path to the file
   pathComponents = [NSArray arrayWithObjects: path, [content
objectAtIndex:i], nil];
   NSString *fullPath = [NSString pathWithComponents:pathComponents];
   NSString *fileExtension = [fullPath pathExtension];

   RomFile *romObject = [[RomFile alloc] init];
   NSFileHandle *fileHandle = [NSFileHandle
fileHandleForReadingAtPath:fullPath];
   NSData *romBuffer;

   ... switches based on file extension ...

//    File CRC32
   NSString *romFileCRC32;
   romBuffer = [fileHandle readDataToEndOfFile];
   romFileCRC32 = [NSString stringWithFormat:@"0xx", [romBuffer crc32]];

//    Game Title
//    GameBoy Header Offset is 0x134 hex / 308 integer
   [fileHandle seekToFileOffset: 308];

   NSString *romGameName = [[NSString alloc] init];
   romBuffer = [fileHandle readDataOfLength:15];
   romGameName = [[NSString alloc] initWithData:romBuffer
encoding:[NSString defaultCStringEncoding]];

   ... very very long ...

   [fileHandle closeFile];

//    Check to make sure nothing is being passed as (null) so it can be
safly written
   if(romFileCRC32 == nil)    romFileCRC32    = @"0x00000000";
   if(romGameName == nil)    romGameName        = @"NA";
   [romsArray addObject: romObject];

   [romObject release];
   [loopPool release];
}


-- - Matthew http://eludevisibility.org/ _______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Organizing A File Into Multiple Files
      • From: Chris Suter <email@hidden>
  • Prev by Date: Re: nodesForXPath almost always returns no objects
  • Next by Date: Re: Scaleable Toolbar Items
  • Previous by thread: Re: Scaleable Toolbar Items
  • Next by thread: Re: Organizing A File Into Multiple Files
  • Index(es):
    • Date
    • Thread