How to List (Almost) All Emojis in Swift for iOS 8 Without Using Any Form of Lookup Tables

How to list (almost) all emojis in Swift for iOS 8 without using any form of lookup tables?

You can loop over those hex values with a Range: 0x1F601...0x1F64F and then create the Strings using a UnicodeScalar:

for i in 0x1F601...0x1F64F {
guard let scalar = UnicodeScalar(i) else { continue }
let c = String(scalar)
print(c)
}

Outputs:

/p>

If you want all the emoji, just add another loop over an array of ranges:

// NOTE: These ranges are still just a subset of all the emoji characters;
// they seem to be all over the place...
let emojiRanges = [
0x1F601...0x1F64F,
0x2702...0x27B0,
0x1F680...0x1F6C0,
0x1F170...0x1F251
]

for range in emojiRanges {
for i in range {
guard let scalar = UnicodeScalar(i) else { continue }
let c = String(scalar)
print(c)
}
}

For those asking, the full list of available emojis can be found here: https://www.unicode.org/emoji/charts/full-emoji-list.html

A parsable list of unicode sequences for all emojis can be found in the emoji-sequences.txt file under the directory for the version you're interested in here: http://unicode.org/Public/emoji/

As of 9/15/2021 the latest version of the emoji standard available on Apple devices is 13.1.

How to get all available emojis in an array in Swift?

This SO seems to provide the answer
How to list (almost) all emojis in Swift for iOS 8 without using any form of lookup tables?

for i in 0x1F601...0x1F64F {  
let c = String(UnicodeScalar(i) ?? "-")
print(c)
}

You should go beyond 1F64F,
Find out if Character in String is emoji?

        0x1F600...0x1F64F, // Emoticons
8400...8447: // Combining Diacritical Marks for Symbols
9100...9300, // Misc items
0x2600...0x26FF, // Misc symbols
0x2700...0x27BF, // Dingbats
0xFE00...0xFE0F, // Variation Selectors
0x1F018...0x1F270, // Various asian characters
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
0x1F1E6...0x1F1FF, // Regional country flags
0x1F900...0x1F9FF, // Supplemental Symbols and Pictographs
65024...65039, // Variation selector

However, you get some undefined (marked as ? at the end of ranges)
See here to skip them
Is there a way to know if an Emoji is supported in iOS?

Note, while searching, found this interesting link to generate emoji flags based on country code
www.timekl.com/blog/2017/08/31/swift-tricks-emoji-flags/

That ends up with the following code

func isEmoji(_ value: Int) -> Bool {  
switch value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
0x1F1E6...0x1F1FF, // Regional country flags
0x2600...0x26FF, // Misc symbols 9728 - 9983
0x2700...0x27BF, // Dingbats
0xFE00...0xFE0F, // Variation Selectors
0x1F900...0x1F9FF, // Supplemental Symbols and Pictographs 129280 - 129535
0x1F018...0x1F270, // Various asian characters 127000...127600
65024...65039, // Variation selector
9100...9300, // Misc items
8400...8447: // Combining Diacritical Marks for Symbols
return true

default: return false
}
}

extension Character {
private static let refUnicodeSize: CGFloat = 8
private static let refUnicodePng =
Character("\u{1fff}").png(ofSize: Character.refUnicodeSize)

func png(ofSize fontSize: CGFloat) -> Data? {
let attributes = [NSAttributedString.Key.font:
UIFont.systemFont(ofSize: fontSize)]
let charStr = "\(self)" as NSString
let size = charStr.size(withAttributes: attributes)

UIGraphicsBeginImageContext(size)
charStr.draw(at: CGPoint(x: 0,y :0), withAttributes: attributes)

var png:Data? = nil
if let charImage = UIGraphicsGetImageFromCurrentImageContext() {
png = charImage.pngData()
}

UIGraphicsEndImageContext()
return png
}

func unicodeAvailable() -> Bool {
if let refUnicodePng = Character.refUnicodePng,
let myPng = self.png(ofSize: Character.refUnicodeSize) {
return refUnicodePng != myPng
}
return false
}
}

for i in 8400...0x1F9FF where isEmoji(i) {
if let scalar = UnicodeScalar(i) {
let unicode = Character(scalar)
if unicode.unicodeAvailable() {
print(i, String(scalar))
count += 1
} else {
notAvail += 1
print(i)
}
} else {
notCounted += 1
}
}

print("Count", count, "Not counted", notCounted, "Not Avail", notAvail)

How could I get an array of emojis found in iOS8.3

After some struggling,here is the fullest list of emojis found in iOS8.3 written in Swift.Browse in Safari for best compatibility.[April 8 2015]

