gpt4 book ai didi

xcode - 仅在模拟器中发生的字符串错误的随机 StringByReplacingOccurances

转载 作者:行者123 更新时间:2023-12-01 09:07:39 25 4
gpt4 key购买 nike

所以我有这个奇怪的错误。我一整天都能够毫无问题地调试我的应用程序,但突然出现了这个奇怪的错误消息,即使我没有做任何更改......

2013-04-21 01:06:26.617 Schema REVAMP[4874:907] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[__NSCFString stringByReplacingOccurrencesOfString:withString:options :范围:]:无参数'* 首先抛出调用栈:(0x3131f2a3 0x38fc497f 0x3131f1c5 0x31b8c9b5 0x31b8c95d 0x6765 0x58c3 0x3318e311 0x3319a79b 0x3319a4c1 0x3316b4e9 0x3312a803 0x32ed4d8b 0x32ed4929 0x32f037cf 0x331d40e9 0x331d32d5 0x331d24a7 0x331d2431 0x33308309 0x33190691 0x331903d5 0x3318fd3b 0x33186eab 0x33182aed 0x331c41e9 0x3318783f 0x3317f84b 0x33127c39 0x331276cd 0x3312711b 0x34e2a5a3 0x34e2a1d3 0x312f4173 0x312f4117 0x312f2f99 0x31265ebd 0x31265d49 0x3317e485 0x3317b301 0x54cd 0x393fbb20)libc++abi.dylib:终止调用抛出异常(lldb)

发生错误的我的void:

- (void) loadSchema {

NSURL *scriptUrl = [NSURL URLWithString:@"http://schemaappen.se/plist/risbergska.plist"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data)
NSLog(@"Device is connected to the internet");
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Ingen internetanslutning" message:@"Försök igen senare" delegate:self cancelButtonTitle:@"Okej" otherButtonTitles: nil];
[alert show];
}


NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"EEEE"];
NSString *string = [f stringFromDate:[NSDate date]];

unique = string;

if ([unique isEqualToString:@"måndag"] || [unique isEqualToString:@"Monday"]) {
dagen = @"1";
}
if ([unique isEqualToString:@"tisdag"] || [unique isEqualToString:@"Tuesday"]) {
dagen = @"2";

}
if ([unique isEqualToString:@"onsdag"] || [unique isEqualToString:@"Wednesday"]) {
dagen = @"4";
}
if ([unique isEqualToString:@"torsdag"] || [unique isEqualToString:@"Thursday"]) {
dagen = @"8";
}
if ([unique isEqualToString:@"fredag"] || [unique isEqualToString:@"Friday"]) {
dagen = @"16";
}
if ([unique isEqualToString:@"lördag"] || [unique isEqualToString:@"Saturday"]) {
dagen = @"1";
}
if ([unique isEqualToString:@"söndag"] || [unique isEqualToString:@"Sunday"]) {
dagen = @"1";
}


urlString = [[NSUserDefaults standardUserDefaults] valueForKey:@"SchemaURL"];


NSRange rangeValue = [urlString rangeOfString:@"currentweek" options:NSCaseInsensitiveSearch];

if (rangeValue.length > 0){
weekURL = [urlString stringByReplacingOccurrencesOfString:@"currentweek" withString:weekNumber];
}
else {
weekURL = urlString;
}

NSString *dayURL = [weekURL stringByReplacingOccurrencesOfString:@"dagen" withString:dagen];
NSURL *url = [NSURL URLWithString:dayURL];
NSURLRequest *req = [NSURLRequest requestWithURL:url];

[webView loadRequest:req];

[MBHUDView hudWithBody:@"Laddar schema..." type:MBAlertViewHUDTypeActivityIndicator hidesAfter:NO show:YES];

}

如果我在我的设备上运行该应用程序而不通过 xcode 运行它,该应用程序可以正常运行。没有一次崩溃。

有人知道为什么会这样吗?

最佳答案

应用程序在模拟器中崩溃但在设备上不崩溃的一个可能原因是对文件的访问区分大小写。(模拟器区分大小写,设备不区分大小写)

1) 我会检查 stringByReplacingOccurrencesOfString 使用的任何文件名是否存在区分大小写问题。

2) 根据您的代码和给定的错误,我的第一个猜测是 weakNumber 在某个时候为 nil 导致崩溃。

关于xcode - 仅在模拟器中发生的字符串错误的随机 StringByReplacingOccurances,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16126182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com