https://github.com/tattn/mergeable
Mergeable is a protocol which can merge multiple models.
https://github.com/tattn/mergeable
codable ios macos swift
Last synced: about 2 months ago
JSON representation
Mergeable is a protocol which can merge multiple models.
- Host: GitHub
- URL: https://github.com/tattn/mergeable
- Owner: tattn
- License: mit
- Created: 2017-11-26T16:47:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-26T18:17:04.000Z (over 8 years ago)
- Last Synced: 2025-04-14T03:39:37.860Z (about 1 year ago)
- Topics: codable, ios, macos, swift
- Language: Swift
- Homepage:
- Size: 13.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mergeable
===
[](https://github.com/Carthage/Carthage)
[](https://developer.apple.com/swift)
Mergeable is a protocol which can merge multiple models.
```swift
struct APIResponse: Encodable {
let id: Int
let title: String
let foo: String
}
struct APIResponse2: Encodable {
let tags: [String]
}
struct Model: Decodable, Mergeable {
let id: Int
let title: String
let tags: [String]
}
let response = APIResponse(id: 0, title: "にゃーん", foo: "bar")
let response2 = APIResponse2(tags: ["swift", "ios", "macos"])
let model = try Model.merge(response, response2)
XCTAssertEqual(model.id, response.id)
XCTAssertEqual(model.title, response.title)
XCTAssertEqual(model.tags, response2.tags)
```
##
# Installation
## Carthage
```ruby
github "tattn/Mergeable"
```
# Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
# License
Mergeable is released under the MIT license. See LICENSE for details.