{"id":2052,"date":"2020-07-27T09:30:00","date_gmt":"2020-07-27T07:30:00","guid":{"rendered":"http:\/\/www.albertopasca.it\/whiletrue\/?p=2052"},"modified":"2023-06-26T15:54:07","modified_gmt":"2023-06-26T13:54:07","slug":"swift-identify-misspelled-words-and-errors-in-phrases","status":"publish","type":"post","link":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/","title":{"rendered":"Swift &#8211; Identify misspelled words and errors in phrases"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A simple tutorial for find and identify the wrong typed words of the user in your application using the <strong>UITextChecker<\/strong> framework and the <strong>NatualLanguage<\/strong> framework.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Final result:<\/h3>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"473\" height=\"1024\" data-id=\"2056\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.32.48-473x1024.png?resize=473%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-2056\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.32.48.png?resize=473%2C1024&amp;ssl=1 473w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.32.48.png?resize=139%2C300&amp;ssl=1 139w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.32.48.png?resize=768%2C1663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.32.48.png?resize=709%2C1536&amp;ssl=1 709w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.32.48.png?resize=946%2C2048&amp;ssl=1 946w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.32.48.png?w=1125&amp;ssl=1 1125w\" sizes=\"auto, (max-width: 473px) 100vw, 473px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"473\" height=\"1024\" data-id=\"2054\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.38.53-473x1024.png?resize=473%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-2054\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.38.53.png?resize=473%2C1024&amp;ssl=1 473w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.38.53.png?resize=139%2C300&amp;ssl=1 139w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.38.53.png?resize=768%2C1663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.38.53.png?resize=709%2C1536&amp;ssl=1 709w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.38.53.png?resize=946%2C2048&amp;ssl=1 946w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.38.53.png?w=1125&amp;ssl=1 1125w\" sizes=\"auto, (max-width: 473px) 100vw, 473px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"473\" height=\"1024\" data-id=\"2055\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.37.13-473x1024.png?resize=473%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-2055\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.37.13.png?resize=473%2C1024&amp;ssl=1 473w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.37.13.png?resize=139%2C300&amp;ssl=1 139w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.37.13.png?resize=768%2C1663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.37.13.png?resize=709%2C1536&amp;ssl=1 709w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.37.13.png?resize=946%2C2048&amp;ssl=1 946w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/03\/Simulator-Screen-Shot-iPhone-11-Pro-2020-03-27-at-12.37.13.png?w=1125&amp;ssl=1 1125w\" sizes=\"auto, (max-width: 473px) 100vw, 473px\" \/><\/figure>\n<\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-luminous-vivid-orange-color has-css-opacity has-luminous-vivid-orange-background-color has-background\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Let&#8217;s start!<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We use for this tutorial the following new things:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>NaturalLanguage<\/strong> framework (<a rel=\"noreferrer noopener\" aria-label=\"reference (opens in a new tab)\" href=\"https:\/\/developer.apple.com\/documentation\/naturallanguage\" target=\"_blank\">reference<\/a>)<\/li>\n\n\n\n<li><strong>NLLanguageRecognizer<\/strong> (<a rel=\"noreferrer noopener\" aria-label=\"reference (opens in a new tab)\" href=\"https:\/\/developer.apple.com\/documentation\/naturallanguage\/nllanguagerecognizer\" target=\"_blank\">reference<\/a>)<\/li>\n\n\n\n<li><strong>UITextChecker<\/strong> (<a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/uitextchecker\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"reference (opens in a new tab)\">reference<\/a>)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In order to identify the wrong words in your phrase, you need to understand the language of the phrase.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>NLLanguageRecognizer<\/strong> helps you to resolve this issue in a very simple way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">private func detectLanguage( phrase: String ) -&gt; NLLanguage? {\n     let recognizer = <strong>NLLanguageRecognizer<\/strong>()\n     recognizer.processString(phrase)\n     return recognizer.<strong>dominantLanguage<\/strong>\n }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can pass a phrase on it and get the corresponding language.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">let phrase = \"<strong>This si a text wiht lots of errrors. The scope of this tutorila is to colorizze the wrong wordss.<\/strong>\"\n\nlet phraseLanguage: NLLanguage? = <strong>detectLanguage<\/strong>( phrase: phrase )\nprint( phraseLanguage )<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we need to check all the words and get, <em>the wrong list words<\/em> or <em>the range of the words<\/em> (use it for <strong>NSAttributedStrings<\/strong> for instance)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;ve created a simple <strong>struct<\/strong> and a simple checker function, like these:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">struct <strong>Words<\/strong> {\n     var range: NSRange?\n     var word:  String\n }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And we use it in the checker:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">private func <strong>checkMispelledWords<\/strong>( phrase: String ) -&gt; [Words] {\n     <strong>var rangesOfWords: [Words] = [Words]()<\/strong>\n\n     let phraseLanguage: NLLanguage? = <strong>detectLanguage<\/strong>( phrase: phrase )\n     guard let language = phraseLanguage else { return rangesOfWords }\n\n     let textChecker = <strong>UITextChecker<\/strong>()\n     let nsString = NSString(string: phrase)\n     let stringRange = NSRange(location: 0, length: nsString.length)\n     var offset = 0\n\n     while true {\n         let wordRange = textChecker.<strong>rangeOfMisspelledWord<\/strong>(\n             in: phrase,\n             range: stringRange,\n             startingAt: offset,\n             wrap: false,\n             language: language.rawValue)\n\n         guard wordRange.location != NSNotFound else { <strong>break<\/strong> }\n\n         let wrongWord = nsString.substring(with: wordRange)\n         offset = wordRange.upperBound\n\n         <strong>rangesOfWords<\/strong>.append( <strong>Words<\/strong>(range: wordRange, word: wrongWord) )\n     }\n     return <strong>rangesOfWords<\/strong>\n }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have a new <strong>[Word]<\/strong> array with our data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">let words: [<strong>Words<\/strong>] = <strong>checkMispelledWords<\/strong>(\n                      phrase: textArea.attributedText.string)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you add a button and a textarea in your app you can attach the attributed string and play with the attributes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\"><strong>@IBAction<\/strong> func <strong>didCheckErrorsPressed<\/strong>(_ sender: Any) {\n     let words: [Words] = checkMispelledWords(phrase: textArea.attributedText.string)\n\n     <strong>words.forEach<\/strong> {\n         print( \"Word: (<strong>$0.word<\/strong>)\" )\n         attributedString?.addAttribute(<strong>NSAttributedString.Key.foregroundColor<\/strong>, value: <strong>UIColor.red<\/strong> , range: $0.range!)\n     }\n\n     textArea.attributedText = attributedString\n }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you can &#8220;<strong>coloryze<\/strong>&#8221; your text to make the errors in red.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enjoy writing!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A simple tutorial for find and identify the wrong typed words of the user in your application using the UITextChecker framework and the NatualLanguage framework. Final result:<\/p>\n","protected":false},"author":1,"featured_media":2522,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[217,763,12,11,3,30],"tags":[875,879,874,884,883,881,878,880,873,882,876,877,401],"class_list":["post-2052","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","category-ios","category-macos","category-mobile","category-swift","category-xcode","tag-attributedtext","tag-dominantlanguage","tag-foreach","tag-grammar","tag-language-recognizer","tag-misspelling","tag-nllanguage","tag-nllanguagerecognizer","tag-nsattributedstring","tag-phrases","tag-rangeofmisspelledword","tag-uitextchecker","tag-words"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Swift - Identify misspelled words and errors in phrases - while (true) {\u00a0}<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift - Identify misspelled words and errors in phrases - while (true) {\u00a0}\" \/>\n<meta property=\"og:description\" content=\"A simple tutorial for find and identify the wrong typed words of the user in your application using the UITextChecker framework and the NatualLanguage framework. Final result:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/\" \/>\n<meta property=\"og:site_name\" content=\"while (true) {\u00a0}\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-27T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-26T13:54:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/04\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1707\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Alberto Pasca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lupasca\" \/>\n<meta name=\"twitter:site\" content=\"@lupasca\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alberto Pasca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/\"},\"author\":{\"name\":\"Alberto Pasca\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"headline\":\"Swift &#8211; Identify misspelled words and errors in phrases\",\"datePublished\":\"2020-07-27T07:30:00+00:00\",\"dateModified\":\"2023-06-26T13:54:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/\"},\"wordCount\":190,\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"image\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1\",\"keywords\":[\"attributedText\",\"dominantLanguage\",\"forEach\",\"grammar\",\"language recognizer\",\"misspelling\",\"NLLanguage\",\"NLLanguageRecognizer\",\"NSAttributedString\",\"phrases\",\"rangeOfMisspelledWord\",\"UITextChecker\",\"words\"],\"articleSection\":[\"development\",\"ios\",\"macOS\",\"mobile\",\"swift\",\"xcode\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/\",\"name\":\"Swift - Identify misspelled words and errors in phrases - while (true) {\u00a0}\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1\",\"datePublished\":\"2020-07-27T07:30:00+00:00\",\"dateModified\":\"2023-06-26T13:54:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1\",\"width\":2560,\"height\":1707},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-identify-misspelled-words-and-errors-in-phrases\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift &#8211; Identify misspelled words and errors in phrases\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\",\"name\":\"while (true) {\u00a0}\",\"description\":\"notes from a developer, tutorials, how-to, ideas\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\",\"name\":\"Alberto Pasca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"caption\":\"Alberto Pasca\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\"},\"description\":\"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.\",\"sameAs\":[\"https:\\\/\\\/www.albertopasca.it\",\"albertopasca\",\"https:\\\/\\\/x.com\\\/lupasca\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Swift - Identify misspelled words and errors in phrases - while (true) {\u00a0}","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/","og_locale":"en_US","og_type":"article","og_title":"Swift - Identify misspelled words and errors in phrases - while (true) {\u00a0}","og_description":"A simple tutorial for find and identify the wrong typed words of the user in your application using the UITextChecker framework and the NatualLanguage framework. Final result:","og_url":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/","og_site_name":"while (true) {\u00a0}","article_published_time":"2020-07-27T07:30:00+00:00","article_modified_time":"2023-06-26T13:54:07+00:00","og_image":[{"width":2560,"height":1707,"url":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/04\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1","type":"image\/jpeg"}],"author":"Alberto Pasca","twitter_card":"summary_large_image","twitter_creator":"@lupasca","twitter_site":"@lupasca","twitter_misc":{"Written by":"Alberto Pasca","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/#article","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/"},"author":{"name":"Alberto Pasca","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"headline":"Swift &#8211; Identify misspelled words and errors in phrases","datePublished":"2020-07-27T07:30:00+00:00","dateModified":"2023-06-26T13:54:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/"},"wordCount":190,"publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"image":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/04\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1","keywords":["attributedText","dominantLanguage","forEach","grammar","language recognizer","misspelling","NLLanguage","NLLanguageRecognizer","NSAttributedString","phrases","rangeOfMisspelledWord","UITextChecker","words"],"articleSection":["development","ios","macOS","mobile","swift","xcode"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/","url":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/","name":"Swift - Identify misspelled words and errors in phrases - while (true) {\u00a0}","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/#primaryimage"},"image":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/04\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1","datePublished":"2020-07-27T07:30:00+00:00","dateModified":"2023-06-26T13:54:07+00:00","breadcrumb":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/#primaryimage","url":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/04\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/04\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1","width":2560,"height":1707},{"@type":"BreadcrumbList","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-identify-misspelled-words-and-errors-in-phrases\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.albertopasca.it\/whiletrue\/"},{"@type":"ListItem","position":2,"name":"Swift &#8211; Identify misspelled words and errors in phrases"}]},{"@type":"WebSite","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website","url":"https:\/\/www.albertopasca.it\/whiletrue\/","name":"while (true) {\u00a0}","description":"notes from a developer, tutorials, how-to, ideas","publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.albertopasca.it\/whiletrue\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac","name":"Alberto Pasca","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","caption":"Alberto Pasca"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g"},"description":"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.","sameAs":["https:\/\/www.albertopasca.it","albertopasca","https:\/\/x.com\/lupasca"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/04\/16e105be-905b-44ce-9c2e-83782aff68ad-scaled.jpg?fit=2560%2C1707&ssl=1","_links":{"self":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/2052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/comments?post=2052"}],"version-history":[{"count":28,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/2052\/revisions"}],"predecessor-version":[{"id":3391,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/2052\/revisions\/3391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media\/2522"}],"wp:attachment":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media?parent=2052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/categories?post=2052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/tags?post=2052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}