How to get all available emojis in an array in Swift - Apple ...

文章推薦指數: 80 %
投票人數:10人

I want to be able to get an array of all the available emojis in Swift. ... ://stackoverflow.com/questions/30757193/find-out-if-character-in-string-is-emoji. GlobalNavOpenMenu GlobalNavCloseMenu AppleDeveloper SearchDeveloper Cancel AppleDeveloper Discover Design Develop Distribute Support Account Cancel DeveloperForums Searchbykeywordsortags SubmitSearch Clearsearchquery AdditionalinformationaboutSearchbykeywordsortags SupportedSearches:KeywordsearchkeywordSingletag[iOS]MultipletagswithOR[iOS]OR[macOS]OR[Xcode]MultipletagswithAND[iOS][macOS][Xcode]Keywordsandtags[iOS][macOS]keywordUsernamesandprofilesuser:appleseed Ask Profile ▲ Signin Createaccount Searchbykeywordsortags SubmitSearch Clearsearchquery AdditionalinformationaboutSearchbykeywordsortags SupportedSearches:KeywordsearchkeywordSingletag[iOS]MultipletagswithOR[iOS]OR[macOS]OR[Xcode]MultipletagswithAND[iOS][macOS][Xcode]Keywordsandtags[iOS][macOS]keywordUsernamesandprofilesuser:appleseed     You’renowwatchingthisthreadandwillreceiveemailswhenthere’sactivity.Clickagaintostopwatchingorvisityourprofile/homepagetomanageyourwatchedthreads.   You’vestoppedwatchingthisthreadandwillnolongerreceiveemailswhenthere’sactivity.Clickagaintostartwatching. IwanttobeabletogetanarrayofalltheavailableemojisinSwift.WhatImeanbyavailableisalltheonesthatarecurrentaccessabletothedevice.LikewhenAppleaddssomenewemojis,Iwouldliketonothavetochangeanycode,andthenewemojisjustgetaddedinthearraywithalltheotherones.Ifgettingupdatedemojisisnotpossible,thenhowcanIgetallofthecurrentemojisintoanarray(orperhapsa.plistfileIcanthenloadintoanarray)soIcanaccessthemincode? Swift   UpvotepostofAdalex DownvotepostofAdalex 4.5k views Asked by Adalex Copytoclipboard Sharethispost CopiedtoClipboard AnswerthisQuestion AddaComment AcceptedAnswer   ThisSOseemstoprovidetheanswerhttps://stackoverflow.com/questions/26170876/how-to-list-almost-all-emojis-in-swift-for-ios-8-without-using-any-form-of-looforiin0x1F601...0x1F64F{ letc=String(UnicodeScalar(i)??"-") print(c) }Youshouldgobeyond1F64F,https://stackoverflow.com/questions/30757193/find-out-if-character-in-string-is-emoji0x1F600...0x1F64F,//Emoticons8400...8447://CombiningDiacriticalMarksforSymbols9100...9300,//Miscitems0x2600...0x26FF,//Miscsymbols0x2700...0x27BF,//Dingbats0xFE00...0xFE0F,//VariationSelectors0x1F018...0x1F270,//Variousasiancharacters0x1F300...0x1F5FF,//MiscSymbolsandPictographs0x1F680...0x1F6FF,//TransportandMap0x1F1E6...0x1F1FF,//Regionalcountryflags0x1F900...0x1F9FF,//SupplementalSymbolsandPictographs65024...65039,//VariationselectorHowever,yougetsomeundefined(markedas?attheendofranges)Seeheretoskipthemhttps://stackoverflow.com/questions/41318999/is-there-a-way-to-know-if-an-emoji-is-supported-in-iosNote,whilesearching,foundthisinterestinglinktogenerateemojiflagsbasedoncountrycodewww.timekl.com/blog/2017/08/31/swift-tricks-emoji-flags/ThatendsupwiththefollowingcodefuncisEmoji(_value:Int)->Bool{ switchvalue{ case0x1F600...0x1F64F,//Emoticons 0x1F300...0x1F5FF,//MiscSymbolsandPictographs 0x1F680...0x1F6FF,//TransportandMap 0x1F1E6...0x1F1FF,//Regionalcountryflags 0x2600...0x26FF,//Miscsymbols9728-9983 0x2700...0x27BF,//Dingbats 0xFE00...0xFE0F,//VariationSelectors 0x1F900...0x1F9FF,//SupplementalSymbolsandPictographs129280-129535 0x1F018...0x1F270,//Variousasiancharacters127000...127600 65024...65039,//Variationselector 9100...9300,//Miscitems 8400...8447://CombiningDiacriticalMarksforSymbols returntrue default:returnfalse } } extensionCharacter{ privatestaticletrefUnicodeSize:CGFloat=8 privatestaticletrefUnicodePng= Character("\u{1fff}").png(ofSize:Character.refUnicodeSize) funcpng(ofSizefontSize:CGFloat)->Data?{ letattributes=[NSAttributedString.Key.font: UIFont.systemFont(ofSize:fontSize)] letcharStr="\(self)"asNSString letsize=charStr.size(withAttributes:attributes) UIGraphicsBeginImageContext(size) charStr.draw(at:CGPoint(x:0,y:0),withAttributes:attributes) varpng:Data?=nil ifletcharImage=UIGraphicsGetImageFromCurrentImageContext(){ png=charImage.pngData() } UIGraphicsEndImageContext() returnpng } funcunicodeAvailable()->Bool{ ifletrefUnicodePng=Character.refUnicodePng, letmyPng=self.png(ofSize:Character.refUnicodeSize){ returnrefUnicodePng!=myPng } returnfalse } } foriin8400...0x1F9FFwhereisEmoji(i){ ifletscalar=UnicodeScalar(i){ letunicode=Character(scalar) ifunicode.unicodeAvailable(){ print(i,String(scalar)) count+=1 }else{ notAvail+=1 print(i) } }else{ notCounted+=1 } } print("Count",count,"Notcounted",notCounted,"NotAvail",notAvail) Posted by Claude31 Copytoclipboard Sharethispost CopiedtoClipboard   UpvotereplyofClaude31 DownvotereplyofClaude31 Postmarkedassolved AddaComment Answers   ThisSOseemstoprovidetheanswerhttps://stackoverflow.com/questions/26170876/how-to-list-almost-all-emojis-in-swift-for-ios-8-without-using-any-form-of-looforiin0x1F601...0x1F64F{ letc=String(UnicodeScalar(i)??"-") print(c) }Youshouldgobeyond1F64F,https://stackoverflow.com/questions/30757193/find-out-if-character-in-string-is-emoji0x1F600...0x1F64F,//Emoticons8400...8447://CombiningDiacriticalMarksforSymbols9100...9300,//Miscitems0x2600...0x26FF,//Miscsymbols0x2700...0x27BF,//Dingbats0xFE00...0xFE0F,//VariationSelectors0x1F018...0x1F270,//Variousasiancharacters0x1F300...0x1F5FF,//MiscSymbolsandPictographs0x1F680...0x1F6FF,//TransportandMap0x1F1E6...0x1F1FF,//Regionalcountryflags0x1F900...0x1F9FF,//SupplementalSymbolsandPictographs65024...65039,//VariationselectorHowever,yougetsomeundefined(markedas?attheendofranges)Seeheretoskipthemhttps://stackoverflow.com/questions/41318999/is-there-a-way-to-know-if-an-emoji-is-supported-in-iosNote,whilesearching,foundthisinterestinglinktogenerateemojiflagsbasedoncountrycodewww.timekl.com/blog/2017/08/31/swift-tricks-emoji-flags/ThatendsupwiththefollowingcodefuncisEmoji(_value:Int)->Bool{ switchvalue{ case0x1F600...0x1F64F,//Emoticons 0x1F300...0x1F5FF,//MiscSymbolsandPictographs 0x1F680...0x1F6FF,//TransportandMap 0x1F1E6...0x1F1FF,//Regionalcountryflags 0x2600...0x26FF,//Miscsymbols9728-9983 0x2700...0x27BF,//Dingbats 0xFE00...0xFE0F,//VariationSelectors 0x1F900...0x1F9FF,//SupplementalSymbolsandPictographs129280-129535 0x1F018...0x1F270,//Variousasiancharacters127000...127600 65024...65039,//Variationselector 9100...9300,//Miscitems 8400...8447://CombiningDiacriticalMarksforSymbols returntrue default:returnfalse } } extensionCharacter{ privatestaticletrefUnicodeSize:CGFloat=8 privatestaticletrefUnicodePng= Character("\u{1fff}").png(ofSize:Character.refUnicodeSize) funcpng(ofSizefontSize:CGFloat)->Data?{ letattributes=[NSAttributedString.Key.font: UIFont.systemFont(ofSize:fontSize)] letcharStr="\(self)"asNSString letsize=charStr.size(withAttributes:attributes) UIGraphicsBeginImageContext(size) charStr.draw(at:CGPoint(x:0,y:0),withAttributes:attributes) varpng:Data?=nil ifletcharImage=UIGraphicsGetImageFromCurrentImageContext(){ png=charImage.pngData() } UIGraphicsEndImageContext() returnpng } funcunicodeAvailable()->Bool{ ifletrefUnicodePng=Character.refUnicodePng, letmyPng=self.png(ofSize:Character.refUnicodeSize){ returnrefUnicodePng!=myPng } returnfalse } } foriin8400...0x1F9FFwhereisEmoji(i){ ifletscalar=UnicodeScalar(i){ letunicode=Character(scalar) ifunicode.unicodeAvailable(){ print(i,String(scalar)) count+=1 }else{ notAvail+=1 print(i) } }else{ notCounted+=1 } } print("Count",count,"Notcounted",notCounted,"NotAvail",notAvail) Posted by Claude31 Copytoclipboard Sharethispost CopiedtoClipboard   UpvotereplyofClaude31 DownvotereplyofClaude31 Postmarkedassolved AddaComment   WithoutprejudicetoClaude31’sresponse,IwanttopointoutthatdeterminingifanarbitraryUnicodecharacterisanemojiisreallyhard.ThisissuewasdiscussedextensivelyoveronSwiftForumsaspartofthecreationofSE-0221CharacterProperties,andultimatelytheisEmojipropertywas droppedfromthatproposal.Ifyou’reinterestedinthegorydetails—andImustadmitthatIskippedoverthesemyself—youcanreadthe discussionthread. ShareandEnjoy—Quinn“TheEskimo!”AppleDeveloperRelations,DeveloperTechnicalSupport,CoreOS/HardwareletmyEmail="eskimo"+"1"+"@apple.com" Posted by eskimo  Copytoclipboard Sharethispost CopiedtoClipboard   Upvotereplyofeskimo Downvotereplyofeskimo AddaComment



請為這篇文章評分?