Avatar
norio_nomura 1/24/2019 2:19 AM
Swift 4.2.1までString.Index.encodedOffsetはUTF-16のオフセット。 Swift 5ではUTF-8とUTF-16が混在し、 Linuxだと(常に?)UTF-8 macOSだとNativeなStringはUTF-8、NSString APIで作ったStringはUTF-16になる。 $ xcrun --toolchain org.swift.5020190122a swift test.swift endIndex.encodedOffset is 4 that same with utf8 offset (String) endIndex.encodedOffset is 2 that same with utf16 offset (String created by NSString API) $ xcrun --toolchain org.swift.42120181030a swift test.swift endIndex.encodedOffset is 2 that same with utf16 offset (String) endIndex.encodedOffset is 2 that same with utf16 offset (String created by NSString API) (edited)