开发者

NSDateformatter (seems to) throwing an exception. But process does not exit with an error message and call stack

开发者 https://www.devze.com 2023-04-09 20:54 出处:网络
Unfortunately, the Mac I\'m working on does not allow us to attach a debugger, so I have no idea what the cause it.

Unfortunately, the Mac I'm working on does not allow us to attach a debugger, so I have no idea what the cause it.

Talk about a baptism by fire.

The tutorial program finds four placeholders and replaces them with text from four text fields.

NSString *stringTemplate = [[NSString alloc] initWithString:txtTemplate.text];
// My pseudo 开发者_JS百科debugger
NSLog(@"%@", stringTemplate);


//Start Weird Exit
NSDateFormatter *dateShortFormat = [[[NSDateFormatter alloc]init]autorelease];
    [dateShortFormat setDateFormat:NSDateFormatterShortStyle];
//End Weird Exit    

//Pseudo debugger
    NSLog(@"%@", txtPlace.text);
    [stringTemplate stringByReplaceingOccurancesOfString:@"<place>" withString:txtPlace.text];
   //txtDate is a TextField
    NSLog(@"%@", txtDate.text);
    [stringTemplate stringByReplaceingOccurancesOfString:@"<date>" withString:[NSString stringFromDate:[dateShortFormat dateFromString:txtDate.text]]];
   //There has to be a shorter way to type that. . .

    NSLog(@"%@", txtVerb.text);
    [stringTemplate stringByReplaceingOccurancesOfString:@"<verb>" withString:txtVerb.text];
    NSLog(@"%@", txtNumber.text);
    [stringTemplate stringByReplaceingOccurancesOfString:@"<number>" withString:txtNumber.text];
    txvStory.text =stringTemplate;

So I don't ever see the bottom four console messages. But I see the very first message though.

Like always, any improvements would be greatly appreciated. Anything from memory management to design principle advice. Strangely, it is difficult to get a lot of advice in real life. But on the Internet, it seems to come left and right.


It looks like you've either got typos in your post, or your actually sending invalid messages to your date formatter. You have:

[stringTemplate stringByReplaceingOccurancesOfString ...

Where you should have

[stringTemplate stringByReplacingOccurancesOfString ...

In other words, there is no "e" in "Replacing"

0

精彩评论

暂无评论...
验证码 换一张
取 消