• 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
Guidance for learner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Guidance for learner


  • Subject: Guidance for learner
  • From: "Barry" <email@hidden>
  • Date: Tue, 26 Jun 2007 10:59:01 +0100

I've added code to ImageApp, slowly developing my own App. which needs to load several datafiles at init time.
Seems to work but then had self-doubts regarding alloc & autorelease et. al.
Should I have alloc'd the NSStrings & NSData objects ?
I really need parts of the NSData data (or rather pointers to those parts) to be held as class variables so would not want the data released.


Here's the code I've  added

- (id) init
{
// Instantiate our subclass of NSDocumentController so that it will be used
[[ImageDocController alloc] init];


NSData *data[7];
int i;
const char *b[7];

NSString *path=[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
NSString *filepath=[path stringByAppendingPathComponent:@"5a_"];
for(i=0;i<7;i++) {
NSString *file=[filepath stringByAppendingFormat:@"d.w6s",i];
data[i]=[NSData dataWithContentsOfFile:file];
b[i]=[data[i] bytes];
}


   self = [super init];
   [self setDelegate:self];
   return self;
}


So if I add class variables like:

@interface ImageApp : NSApplication
{
   NSData *myData[7];
}
@end

then I will have to allocate space for them before copying selected data.
As you can see, I'm a tad confused by the [... alloc] stuff


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: Guidance for learner
      • From: "Alan Smith" <email@hidden>
  • Prev by Date: Re: Play a song with QTMovie
  • Next by Date: Re: Play a song with QTMovie
  • Previous by thread: Error inserting object
  • Next by thread: Re: Guidance for learner
  • Index(es):
    • Date
    • Thread