let allEmojis = [",",",",",",",",",",",","☺️",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","‍‍,"‍‍‍,"‍‍‍,"‍‍‍,"‍‍,"‍‍,"‍‍‍,"‍‍‍,"‍‍‍,"‍‍,"‍‍,"‍‍‍,"‍‍‍,"‍‍‍,",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","‍❤️‍,"‍❤️‍,","‍❤️‍‍,"‍❤️‍‍,",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","☝","☝,"☝,"☝,"☝,"☝,",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","✌","✌,"✌,"✌,"✌,"✌,",",",",",","✊","✊,"✊,"✊,"✊,"✊,"✋","✋,"✋,"✋,"✋,"✋,",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","⚡️",",","☀️","⛅️","☁️",",","☔️",","❄️",","⭐️",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","☕️",",",",",",",",",",",",",",",",",",",",",","✨",",",",",",",",",","❤️",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","⛄️",",",",",",",",",",",",",",",",",",","⛺️",","⚽️",",","⚾️",",","⛳️",",",",",",",",",",",",",",",",",",",",",",",",",",",","️",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","⛽️",",",",",","✈️",","⚓️",",","⛵️",",",",",",",",",",",",",",",","⛲️",",",",",",",",",",",",",",",",",",","⛪️",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","⌚️",",",","⏰","⏳","⌛️",",",",",",",","☎️",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","✉️",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",",","✂️",",",",",",","✒️","✏️",",",",",",",",",",",",",",",",",",",",","⛔️",",",",",",",",",",","㊙️","㊗️",",",",","️",",",",",",",","️",","❇️","✳️","❎","✅","✴️",",",",",",",",",",","️",",",",",",",",","♈️","♉️","♊️","♋️","♌️","♍️","♎️","♏️","♐️","♑️","♒️","♓️",",",",","♿️",",",","▶️","◀️",",","⏩","⏪","⏫","⏬","➡️","⬅️","⬆️","⬇️","↗️","↘️","↙️","↖️","↕️","↔️",","↪️","↩️","⤴️","⤵️",",",","#⃣","0⃣","1⃣","2⃣","3⃣","4⃣","5⃣","6⃣","7⃣","8⃣","9⃣",",",",",","ℹ️",",",","➕","➖","〰","➗","✖️","✔️",","™","©","®",",","➰","➿","〽️","❗️","❓","❕","❔","‼️","⁉️","❌","⭕️",",",",",",",","Ⓜ️","⛎",",",","⚠️","♨️","♻️",",","♠️","♣️","♥️","♦️","☑️","⚪️","⚫️",",",",",",",",",","▪️","▫️","⬛️","⬜️","◼️","◻️","◾️","◽️",",",",",",",",",",",",",",",",",",",",",",",",",","]

Also you could write them into a plist file for persistence.

(allEmojis as NSArray).writeToFile(NSHomeDirectory() + "/emoji.plist", atomically: true)

NSNonLossyASCIIStringEncoding returns nil

The problem is due to different encodings you have used for encoding and decoding.

 testString=":;Hello \ud83d\ude09\ud83d\ude00 ., <> /?\";
NSData *data = [testString dataUsingEncoding:NSUTF8StringEncoding];

Here you have converted a string to data using UTF8 encoding. This means it will convert the unicode characters in 1-4 bytes depending on the unicode character used. for e.g. \ude09 will translate to ED B8 89. The explanation of the same is available in wiki. Basically is uses the following technique:

Sample Image

Now if you try to decode this to string using ascii encoding like below

   NSString *strBody = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding]; 

The above is bound to fail as it cannot decode ED B8 89 or similar unicode data to ascii string. That's why it returns an error.

If the data was ascii encoded, it would have used literal ascii hex for the conversion. So \ude09 would have become "5c 75 64 65 30 39"

So the correct conversion would be :

    testString=":;Hello \ud83d\ude09\ud83d\ude00 ., <> /?\";
NSData *data = [testString dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *strBody = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];

The question for you is why you want it to encode as UTF8 and decode as ASCII?


For emojis, please try the below

        testString=":;Hello \\ud83d\\ude09\\ud83d\\ude00 ., <> /?";
NSData *data = [testString dataUsingEncoding:NSUTF8StringEncoding];
NSString *strBody = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];

Find all available images for Image(systemName:) in SwiftUI

These icons are called SF Symbols. There are over 3,300 symbols you can use in iOS 13 and later, macOS 11 and later, watchOS 6 and later, and tvOS 13 and later. You can use a symbol everywhere you can use an image.

To browse the full set of symbols, download the SF Symbols app. For more info about SF Symbols check here.

History of SF Symbols updates:


SF Symbols 2 introduces over 750 new symbols and includes:

  • Over 150 preconfigured, multicolor symbols that automatically adapt to vibrancy, accessibility settings, and appearance modes
  • Negative side margins in both standard and custom symbols, giving you
    greater control over horizontal alignment
  • Localized symbol variants for right-to-left writing systems, as well
    as script-specific symbols for Arabic, Devanagari, and Hebrew

SF Symbols 3 features over 600 new symbols, enhanced color customization, a new inspector, and improved support for custom symbols.


SF Symbols 4 features over 1000 new symbols, variable color, automatic rendering, and new unified layer annotation. These new symbols are available in apps running iOS 16, iPadOS 16, macOS 13, tvOS 16, and watchOS 9.


Usage

UIKit:

let heartImage = UIImage(systemName: "heart.fill")

SwiftUI:

let heartImage = Image(systemName: "heart.fill")


Related Topics



Leave a reply



Submit