简体   繁体   中英

How to solve NSInvalidArgumentException error?

My app is crashing intermittently for users, but unfortunately I am not able reproduce the problem on any of my devices. The reported error is:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteAttributedString initWithString:: nil value'

The log trace is not clear about the crash source. I have attached a log trace. I'm looking for any pointers that can help me to track this down.

示例异常的屏幕截图

The reason for the crash is in your title...

reason: 'NSConcreteAttributedString initWithString:: nil value'

It looks like you are trying to create an attributed string from a string but that string is nil.

Add a guard before you do you NSAttributeString initWithString to make sure the string isn't nil ie

if (string) {
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithAttributedString:string];

    //other code etc...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM