• 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
Re: newbie EXC_BAD_ACCESS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie EXC_BAD_ACCESS


  • Subject: Re: newbie EXC_BAD_ACCESS
  • From: Daniel Child <email@hidden>
  • Date: Sun, 20 Mar 2005 22:12:23 -1000

Hurray! Problem solved using code below. Many many thanks, Hamish, and to all other helping out during this two-day saga.

Two things I don't get, however....

1. I think the line
if ([scanner scanInt:&type] && [scanner scanUpToString:@"\n" intoString:&desc])
[self addStrokeDesc:[StrokeDescription strokeDescriptionWithType:type
desc: desc];

can be paraphrased as
if (you find an int AND you find a string in the first line)
// i.e. if two YES values returned
place those values into whatever it is the type and desc pointers point to, and
use those values to initialize a StrokeDescription.

This means you are passing pointers without ever assigning names to those pointers. Aiming for less dense code (reflecting novice stage), would this work?

int *typePtr = &type;
NSString **descPtr = &desc;
if ([scanner scanInt: typePtr] && [scanner scanUpToString:@"\n" intoString:descPtr])
... the rest.


2. You created a class method. Could I have pulled this off without doing that? e.g. something along the lines of....

int *typePtr = &type;
NSString **descPtr = &desc;
while (![scanner isAtEnd) {
sd = [[StrokeDescription alloc] init];
[scanner scanInt: typePtr]; // OBVIOUS FLAW OF NOT KNOWING BOOL RTN VAL
[scanner scanUpToString:@"\n" intoString:descPtr]; // SAME HERE
// IS THERE A WORKAROUND WITHOUT THE COMPLEX IF STATEMENT?
[sd setStrokeType: type];
[sd setStrokeDesc: desc];
[self addStrokeDesc: sd]; // to add to knownStrokes array
// where addStrokeDesc retains the passed parameter sd
[sd release];
}

In other words, without using a public constructor and sticking with plain old instance accessors, can you create the sd's and then place them in the array? Once sigdev error was solved, I was having troubles because the knownStrokes array was getting the last copy of sd created placed in every single slot of the array.

On Sunday, March 20, 2005, at 04:45 PM, Hamish Allan wrote:

Unfortunately that is the least of your worries. Using a fixed-size of 44 for your array of lines is not a good idea, nor is it necessary. Your code should read something like:

- (void)fillStrokes
{
NSScanner *scanner = [NSScanner scannerWithString:
[NSString stringWithContentsOfFile:
@"~/Documents/PROGRAMMING/IME DEV/ScratchPad/strokeList.txt"
stringByExpandingTildeInPath]];

int type;
NSString *desc;
while (![scanner isAtEnd])
if ([scanner scanInt:&type] && [scanner scanUpToString:@"\n" intoString:&desc])
[self addStrokeDesc:[StrokeDescription strokeDescriptionWithType:type desc:desc]];
}

with the following method in StrokeDescription:

+ (id)strokeDescriptionWithType:(int)type desc:(NSString *)desc
{
id sd = [[StrokeDescription alloc] init];
[sd setStrokeType:[NSNumber numberWithInt:type]]; // is this wrapping necessary?
[sd setDesc:desc];
return [sd autorelease];
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: newbie EXC_BAD_ACCESS
      • From: Hamish Allan <email@hidden>
    • Re: newbie EXC_BAD_ACCESS
      • From: mmalcolm crawford <email@hidden>
    • Re: newbie EXC_BAD_ACCESS
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Re: NSTimer causes events to be lost
  • Next by Date: Re: newbie EXC_BAD_ACCESS
  • Previous by thread: Re: newbie EXC_BAD_ACCESS
  • Next by thread: Re: newbie EXC_BAD_ACCESS
  • Index(es):
    • Date
    • Thread