Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor mechanism to deserialize user-defined classes for entries #138

Merged
merged 5 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=0.10.2
CONTENTFUL_SDK_VERSION=0.11.0
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export CONTENFUL_SDK_VERSION=0.10.2
export CONTENFUL_SDK_VERSION=0.11.0
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from
## Table of contents

#### 0.x Releases
- `0.10.x` Releases - [0.11.0](#0110)
- `0.10.x` Releases - [0.10.0](#0100) | [0.10.1](#0101) | [0.10.2](#0102)
- `0.9.x` Releases - [0.9.0](#090) | [0.9.1](#091) | [0.9.2](#092) | [0.9.3](#093)
- `0.8.x` Releases - [0.8.0](#080)
Expand All @@ -22,12 +23,25 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from

---

## [`0.11.0`](https://github.com/contentful/contentful.swift/releases/tag/0.11.0)
Released on 2017-10-10

#### Changed
- **BREAKING:** `EntryModellable` is now called `EntryDecodable` and extends `Decodable` from the Swift 4 Foundation standard library. There are convenience methods for deserializing fields in the "fields" container for an entry.
- **BREAKING:** The `MappedContent` type no longer exists. If requesting heterogeneous collections (by hitting "/entries" with no query paramters for intance), you will get a `Result<MixedMappedArrayResponse>` and it is up to you to filter the array by the contained types.

#### Fixed
- [#132](https://github.com/contentful/contentful.swift/issues/132) `EntryDecodable` not synthesizing arrays of links
- [#133](https://github.com/contentful/contentful.swift/issues/133) `EntryDecodable` not allowing properties that are implicit optionals

---

## [`0.10.2`](https://github.com/contentful/contentful.swift/releases/tag/0.10.2)
Released on 2017-10-06

#### Fixed
- Compile error due to incorrect protection level setting
`

---

## [`0.10.1`](https://github.com/contentful/contentful.swift/releases/tag/0.10.1)
Expand Down
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=0.10.2
CONTENTFUL_SDK_VERSION=0.11.0
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ client.fetchEntries(with: query).next { catsArrayResponse in
//: Each entry has a number of read-only system fields, like its creation date
let creationDate = cat.sys.createdAt
//: You also have access to its user-defined fields in a similar fashion
let name = cat.fields.string(at:"name") ?? ""
let name = cat.fields.string(at: "name") ?? ""
let likes = cat.fields.strings(at: "likes")?.joined(separator: " and ") ?? ""
let lives = cat.fields.int(at: "lives") ?? 0

Expand All @@ -56,7 +56,7 @@ client.fetchEntries(with: query).next { catsArrayResponse in
//: The SDK will also resolve any included links automatically for you.
guard let friend = cat.fields.linkedEntry(at: "bestFriend") else { return }

let friendsName = friend.fields.string(at:"name") ?? ""
let friendsName = friend.fields.string(at: "name") ?? ""
let friendsLikes = friend.fields.strings(at: "likes")?.joined(separator: " and ") ?? ""

print("\(name)'s friend is named: '\(friendsName)'")
Expand Down
24 changes: 16 additions & 8 deletions Contentful.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
A1BF6BBC1C0D0FBD00049712 /* SignalUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1BF6BBB1C0D0FBD00049712 /* SignalUtils.swift */; };
ED02BC611E7047B900BAB2CA /* QueryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED02BC5F1E7047AE00BAB2CA /* QueryTests.swift */; };
ED0876DA1E1D07B3008E1A06 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0876D91E1D07B3008E1A06 /* Date.swift */; };
ED10F3FA1F8BD82200A00180 /* QueryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED10F3F81F8BD81F00A00180 /* QueryTests.json */; };
ED10F3FB1F8BD82300A00180 /* QueryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED10F3F81F8BD81F00A00180 /* QueryTests.json */; };
ED10F3FC1F8BD82300A00180 /* QueryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED10F3F81F8BD81F00A00180 /* QueryTests.json */; };
ED1638C51ED5CA6D009BAA9F /* ImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED1638C41ED5CA6D009BAA9F /* ImageTests.swift */; };
ED1D789A1F2F96260048E169 /* DataCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED1D78991F2F96260048E169 /* DataCache.swift */; };
ED1D789B1F2F96260048E169 /* DataCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED1D78991F2F96260048E169 /* DataCache.swift */; };
Expand Down Expand Up @@ -110,9 +113,6 @@
ED68BD731E6DC47F00939F6D /* Query.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED68BD711E6DC47A00939F6D /* Query.swift */; };
ED68BD741E6DC48000939F6D /* Query.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED68BD711E6DC47A00939F6D /* Query.swift */; };
ED68BD751E6DC48000939F6D /* Query.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED68BD711E6DC47A00939F6D /* Query.swift */; };
ED6EA90A1F44675F00FCA0F2 /* QueryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED6EA9081F44675C00FCA0F2 /* QueryTests.json */; };
ED6EA90B1F44676000FCA0F2 /* QueryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED6EA9081F44675C00FCA0F2 /* QueryTests.json */; };
ED6EA90C1F44676000FCA0F2 /* QueryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED6EA9081F44675C00FCA0F2 /* QueryTests.json */; };
ED737C6B1EF0095400ECB3F1 /* AssetTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED737C691EF0095200ECB3F1 /* AssetTests.json */; };
ED737C6E1EF0097000ECB3F1 /* ContentTypeTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED737C6C1EF0096D00ECB3F1 /* ContentTypeTests.json */; };
ED737C711EF0098C00ECB3F1 /* EntryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = ED737C6F1EF0098A00ECB3F1 /* EntryTests.json */; };
Expand Down Expand Up @@ -193,6 +193,9 @@
EDBEC9511E3F548F0040FC56 /* Contentful.h in Headers */ = {isa = PBXBuildFile; fileRef = EDBEC9491E3F51FE0040FC56 /* Contentful.h */; settings = {ATTRIBUTES = (Public, ); }; };
EDBEC9521E3F548F0040FC56 /* Contentful.h in Headers */ = {isa = PBXBuildFile; fileRef = EDBEC9491E3F51FE0040FC56 /* Contentful.h */; settings = {ATTRIBUTES = (Public, ); }; };
EDBEC9531E3F54900040FC56 /* Contentful.h in Headers */ = {isa = PBXBuildFile; fileRef = EDBEC9491E3F51FE0040FC56 /* Contentful.h */; settings = {ATTRIBUTES = (Public, ); }; };
EDE83CBC1F8CEA8C00467CD6 /* LinkResolverTests.json in Resources */ = {isa = PBXBuildFile; fileRef = EDE83CBA1F8CEA8A00467CD6 /* LinkResolverTests.json */; };
EDE83CBD1F8CEA8D00467CD6 /* LinkResolverTests.json in Resources */ = {isa = PBXBuildFile; fileRef = EDE83CBA1F8CEA8A00467CD6 /* LinkResolverTests.json */; };
EDE83CBE1F8CEA8D00467CD6 /* LinkResolverTests.json in Resources */ = {isa = PBXBuildFile; fileRef = EDE83CBA1F8CEA8A00467CD6 /* LinkResolverTests.json */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -247,6 +250,7 @@
A1BF6BBB1C0D0FBD00049712 /* SignalUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SignalUtils.swift; sourceTree = "<group>"; };
ED02BC5F1E7047AE00BAB2CA /* QueryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryTests.swift; sourceTree = "<group>"; };
ED0876D91E1D07B3008E1A06 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
ED10F3F81F8BD81F00A00180 /* QueryTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = QueryTests.json; sourceTree = "<group>"; };
ED1638C41ED5CA6D009BAA9F /* ImageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageTests.swift; sourceTree = "<group>"; };
ED1D78991F2F96260048E169 /* DataCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataCache.swift; sourceTree = "<group>"; };
ED1D789E1F3069FF0048E169 /* Client+Modellable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Client+Modellable.swift"; sourceTree = "<group>"; };
Expand All @@ -261,7 +265,6 @@
ED535E631F5E8E1300886D93 /* Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Decodable.swift; sourceTree = "<group>"; };
ED65CF951E3F6BF8000EBC62 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = "<group>"; };
ED68BD711E6DC47A00939F6D /* Query.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Query.swift; sourceTree = "<group>"; };
ED6EA9081F44675C00FCA0F2 /* QueryTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = QueryTests.json; sourceTree = "<group>"; };
ED737C691EF0095200ECB3F1 /* AssetTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = AssetTests.json; sourceTree = "<group>"; };
ED737C6C1EF0096D00ECB3F1 /* ContentTypeTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ContentTypeTests.json; sourceTree = "<group>"; };
ED737C6F1EF0098A00ECB3F1 /* EntryTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = EntryTests.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -294,6 +297,7 @@
EDDC070F1E3BCE920022F2F9 /* Contentful.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Contentful.framework; sourceTree = BUILT_PRODUCTS_DIR; };
EDDC071C1E3BCEA40022F2F9 /* Contentful.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Contentful.framework; sourceTree = BUILT_PRODUCTS_DIR; };
EDDC07291E3BCEB10022F2F9 /* Contentful.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Contentful.framework; sourceTree = BUILT_PRODUCTS_DIR; };
EDE83CBA1F8CEA8A00467CD6 /* LinkResolverTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = LinkResolverTests.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -520,11 +524,12 @@
ED9102671E65AE880076FDBD /* DVRRecordings */ = {
isa = PBXGroup;
children = (
ED10F3F81F8BD81F00A00180 /* QueryTests.json */,
EDE83CBA1F8CEA8A00467CD6 /* LinkResolverTests.json */,
ED737C691EF0095200ECB3F1 /* AssetTests.json */,
ED737C6C1EF0096D00ECB3F1 /* ContentTypeTests.json */,
ED737C6F1EF0098A00ECB3F1 /* EntryTests.json */,
ED737C721EF009A000ECB3F1 /* ImageTests.json */,
ED6EA9081F44675C00FCA0F2 /* QueryTests.json */,
ED737C871EF15CC600ECB3F1 /* PreviewSyncTests.json */,
ED737C7E1EF00A0600ECB3F1 /* RateLimitTests.json */,
ED737C751EF009C400ECB3F1 /* testClientCanAccessPreviewAPI.json */,
Expand Down Expand Up @@ -794,10 +799,11 @@
ED737C771EF009C700ECB3F1 /* testClientCanAccessPreviewAPI.json in Resources */,
ED737C831EF00A2000ECB3F1 /* testFetchSpace.json in Resources */,
ED737C6E1EF0097000ECB3F1 /* ContentTypeTests.json in Resources */,
ED6EA90C1F44676000FCA0F2 /* QueryTests.json in Resources */,
ED10F3FC1F8BD82300A00180 /* QueryTests.json in Resources */,
ED737C6B1EF0095400ECB3F1 /* AssetTests.json in Resources */,
ED737C741EF009A500ECB3F1 /* ImageTests.json in Resources */,
A10FF9D81BBB3860001AA4E9 /* Data in Resources */,
EDE83CBC1F8CEA8C00467CD6 /* LinkResolverTests.json in Resources */,
ED737C801EF00A0800ECB3F1 /* RateLimitTests.json in Resources */,
ED737C7A1EF009DD00ECB3F1 /* testClientCantAccessPreviewAPIWithProductionToken.json in Resources */,
ED737C921EF1748700ECB3F1 /* SyncTests.json in Resources */,
Expand All @@ -813,10 +819,11 @@
EDA690B41F43188500581FC6 /* testFetchSpace.json in Resources */,
EDA690B01F43188500581FC6 /* RateLimitTests.json in Resources */,
EDA690B31F43188500581FC6 /* SyncTests.json in Resources */,
ED6EA90B1F44676000FCA0F2 /* QueryTests.json in Resources */,
ED10F3FB1F8BD82300A00180 /* QueryTests.json in Resources */,
EDA690AB1F43188500581FC6 /* ContentTypeTests.json in Resources */,
EDA690AA1F43188500581FC6 /* AssetTests.json in Resources */,
EDA690AD1F43188500581FC6 /* ImageTests.json in Resources */,
EDE83CBD1F8CEA8D00467CD6 /* LinkResolverTests.json in Resources */,
EDA690AF1F43188500581FC6 /* PreviewSyncTests.json in Resources */,
EDA690B21F43188500581FC6 /* testClientCantAccessPreviewAPIWithProductionToken.json in Resources */,
EDA690B11F43188500581FC6 /* testClientCanAccessPreviewAPI.json in Resources */,
Expand All @@ -832,10 +839,11 @@
EDA690BF1F43188500581FC6 /* testFetchSpace.json in Resources */,
EDA690BB1F43188500581FC6 /* RateLimitTests.json in Resources */,
EDA690BE1F43188500581FC6 /* SyncTests.json in Resources */,
ED6EA90A1F44675F00FCA0F2 /* QueryTests.json in Resources */,
ED10F3FA1F8BD82200A00180 /* QueryTests.json in Resources */,
EDA690B61F43188500581FC6 /* ContentTypeTests.json in Resources */,
EDA690B51F43188500581FC6 /* AssetTests.json in Resources */,
EDA690B81F43188500581FC6 /* ImageTests.json in Resources */,
EDE83CBE1F8CEA8D00467CD6 /* LinkResolverTests.json in Resources */,
EDA690BA1F43188500581FC6 /* PreviewSyncTests.json in Resources */,
EDA690BD1F43188500581FC6 /* testClientCantAccessPreviewAPIWithProductionToken.json in Resources */,
EDA690BC1F43188500581FC6 /* testClientCanAccessPreviewAPI.json in Resources */,
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ client.fetchEntry("nyancat") { (result: Result<Entry>) in
}
```

## `EntryModellable` and `MappedContent`
## `EntryDecodable`

The `EntryModellable` protocols allows you to define types that will be mapped from `Entry`s of the various content types in your Contentful space. When using methods such as:
The `EntryDecodable` protocol allows you to define types that will be mapped from `Entry`s of the various content types in your Contentful space. When using methods such as:

```swift
func fetchMappedEntries(with query: Query) -> Observable<Result<MappedContent>>
func fetchMappedEntries(with query: Query) -> Observable<Result<MappedArrayResponse<EntryDecodable>>>
```

the asynchronously returned result will be an instance of `MappedContent` which will contain a dictionary which maps content type identifiers to arrays of `EntryModellable` (types of your own definition) that have been fetched. Note that these features are in beta and the API is subject to change.
the asynchronously returned result will be an instance of `MappedArrayResponse` in which the generic type parameter is the class you've defined for your content type. If you are using a `Query` that does not restrict the response to contain entries of one content type, you will use methods that return `MixedMappedArrayResponse` instead of `MappedArrayResponse`. The `EntryDecodable` protocol extends the `Decodable` protocol in Swift 4's Foundation standard library. The SDK provides helper methods for resolving relationships between `EntryDecodable`s and also for grabbing values from the fields container in the JSON for each resource.

## Swift playground

Expand Down
Loading