Category to search emojis on an NSString.
Category to search emojis on an NSString. The category allows to check if has emojis, the number of emoji, the range of the emojis and if the string consists entirely of emojis.
platform :ios, '8.0'
pod 'SearchEmojiOnString', '~> 1.0'
Then, run the following command:
$ pod install
Drag into your project the folder /SearchEmojiOnString-iOS
. That's all.
YES if the String contains emojis, NO otherwise.
#import "NSString+EMOEmoji.h"
...
NSString *emojis = @"🤐🤑🤒🤓🤔🤕🤖🤗🤘🦀🦁🦂🦃🦄🧀☂️✝️✡️☯️";
BOOL containsEmoji = [emojis emo_containsEmoji];
NSLog(@"%@", @(containsEmoji));
// Output: ["true"]
Calculate number of emojis on the string.
#import "NSString+EMOEmoji.h"
...
NSString *emojis = @"🤐🤑🤒🤓🤔";
NSInteger emojiCount = [emojis emo_emojiCount];
NSLog(@"%@", @(emojiCount));
// Output: ["5"]
Calculate the NSRange for every emoji on the string.
#import "NSString+EMOEmoji.h"
...
NSString *emojis = @"🤐emoji🤑test🤒";
NSArray *emojiRanges = [emojis emo_emojiRanges];
NSLog(@"%@", emojiRanges);
// Output: ["(
// "NSRange: {0, 2}",
// "NSRange: {7, 2}",
// "NSRange: {13, 2}"
// )"]
Thanks to Jichao Wu
Calculate if the string consists entirely of emojis.
#import "NSString+EMOEmoji.h"
...
NSString *emojisText = @"🤐emoji🤑test🤒";
BOOL emojiText_isPureEmojiString = [emojisText emo_isPureEmojiString];
NSLog(@"%@", @(emojiText_isPureEmojiString));
// Output: ["false"]
NSString *emojis = @"🤐🤑🤒";
BOOL emoji_isPureEmojiString = [emojis emo_isPureEmojiString];
NSLog(@"%@", @(emoji_isPureEmojiString));
// Output: ["true"]
SearchEmojiOnString-iOS is released under the MIT license. Please see the file called LICENSE.
$ git tag -a 1.0.0 -m 'Version 1.0.0'
$ git push --tags
Gabriel Massana
##Found an issue?
Please open a new Issue here if you run into a problem specific to SearchEmojiOnString-iOS, have a feature request, or want to share a comment.