{"id":35719,"date":"2022-04-27T14:58:19","date_gmt":"2022-04-27T18:58:19","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=35719"},"modified":"2022-04-27T14:58:19","modified_gmt":"2022-04-27T18:58:19","slug":"attributedstrings-codable-format","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/04\/27\/attributedstrings-codable-format\/","title":{"rendered":"AttributedString&rsquo;s Codable Format"},"content":{"rendered":"<p><a href=\"https:\/\/oleb.net\/2022\/attributedstring-codable\/\">Ole Begemann<\/a>:<\/p>\n<blockquote cite=\"https:\/\/oleb.net\/2022\/attributedstring-codable\/\">\n<p>The problem is that the character offsets that define the runs aren&rsquo;t guaranteed to be stable. The definition of what constitutes a <a href=\"https:\/\/developer.apple.com\/documentation\/swift\/character\"><code>Character<\/code><\/a>, i.e. a user-perceived character, or a <a href=\"https:\/\/unicode.org\/reports\/tr29\/#Grapheme_Cluster_Boundaries\">Unicode grapheme cluster<\/a>, can and does change in new Unicode versions.<\/p>\n<p>[&#8230;]<\/p>\n<p>The people on the Foundation team know all this, of course, and chose a better encoding format for <code>Attributed String<\/code>.<\/p>\n<p>[&#8230;]<\/p>\n<p>This is an array of runs, where each run consists of a text segment and a dictionary of formatting attributes. The important point is that the formatting attributes are directly associated with the text segments they belong to, not indirectly via brittle byte or character offsets.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Ole Begemann: The problem is that the character offsets that define the runs aren&rsquo;t guaranteed to be stable. The definition of what constitutes a Character, i.e. a user-perceived character, or a Unicode grapheme cluster, can and does change in new Unicode versions. [&#8230;] The people on the Foundation team know all this, of course, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2022-04-27T18:58:30Z","apple_news_api_id":"2ae5df6e-1d19-4bb3-9040-34a2980b8343","apple_news_api_modified_at":"2022-04-27T18:58:30Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AKuXfbh0ZS7OQQDSimAuDQw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,71,1774,901,258],"class_list":["post-35719","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-programming","tag-swift-codable","tag-swift-programming-language","tag-unicode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=35719"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35719\/revisions"}],"predecessor-version":[{"id":35720,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35719\/revisions\/35720"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=35719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=35719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=35719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}