我正在使用 SOCKit为我的应用程序实现 URL 路由器的库。我有一个自定义 Router
类,它跟踪所有有效路由并实现一个 match
方法,给定一个路由 NSString
,将它匹配到相应的 View Controller 。为了使事情变得更简单,可匹配的 View Controller 必须实现 Routable
协议(protocol),这需要一个 initWithState:
方法,该方法将 NSDictionary
作为参数。相关代码如下:
- (id)match:(NSString *)route
{
for (NSArray *match in routePatterns) {
const SOCPattern * const pattern = [match objectAtIndex:kPatternIndex];
if ([pattern stringMatches:route]) {
Class class = [match objectAtIndex:kObjectIndex];
NSLog(@"[pattern parameterDictionaryFromSourceString:route]: %@", [pattern parameterDictionaryFromSourceString:route]);
UIViewController<Routable> *vc;
vc = [[class alloc] initWithState:[pattern parameterDictionaryFromSourceString:route]];
return vc;
}
}
return nil;
}
当我使用 debug
配置运行应用程序时,[pattern parameterDictionaryFromSourceString:route]
产生了预期的结果:
[pattern parameterDictionaryFromSourceString:route]: {
uuid = "e9ed6708-5ad5-11e1-91ca-12313810b404";
}
另一方面,当我使用 release
配置运行应用程序时,[pattern parameterDictionaryFromSourceString:route]
生成一个空字典。我真的不确定如何调试它。我已经检查了我自己的代码,看看 debug
和 release
构建之间是否有任何明显差异,但无济于事,我还查看了 SOCKit source code .想法?谢谢!
最佳答案
我今天刚遇到这个问题。在我的案例中,问题是 Release 构建了被阻止的断言,但在 -performSelector:onObject:sourceString:
和 -parameterDictionaryFromSourceString:
中,这一行很重要:
NSAssert([self gatherParameterValues:&values fromString:sourceString],
@"The pattern can't be used with this string.");
当断言被转换为空操作时,它就消失了,并且收集永远不会发生。没有参数值,不会发生太多事情!我将其更改为以下内容(并将向 GitHub 存储库提交问题):
if( ![self gatherParameterValues:&values fromString:sourceString] ) {
NSAssert(NO, @"The pattern can't be used with this string.");
return nil;
}
编辑:报告为issue #13 .
关于objective-c - 调试和发布版本之间的不同行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9348764/