Re: NSScanner Failing with EXC_BAD_ACCESS
Re: NSScanner Failing with EXC_BAD_ACCESS
- Subject: Re: NSScanner Failing with EXC_BAD_ACCESS
- From: Matt Neuburg <email@hidden>
- Date: Fri, 15 Oct 2010 18:19:16 -0700
- Thread-topic: NSScanner Failing with EXC_BAD_ACCESS
On Fri, 15 Oct 2010 11:44:26 -0700, Chris Tracewell <email@hidden>
said:
>NOTE :: GC Enabled
>
>I am using an NSScanner in an NSString category but am crashing whenever
>I try to log the string I scanned into or to return it. If I comment out
>the NSLog there are no problems.
>
>NSString *theScannedString;
>NSScanner *theScanner = [NSScanner scannerWithString:theNewHTML];
>NSCharacterSet *theCharacterSet = [NSCharacterSet
>characterSetWithCharactersInString:@"1234567890abcdefghijklmnopqrstuvwxyz`
>~!@#$%^&*()-_=+<>?,./:\";'[]\{}| "];
>[theScanner scanCharactersFromSet:theCharacterSet
>intoString:&theScannedString];
>
>NSLog(@"%@",theScannedString);
>
>Does anyone have a hint as to what may be the issue?
>
The problem is probably that theScannedString has never been initialize
it. Always initialize when you declare, because otherwise your value could
be nonsense and can't be logged. So, minimally, you'd say this:
NSString *theScannedString = nil;
Now you can log that value successfully, even if nothing gets written into
it. Then you can track down *why* nothing is getting written into it. :) m.
--
matt neuburg, phd = email@hidden, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/matt/default.html#applescriptthings
_______________________________________________
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