• 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: mmalcolm crawford <email@hidden>
  • Date: Sun, 20 Mar 2005 19:07:04 -0800


On Mar 20, 2005, at 3:17 PM, Daniel Child wrote:
You suggested I show the fillStrokes method. Here it is.

- (void)fillKnownStrokes
{
  NSCharacterSet *chSetTab, *chSetRtn; // token parsers
  NSString *scannedName, *string;
  NSScanner *scanner; // essentially a tokenizer
  NSString *stringArray[44];
  NSNumber *thisType;
  NSString *thisDesc;
  StrokeDescription *sd = [[StrokeDescription alloc] init];
  int i = 0, j = 0;

// Initially, you place the entire file contents into one string.
string = [NSString stringWithContentsOfFile:
[@"~/Documents/PROGRAMMING/IME DEV/ScratchPad/strokeList.txt" stringByExpandingTildeInPath]];


chSetRtn = [NSCharacterSet characterSetWithCharactersInString:@"\n"];
chSetTab = [NSCharacterSet characterSetWithCharactersInString:@"\t"];
scanner = [NSScanner scannerWithString:string];


// Now break up each line so that each line is in the array.
while(![scanner isAtEnd]) {
if([scanner scanUpToCharactersFromSet:chSetRtn intoString:&scannedName]) {
stringArray[i] = scannedName;
i++;
}
[scanner scanCharactersFromSet:chSetTab intoString:nil];
}


This is much more easily achieved using:

    string = [NSString stringWithContentsOfFile:
        [@"~/Documents/PROGRAMMING/IME DEV/ScratchPad/strokeList.txt"
            stringByExpandingTildeInPath]];
    NSArray *lines = [string componentsSeparatedByString:@"\n"];

Then enumerate over 'lines' -- which saves having to hard code '44' (you will almost certainly have problems if for some reason you don't have 44 items in the file...).

  for (i = 0; i < 44; i++)
  {
    // now give scanner each full line of text one line at a time
    scanner = [NSScanner scannerWithString: stringArray[i]];
    for (j = 0; j < 2; j++)

It's not clear why you're setting up a loop just for two items?

Something like the following might be rather easier?


NSString *string = @"1\taaa\n2\tbbb\n3\tccc\n4\tddd\n5\teee";

    NSArray *lines = [string componentsSeparatedByString:@"\n"];
    NSEnumerator *linesEnumerator = [lines objectEnumerator];
    NSString *line;

    while (line = [linesEnumerator nextObject])
    {
        NSScanner *lineScanner = [NSScanner scannerWithString:line];

        int type;
        [lineScanner scanInt:&type];
        NSNumber *thisType = [NSNumber numberWithInt:type];
        NSLog(@"thisType %@", thisType);

NSString *thisDesc;
[lineScanner scanCharactersFromSet:[NSCharacterSet letterCharacterSet] intoString:&thisDesc];
NSLog(@"thisDesc %@", thisDesc);
}



From your original listing, it looks like you're creating a single instance of StrokeDescription and simply updating its type and description on each iteration through the loop? Or does [self addStrokeDesc: sd] add a copy of the StrokeDescription? What is the implementation of addStrokeDesc:?




mmalc

_______________________________________________
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: mmalcolm crawford <email@hidden>
References: 
 >Re: newbie EXC_BAD_ACCESS (From: Daniel Child <email@hidden>)

  • Prev by Date: screen brightness
  • Next by Date: Re: newbie EXC_BAD_ACCESS
  • Previous by thread: Re: /usr/X11R6/bin?
  • Next by thread: Re: newbie EXC_BAD_ACCESS
  • Index(es):
    • Date
    • Thread