# \#encoding

**URL:** https://forums.swift.org/tag/encoding/396.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Introducing Automerge: enable collaborative, asynchronous syncing for your data structures](https://forums.swift.org/t/introducing-automerge-enable-collaborative-asynchronous-syncing-for-your-data-structures/67985)

<div class="topic-metadata">

**Author:** [@Joseph\_Heck](https://forums.swift.org/u/Joseph_Heck)\
**Replies:** 12\
**Last updated:** [March 11, 2026, 6:44pm UTC](https://forums.swift.org/t/introducing-automerge-enable-collaborative-asynchronous-syncing-for-your-data-structures/67985 "2026-03-11T18:44:22Z")

</div>

The Automerge-swift library enables collaborative, multi-user editing experience akin to Apple's Notes app or Google docs, or fully offline (local-first) editing with later seamless syncing of those updates. Using Autome…

---

## [Encoding int-keyed dictionaries](https://forums.swift.org/t/encoding-int-keyed-dictionaries/82105)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 11\
**Last updated:** [September 16, 2025, 2:04pm UTC](https://forums.swift.org/t/encoding-int-keyed-dictionaries/82105 "2025-09-16T14:04:28Z")

</div>

I'm creating a custom encoder backed up by a custom encoding container, and want to distinguish the case of string-key based dictionary vs int-key based dictionary: try! \["123" : 0\].encode(to: MyEncoder()) // does one t…

---

## [Text encoding problems on Linux and Windows](https://forums.swift.org/t/text-encoding-problems-on-linux-and-windows/78656)

<div class="topic-metadata">

**Author:** [@sspringer](https://forums.swift.org/u/sspringer)\
**Replies:** 1\
**Last updated:** [March 19, 2025, 3:48pm UTC](https://forums.swift.org/t/text-encoding-problems-on-linux-and-windows/78656 "2025-03-19T15:48:39Z")

</div>

There are major problems with text encodings on Linux and Windows see this Swift issue from end of December which seemingly have not been addressed so far (the issue still displays "triage needed"). The problems are with…

---

## [Lossy decoding from Data to String](https://forums.swift.org/t/lossy-decoding-from-data-to-string/71515)

<div class="topic-metadata">

**Author:** [@sonodima](https://forums.swift.org/u/sonodima)\
**Replies:** 10\
**Last updated:** [April 30, 2024, 7:08am UTC](https://forums.swift.org/t/lossy-decoding-from-data-to-string/71515 "2024-04-30T07:08:53Z")

</div>

I am trying to implement these two methods to read and write strings with the specified encoding to memory. func read(from address: Int, maxLength: Int, encoding: String.Encoding) -\> String? func write(to address: Int, …

---

## [How can I encode a struct to Data/binary?](https://forums.swift.org/t/how-can-i-encode-a-struct-to-data-binary/68652)

<div class="topic-metadata">

**Author:** [@danmihai](https://forums.swift.org/u/danmihai)\
**Replies:** 14\
**Last updated:** [March 6, 2024, 10:34pm UTC](https://forums.swift.org/t/how-can-i-encode-a-struct-to-data-binary/68652 "2024-03-06T22:34:59Z")

</div>

I know Swift has the Codable interface that allows a type be encoded or decoded. However, I only know of two encoders, namely JSONEncoder and PropertyListEncoder. What do I do if all I want to binary (aka Data) encode?

---

## [Encoder & an Actor for the data?](https://forums.swift.org/t/encoder-an-actor-for-the-data/70403)

<div class="topic-metadata">

**Author:** [@carlynorama](https://forums.swift.org/u/carlynorama)\
**Replies:** 3\
**Last updated:** [March 4, 2024, 5:07pm UTC](https://forums.swift.org/t/encoder-an-actor-for-the-data/70403 "2024-03-04T17:07:20Z")

</div>

Does anyone have an example of using an Actor as their data type for their custom Encoder? A TaskGroup to parallelize the encoding? If so I'd love to see it. I'm not sure it should be even something to try.

---

## [Converting UTF-16 byte offset to String.Index](https://forums.swift.org/t/converting-utf-16-byte-offset-to-string-index/69212)

<div class="topic-metadata">

**Author:** [@bbbb](https://forums.swift.org/u/bbbb)\
**Replies:** 2\
**Last updated:** [December 30, 2023, 9:22pm UTC](https://forums.swift.org/t/converting-utf-16-byte-offset-to-string-index/69212 "2023-12-30T21:22:42Z")

</div>

I am receiving UTF16-encoded strings from a server as well as byte offsets for accessing substrings. These byte offsets are all for the UTF-16 text that is received and can be assumed to not fall in the middle of a code …

---

## [Custom binary encoder](https://forums.swift.org/t/custom-binary-encoder/67934)

<div class="topic-metadata">

**Author:** [@e-asphyx](https://forums.swift.org/u/e-asphyx)\
**Replies:** 10\
**Last updated:** [October 18, 2023, 9:23pm UTC](https://forums.swift.org/t/custom-binary-encoder/67934 "2023-10-18T21:23:59Z")

</div>

Swift standard library provides two Encoder implementations: for JSON and for Property List. Both (not 100 percent sure about PL though) support keyed containers for storing structures. What if the destination format has…

---

## [@Observable with Custom Encoders/Decoders](https://forums.swift.org/t/observable-with-custom-encoders-decoders/67895)

<div class="topic-metadata">

**Author:** [@AaronLBratcher](https://forums.swift.org/u/AaronLBratcher)\
**Replies:** 0\
**Last updated:** [October 16, 2023, 9:46pm UTC](https://forums.swift.org/t/observable-with-custom-encoders-decoders/67895 "2023-10-16T21:46:09Z")

</div>

I have a library here: GitHub - AaronBratcher/AgileDB: Easy way to save and retrieve full object graphs from a SQLite Database in Swift It uses custom encoder and decoder to work with SQLite. When using the @Observable …

---

## [Introducing JSONParsing: A library for writing bidirectional JSON parsers](https://forums.swift.org/t/introducing-jsonparsing-a-library-for-writing-bidirectional-json-parsers/66194)

<div class="topic-metadata">

**Author:** [@Oskar\_Ek](https://forums.swift.org/u/Oskar_Ek)\
**Replies:** 0\
**Last updated:** [July 17, 2023, 7:50am UTC](https://forums.swift.org/t/introducing-jsonparsing-a-library-for-writing-bidirectional-json-parsers/66194 "2023-07-17T07:50:46Z")

</div>

Hi :wave: I'd like to introduce JSONParsing - a library for decoding and encoding JSON, built on top of Parsing. This library provides an alternative approach for dealing with JSON to the default way in Swift, which is…

---

## [Aggregating two Encodable's](https://forums.swift.org/t/aggregating-two-encodables/52515)

<div class="topic-metadata">

**Author:** [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Replies:** 1\
**Last updated:** [October 1, 2021, 2:29pm UTC](https://forums.swift.org/t/aggregating-two-encodables/52515 "2021-10-01T14:29:11Z")

</div>

I've just encountered the following in our codebase: public struct ComposedEncodable\<T: Encodable, U: Encodable\>: Encodable { let base: T let extra: U public func encode(to encoder: Encoder) throws { …

---

## [What is the default encoding of String(contentsOf:)?](https://forums.swift.org/t/what-is-the-default-encoding-of-string-contentsof/38406)

<div class="topic-metadata">

**Author:** [@PatrickA](https://forums.swift.org/u/PatrickA)\
**Replies:** 9\
**Last updated:** [September 22, 2020, 8:51am UTC](https://forums.swift.org/t/what-is-the-default-encoding-of-string-contentsof/38406 "2020-09-22T08:51:45Z")

</div>

I'm trying to find documentation which specifies the default encoding of String(contentsOf:) The documentation I found is very laconic... ("No overview available.") https://developer.apple.com/documentation/swift/stri…

---

## [Formatting %s with RTL and system default encoding](https://forums.swift.org/t/formatting-s-with-rtl-and-system-default-encoding/40479)

<div class="topic-metadata">

**Author:** [@PatrickA](https://forums.swift.org/u/PatrickA)\
**Replies:** 9\
**Last updated:** [September 22, 2020, 5:21am UTC](https://forums.swift.org/t/formatting-s-with-rtl-and-system-default-encoding/40479 "2020-09-22T05:21:12Z")

</div>

(May be this should be in the Swift Format category... I'm not too familiar with this forum. I will move this topic if this is not the right place. ) says that "Because the %s specifier causes the characters to be…

---

## [String(decoding: , as: ) with as: not UTF8.self and not ASCII.self](https://forums.swift.org/t/string-decoding-as-with-as-not-utf8-self-and-not-ascii-self/40464)

<div class="topic-metadata">

**Author:** [@PatrickA](https://forums.swift.org/u/PatrickA)\
**Replies:** 6\
**Last updated:** [September 21, 2020, 7:01pm UTC](https://forums.swift.org/t/string-decoding-as-with-as-not-utf8-self-and-not-ascii-self/40464 "2020-09-21T19:01:50Z")

</div>

Is there a way to use String(decoding: , as: ) with as: being another encoding that UTF8 or ASCII? I would like to be able decode an Windows 1252 byte array and display the EncodedReplacementCharacter for the character…
