我在 MyUtils 类中有一个类函数(声明和实现)。当我调用此函数时,我的应用程序崩溃了。在调试器中,我在“theFunction”函数的第一个动作上有一个断点。并且永远不会达到这个断点。
这是代码:
// =================================================================================================
// MyUtils.m
// =================================================================================================
+ (NSString*) changeDateFormat_fromFormat:(NSString*)sourceFormat sourceDateString:(NSString*)sourceDateString destFormat:(NSString*)destFormat {
if (sourceDateString == nil) return (nil); **<-- breakpoint here**
NSDate* aDate = [NSDate dateFromString:sourceFormat theDateString:sourceDateString];
return ([aDate stringValueWithFormat:destFormat]);
}
// ===================================================================
// MyUtils.h
// ===================================================================
@interface MyUtils
+ (NSString*) changeDateFormat_fromFormat:(NSString*)sourceFormat sourceDateString:(NSString*)sourceDateString destFormat:(NSString*)destFormat;
+ (void) simpleAlert_ok:(NSString*)alertTitle message:(NSString*)alertMessage;
@end
// ===================================================================
// Elsewhere.m
// ===================================================================
- (void) aFunction:(SomeClass*)someParam {
SomeOtherClass* val = nil;
NSString* intitule = nil;
intitule = [MyUtils changeDateFormat_fromFormat:@"yyyyMMdd" sourceDateString:@"toto" destFormat:@"EEEE dd MMMM yyyy"]; **<-- crash here**
控制台说:
2011-01-03 02:05:07.188 Learning Project[1667:207] *** NSInvocation: warning: object 0xe340 of class 'MyUtils' does not implement methodSignatureForSelector: -- trouble ahead
2011-01-03 02:05:07.188 Learning Project[1667:207] *** NSInvocation: warning: object 0xe340 of class 'MyUtils' does not implement doesNotRecognizeSelector: -- abort
如果我更换电话,NSString *item = @"youyou";
那么一切都很好。
在调用之前强制保留 aPreviousNSString 不会改变任何内容。你知道发生了什么吗?