Click on UITextView or UITextField to crash

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x115fadbc0'
*** First throw call stack:
(0x1940bd8c8 0x1910097c4 0x194159838 0x19403a4f8 0x1940423a0 0x1e42cb9a8 0x1e42ce220 0x106f02c08 0x1080a461c 0x1080be2b0 0x1080acb2c 0x1080ad7b4 0x1080b9b00 0x1080b91a4 0x1eecdb3b8 0x1eecda8c0)
libc++abi: terminating due to uncaught exception of type NSException
   InputAnalytics called timeIntervalSinceReferenceDate in dispatch_sync.The display issue of the call stack occurs in two stages: keyboard input analysis and folding the keyboard.After adding protection to NSString, it can function normally, but I want to know the reason.
#import "NSString+Safe.h"
@implementation NSString (Safe)
- (NSTimeInterval)timeIntervalSinceReferenceDate {
    return 0;
}
- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)date {
    return 0;
}
@end
Answered by DTS Engineer in 860486022

Please please please don’t do this.

The crash you’re seeing is caused by a memory management problem. The most common cause of such problems is an over-release bug. That is, some code has over-released an NSDate object, that same memory has been re-used as an NSString object, and then some other code has using the original object pointer thinking it’s date when it’s now actually a string, and hence this exception.

You’re ‘fixing’ the crash by using an Objective-C category to add date methods to string objects, and string objects have no business having those methods. This is the wrong approach. Rather, you need to find the underlying memory management bug and resolve that.

My advice is that your run your app under the standard memory debugging tools. Specifically, Zombies is the tool of choice when debugging over-release problems.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Please please please don’t do this.

The crash you’re seeing is caused by a memory management problem. The most common cause of such problems is an over-release bug. That is, some code has over-released an NSDate object, that same memory has been re-used as an NSString object, and then some other code has using the original object pointer thinking it’s date when it’s now actually a string, and hence this exception.

You’re ‘fixing’ the crash by using an Objective-C category to add date methods to string objects, and string objects have no business having those methods. This is the wrong approach. Rather, you need to find the underlying memory management bug and resolve that.

My advice is that your run your app under the standard memory debugging tools. Specifically, Zombies is the tool of choice when debugging over-release problems.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x11495e690' *** First throw call stack: (0x19a0bf988 0x1970097c4 0x19a1588f4 0x19a03f35c 0x19a047200 0x1eb8da9a8 0x1eb8dd220 0x10564ec08 0x1067e863c 0x1068022d0 0x1067f0b4c 0x1067f17d4 0x1067fdb20 0x1067fd1c4 0x1f62a13b8 0x1f62a08c0) libc++abi: terminating due to uncaught exception of type NSException Received external candidate resultset. Total number of candidates: 6 containerToPush is nil, will not push anything to candidate receiver for request token: 5F205501

I’m not sure what your goal of that post was. I understand that you’re crashing due to an unrecognized selector exception. As I mentioned above, that’s almost certainly caused by a memory management error and you need to debug that rather than try to mask the problem.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Click on UITextView or UITextField to crash
 
 
Q