Check if there is an emoji contained in a string

后端 未结 11 1218
野的像风
野的像风 2020-12-31 11:49

I am getting the text size of a string with this

textSize = [[tempDict valueForKeyPath:@\"caption.text\"] sizeWithFont:[UIFont systemFontOfSize:12] constrain         


        
11条回答
  •  耶瑟儿~
    2020-12-31 12:17

    Again and again people use valueForKeyPath instead of objectForKey. None of them can ever explain why. Read the documentation. If after reading it you can explain why you are using valueForKeyPath (and "I copied it from somewhere" is not an explanation), change it to objectForKey.

    The problem you have has nothing to do with Emojis at all. Any attempt to detect Emojis in the string will fail - for the simple reason that you don't have a string in the first place, you have [NSNull null]. The problem might be fixed by using objectForKey - you might get nil instead which behaves a lot more forgiving. Or you still get [NSNull null].

    Find out why you are getting [NSNull null]. Somebody puts it there. If you can't prevent it from being there, then you need to handle it.

提交回复
热议问题