Swiftpack.co - nearfri/ObjectCoder as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nearfri.
nearfri/ObjectCoder 1.0.4
Swift Object Encoder/Decoder
⭐️ 0
🕓 46 weeks ago
.package(url: "https://github.com/nearfri/ObjectCoder.git", from: "1.0.4")


SwiftPM codecov

Swift Object Encoder/Decoder compatible with UserDefaults


import ObjectCoder

// Encode
let frame: CGRect = CGRect(x: 10.0, y: 20.0, width: 30.0, height: 40.0)
let encoded: Any = try ObjectEncoder().encode(frame)
let rawValue: [[Double]] = try XCTUnwrap(encoded as? [[Double]])
XCTAssertEqual(rawValue, [[10.0, 20.0], [30.0, 40.0]])

// Set to and get from UserDefaults
let defaults = UserDefaults.standard
defaults.set(encoded, forKey: "frame")
let object: Any = try XCTUnwrap(defaults.object(forKey: "frame"))

// Decode
let decodedFromEncoded: CGRect = try ObjectDecoder().decode(CGRect.self, from: encoded)
let decodedFromDefaults: CGRect = try ObjectDecoder().decode(CGRect.self, from: object)
XCTAssertEqual(decodedFromEncoded, frame)
XCTAssertEqual(decodedFromDefaults, frame)


Swift Package Manager

.package(url: "https://github.com/nearfri/ObjectCoder", from: "1.0.0")


Preferences is released under the MIT license. See LICENSE for more information.


Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics