Skip to content

Commit

Permalink
feat: add nsdictionary helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed Aug 28, 2023
1 parent 91a054b commit d599829
Show file tree
Hide file tree
Showing 4 changed files with 2,422 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ios/Helpers/DictionaryCodingKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// This source file is largely a copy of code from Swift.org open source project's
// files JSONEncoder.swift and Codeable.swift.
//
// Unfortunately those files do not expose the internal _JSONEncoder and
// _JSONDecoder classes, which are in fact dictionary encoder/decoders and
// precisely what we want...
//
// The original code is copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
// Modifications and additional code here is copyright (c) 2018 Sam Deane, and
// is licensed under the same terms.
//
//===----------------------------------------------------------------------===//

import Foundation

internal struct DictionaryCodingKey : CodingKey {
public var stringValue: String
public var intValue: Int?

public init?(stringValue: String) {
self.stringValue = stringValue
self.intValue = nil
}

public init?(intValue: Int) {
self.stringValue = "\(intValue)"
self.intValue = intValue
}

public init(stringValue: String, intValue: Int?) {
self.stringValue = stringValue
self.intValue = intValue
}

internal init(index: Int) {
self.stringValue = "Index \(index)"
self.intValue = index
}

internal static let `super` = DictionaryCodingKey(stringValue: "super")!
}
Loading

0 comments on commit d599829

Please sign in to comment.