Skip to content

Commit

Permalink
Merge pull request #131 from contentful/improvement/swift-4
Browse files Browse the repository at this point in the history
Migrate to Swift 4
  • Loading branch information
loudmouth authored Oct 2, 2017
2 parents 7219f90 + 9119e55 commit 624c6f3
Show file tree
Hide file tree
Showing 56 changed files with 956 additions and 608 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=0.9.3
CONTENTFUL_SDK_VERSION=0.10.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.9.3
export CONTENFUL_SDK_VERSION=0.10.0
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "Carthage/Checkouts/ObjectMapper"]
path = Carthage/Checkouts/ObjectMapper
url = https://github.com/Hearst-DD/ObjectMapper.git
[submodule "Carthage/Checkouts/Interstellar"]
path = Carthage/Checkouts/Interstellar
url = https://github.com/JensRavens/Interstellar.git
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
4.0
3 changes: 2 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ disabled_rules:
- vertical_parameter_alignment
# ignoring since some file that exists on travis, but not locally is throwing this as a compile error
# Also, swiftlint says it will be removed in future versions
- identifier_name
- identifier_name
- nesting # Disable warnings about structures nested more than 1 level deep.

# Parameterized
line_length:
Expand Down
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ rvm:
cache: bundler
matrix:
include:
# Xcode8
- osx_image: xcode8.3
env: SDK=iphonesimulator PLATFORM="iOS Simulator,name=iPhone 6s,OS=10.3.1" SCHEME=Contentful_iOS
- osx_image: xcode8.3
env: SDK=appletvsimulator PLATFORM="tvOS Simulator,name=Apple TV 1080p,OS=10.2" SCHEME=Contentful_tvOS
- osx_image: xcode8.3
env: SDK=macosx PLATFORM="OS X" SCHEME=Contentful_macOS
# Xcode9
- osx_image: xcode9
env: SDK=iphonesimulator PLATFORM="iOS Simulator,name=iPhone 6s,OS=11.0" SCHEME=Contentful_iOS
- osx_image: xcode9
env: SDK=appletvsimulator PLATFORM="tvOS Simulator,name=Apple TV 1080p,OS=11.0" SCHEME=Contentful_tvOS
- osx_image: xcode9
env: SDK=macosx PLATFORM="OS X" SCHEME=Contentful_macOS
- osx_image: xcode9
env: SWIFT_BUILD=true

script:
- ./Scripts/travis-build-test.sh
Expand Down
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/) starting from 1.x releases.

### Merged, but not yet released
> ~~All recent changes are published~~
> Fixed
> - Ensured all functions and instance members had an explicit protection level set.
> All recent changes are published
---

## Table of contents

#### 0.x Releases
- `0.10.x` Releases - [0.10.0](#0100)
- `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)
- `0.7.x` Releases - [0.7.0](#070) | [0.7.1](#071) | [0.7.2](#072) | [0.7.3](#073) | [0.7.4](#074) | [0.7.5](#075) | [0.7.6](#076) | [0.7.7](#077)
Expand All @@ -22,6 +22,17 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from

---

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

#### Changed
- **BREAKING:** The project is now compiled using Swift 4 and therefore must be developed against with Xcode 9. Backwards compatibility with Swift 3 is not possible as the SDK now uses Swift 4 features like JSON decoding via the `Decodable` protocol in Foundation.
- **BREAKING:** `CLLocationCoordinate2D` has been replaced with `Location` type native to the SDK so that linking with CoreLocation is no longer necessary. If you have location enabled queries, you'll need to migrate your code.
• `Resource` is now a protocol and is no longer the base class for `Asset` and `Entry`. `LocalizableResource` is the new base class.
- [ObjectMapper](https://github.com/Hearst-DD/ObjectMapper) has been pruned and is no longer a dependency of the SDK. If managing your dependencies with Carthage, make sure to manually remove ObjectMapper if you aren't using it yourself.

---

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

Expand Down
1 change: 0 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
github "JensRavens/Interstellar" ~> 2.1.0
github "Hearst-DD/ObjectMapper" ~> 2.2

4 changes: 2 additions & 2 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Quick/Nimble" ~> 7.0.1
github "venmo/DVR" ~> 1.0.0
github "Quick/Nimble" ~> 7.0.2
github "venmo/DVR" ~> 1.1.0

5 changes: 2 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github "Hearst-DD/ObjectMapper" "2.2.8"
github "JensRavens/Interstellar" "2.1.0"
github "Quick/Nimble" "v7.0.1"
github "venmo/DVR" "v1.0.1"
github "Quick/Nimble" "v7.0.2"
github "venmo/DVR" "v1.1.0"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Nimble
Submodule Nimble updated 70 files
+4 −4 .swiftlint.yml
+6 −0 .travis.yml
+2 −1 Nimble.podspec
+27 −15 Nimble.xcodeproj/project.pbxproj
+3 −1 Nimble.xcodeproj/xcshareddata/xcschemes/Nimble-iOS.xcscheme
+3 −1 Nimble.xcodeproj/xcshareddata/xcschemes/Nimble-macOS.xcscheme
+3 −1 Nimble.xcodeproj/xcshareddata/xcschemes/Nimble-tvOS.xcscheme
+20 −16 README.md
+1 −1 Sources/Lib/CwlPreconditionTesting/CwlCatchExceptionSupport/CwlCatchException.m
+2 −1 Sources/Lib/CwlPreconditionTesting/CwlCatchExceptionSupport/include/CwlCatchException.h
+21 −17 Sources/Nimble/Adapters/NMBExpectation.swift
+3 −1 Sources/Nimble/Adapters/NMBObjCMatcher.swift
+7 −2 Sources/Nimble/Adapters/NimbleXCTestHandler.swift
+1 −1 Sources/Nimble/Adapters/NonObjectiveC/ExceptionCapture.swift
+23 −5 Sources/Nimble/DSL+Wait.swift
+1 −1 Sources/Nimble/DSL.swift
+1 −0 Sources/Nimble/Expectation.swift
+2 −1 Sources/Nimble/ExpectationMessage.swift
+11 −2 Sources/Nimble/Expression.swift
+3 −2 Sources/Nimble/Matchers/AllPass.swift
+13 −3 Sources/Nimble/Matchers/AsyncMatcherWrapper.swift
+2 −2 Sources/Nimble/Matchers/BeAKindOf.swift
+3 −3 Sources/Nimble/Matchers/BeAnInstanceOf.swift
+6 −6 Sources/Nimble/Matchers/BeCloseTo.swift
+7 −4 Sources/Nimble/Matchers/BeEmpty.swift
+4 −3 Sources/Nimble/Matchers/BeGreaterThan.swift
+2 −2 Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift
+2 −2 Sources/Nimble/Matchers/BeIdenticalTo.swift
+2 −2 Sources/Nimble/Matchers/BeLessThan.swift
+2 −2 Sources/Nimble/Matchers/BeLessThanOrEqual.swift
+5 −5 Sources/Nimble/Matchers/BeLogical.swift
+2 −2 Sources/Nimble/Matchers/BeNil.swift
+2 −2 Sources/Nimble/Matchers/BeginWith.swift
+3 −2 Sources/Nimble/Matchers/Contain.swift
+3 −2 Sources/Nimble/Matchers/ContainElementSatisfying.swift
+2 −2 Sources/Nimble/Matchers/EndWith.swift
+5 −5 Sources/Nimble/Matchers/Equal.swift
+4 −2 Sources/Nimble/Matchers/HaveCount.swift
+2 −2 Sources/Nimble/Matchers/Match.swift
+6 −1 Sources/Nimble/Matchers/MatchError.swift
+8 −24 Sources/Nimble/Matchers/MatcherProtocols.swift
+3 −5 Sources/Nimble/Matchers/PostNotification.swift
+1 −1 Sources/Nimble/Matchers/Predicate.swift
+25 −10 Sources/Nimble/Matchers/RaisesException.swift
+4 −2 Sources/Nimble/Matchers/SatisfyAnyOf.swift
+3 −2 Sources/Nimble/Matchers/ThrowAssertion.swift
+21 −3 Sources/Nimble/Matchers/ThrowError.swift
+23 −6 Sources/Nimble/Utils/Async.swift
+1 −1 Sources/Nimble/Utils/Stringers.swift
+3 −3 Sources/NimbleObjectiveC/DSL.h
+6 −6 Sources/NimbleObjectiveC/DSL.m
+2 −2 Sources/NimbleObjectiveC/NMBExceptionCapture.h
+3 −3 Sources/NimbleObjectiveC/NMBExceptionCapture.m
+2 −0 Tests/.swiftlint.yml
+25 −0 Tests/NimbleTests/AsynchronousTest.swift
+1 −1 Tests/NimbleTests/Helpers/XCTestCaseProvider.swift
+5 −3 Tests/NimbleTests/Helpers/utils.swift
+5 −5 Tests/NimbleTests/Matchers/BeAKindOfTest.swift
+4 −4 Tests/NimbleTests/Matchers/BeAnInstanceOfTest.swift
+2 −2 Tests/NimbleTests/Matchers/BeEmptyTest.swift
+1 −1 Tests/NimbleTests/Matchers/BeGreaterThanOrEqualToTest.swift
+1 −1 Tests/NimbleTests/Matchers/BeIdenticalToTest.swift
+1 −1 Tests/NimbleTests/Matchers/BeLessThanOrEqualToTest.swift
+1 −1 Tests/NimbleTests/Matchers/BeginWithTest.swift
+1 −1 Tests/NimbleTests/Matchers/ContainTest.swift
+1 −1 Tests/NimbleTests/Matchers/EndWithTest.swift
+2 −2 Tests/NimbleTests/Matchers/EqualTest.swift
+1 −1 Tests/NimbleTests/Matchers/PostNotificationTest.swift
+1 −1 Tests/NimbleTests/Matchers/RaisesExceptionTest.swift
+1 −1 Tests/NimbleTests/Matchers/ThrowAssertionTest.swift
1 change: 0 additions & 1 deletion Carthage/Checkouts/ObjectMapper
Submodule ObjectMapper deleted from 409163
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=0.9.3
CONTENTFUL_SDK_VERSION=0.10.0
Original file line number Diff line number Diff line change
@@ -1,62 +1,68 @@
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
/*: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.*/
//: ![](contentful-logo-white.png)
//: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.
/*:
![](contentful-logo-white.png)

/*: Contentful is an API-first CMS which helps developers deliver content to their apps with API calls, while offering content editors a familiar-looking [web app](https://app.contentful.com) for creating and managing content. This Playground shows how to make API calls to fetch content from Contentful's Content Delivery API (CDA) via the Swift SDK. It also explains what the API response looks like after it has been mapped to native Swift types, and suggests some relevant next steps. */
Contentful is an API-first CMS which helps developers deliver content to their apps with API calls, while offering content editors a familiar-looking [web app](https://app.contentful.com) for creating and managing content. This Playground shows how to make API calls to fetch content from Contentful's Content Delivery API (CDA) via the Swift SDK. It also explains what the API response looks like after it has been mapped to native Swift types, and suggests some relevant next steps.
*/
import Contentful
import Interstellar
/*: This is the space identifer. A space is like a project folder in Contentful terms. */
//: This is the space identifer. A space is like a project folder in Contentful terms.
let spaceId = "developer_bookshelf"
/*: This is the access token for this space. You can find both the space id and your CDA access token in the Contentful web app. */
//: This is the access token for this space. You can find both the space id and your CDA access token in the Contentful web app.
let accessToken = "0b7f6x59a0"
/*: ## Make the first request
Create a `Client` object using those credentials, this type is used to make all API requests. */
/*:
## Make the first request
Create a `Client` object using those credentials, this type is used to make all API requests.
*/
let client = Client(spaceId: spaceId, accessToken: accessToken)

/*: To request an entry with the specified ID: */
//: To request an entry with the specified ID:
client.fetchEntry(id: "5PeGS2SoZGSa4GuiQsigQu") { (result: Result<Entry>) in
switch result {
case .error(let error):
print("Oh no an error: \(error)!")

case .success(let entry):
/*: All resources in Contentful have a variety of read-only, system-managed properties, stored in the “sys” property. This includes things like when the resource was last updated and how many revisions have been published. */
//: All resources in Contentful have a variety of read-only, system-managed properties, stored in the “sys” property. This includes things like when the resource was last updated and how many revisions have been published.
print("The system properties for this entry are: '\(entry.sys)'")

/*: Entries contain a collection of fields, key-value pairs containing the content created in the web app. */
//: Entries contain a collection of fields, key-value pairs containing the content created in the web app.
print("The fields for this entry are: '\(entry.fields)'")
/*: ## Custom content structures
/*:
## Custom content structures

Contentful is built on the principle of structured content: a set of key-value pairs is not a great interface to program against if the keys and data types are always changing!

Just the same way you can set up any content structure in a MySQL database, you can set up a custom content structure in Contentful, too. There are no presets, templates, or anything of the kind – you can (and should) set everything up depending on the logic of your project.

This structure is maintained by content types, which define what data fields are present in a content entry. */
This structure is maintained by content types, which define what data fields are present in a content entry.
*/
guard let contentTypeId = entry.sys.contentTypeId else { return }
print("The content type for this entry is: '\(contentTypeId)'")

}
}
/*: This is a link to the content type which defines the structure of "book" entries. Being API-first, we can of course fetch this content type from the API and inspect it to understand what it contains. */
//: This is a link to the content type which defines the structure of "book" entries. Being API-first, we can of course fetch this content type from the API and inspect it to understand what it contains.
client.fetchContentType(id: "book") { (result: Result<ContentType>) in
switch result {
case .error(let error):
print("Oh no an error: \(error)!")

case .success(let contentType):
/*: Like entries, content types have a set of read-only system managed properties. */
//: Like entries, content types have a set of read-only system managed properties.
print("The system properties for this content type are '\(contentType.sys)'")

/*: A content type is a container for a collection of fields: */
//: A content type is a container for a collection of fields:
guard let field = contentType.fields.first else { return }
/*: The field ID is used in API responses. */
//: The field ID is used in API responses.
print("The first field for the 'book' content type has an internal identifier: '\(field.id)'")
/*: The field name is shown to editors when changing content in the web app. */
//: The field name is shown to editors when changing content in the web app.
print("The name of the field when editing entries of this content type at app.contentful.com is: '\(field.name)'")
/*: Indicates whether the content in this field can be translated to another language. */
//: Indicates whether the content in this field can be translated to another language.
print("This field is localized, true or false? '\(field.localized)'")
/*: The field type determines what can be stored in the field, and how it is queried. See the [doc on Contentful concepts](https://www.contentful.com/developers/docs/concepts/data-model/) for more information on field types */
//: The field type determines what can be stored in the field, and how it is queried. See the [doc on Contentful concepts](https://www.contentful.com/developers/docs/concepts/data-model/) for more information on field types
print("The type of data that can be stored in this field is '\(field.type)'")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*: [Previous](@previous) */
//: [Previous](@previous)
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
import Contentful
import Interstellar
/*: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.*/
/*: Sometimes, it is more convenient to work directly with native Swift classes which define the model in our application and use methods which give us back our own types as opposed to `Entry`s. In order to do this, we will define our types to conform to the `EntryModellable` protocol. */
//: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.
//: Sometimes, it is more convenient to work directly with native Swift classes which define the model in our application and use methods which give us back our own types as opposed to `Entry`s. In order to do this, we will define our types to conform to the `EntryModellable` protocol. */
class Cat: EntryModellable {

let name: String?
Expand Down Expand Up @@ -46,7 +46,7 @@ let client = Client(spaceId: "cfexampleapi",
let query = QueryOn<Cat>(where: "sys.id", .equals("nyancat"))
client.fetchMappedEntries(with: query).next { (mappedCatsArrayResponse: MappedArrayResponse<Cat>) in
guard let nyanCat = mappedCatsArrayResponse.items.first else { return }
/*: We can see that we have directly received a `Cat` via the SDK and we can access properties directly without the indirection of the `fields` dictionary that we would normally access data through on `Entry`. */
//: We can see that we have directly received a `Cat` via the SDK and we can access properties directly without the indirection of the `fields` dictionary that we would normally access data through on `Entry`. */
guard let name = nyanCat.name else { return }
print("The first cat's name is '\(name)'")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*:
[Previous](@previous)

Before running this, please build the "Contentful_macOS" scheme to build the SDK. The following is some Playground specific setup. */
//: [Previous](@previous)
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
import Contentful
import Interstellar

//: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.
//: As a first step, you have to create a client object again.
let client = Client(spaceId: "cfexampleapi", accessToken: "b4c0n73n7fu1")
/*:
Expand Down Expand Up @@ -77,16 +76,15 @@ client.fetchEntries(with: query).next {
}

//: If you have location-enabled content, you can use it for searching as well. Sort results by distance:
import CoreLocation
query = Query(onContentTypeFor: "1t9IbcfdCk6m04uISSsaIK").where("fields.center", .isNear(CLLocationCoordinate2D(latitude: 38, longitude: -122)))
query = Query(onContentTypeFor: "1t9IbcfdCk6m04uISSsaIK").where("fields.center", .isNear(Location(latitude: 38, longitude: -122)))
client.fetchEntries(with: query).next {
let names = $0.items.flatMap { $0.fields.string(at: "name") }
print(names)
}

//: Or retrieve all resources in a bounding rectangle:
let bottomLeft = CLLocationCoordinate2D(latitude: 40, longitude: -124)
let topRight = CLLocationCoordinate2D(latitude: 36, longitude: -121)
let bottomLeft = Location(latitude: 40, longitude: -124)
let topRight = Location(latitude: 36, longitude: -121)
let boundingBox = Bounds.box(bottomLeft: bottomLeft, topRight: topRight)
query = Query(onContentTypeFor: "1t9IbcfdCk6m04uISSsaIK").where("fields.center", .isWithin(boundingBox))
client.fetchEntries(with: query).next {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*: [Previous](@previous) */
//: [Previous](@previous)
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
import Contentful
import Interstellar
import AppKit

/*: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.*/
//: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.
//: We again create an instance of `Client` connected to the space of interest.
let client = Client(spaceId: "cfexampleapi", accessToken: "b4c0n73n7fu1")
//: Assets represent any kind of media you are storing in Contentful. The API is similar to fetching entries.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*: [Previous](@previous) */
//: [Previous](@previous)
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
import Contentful
import Interstellar

/*: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.*/
//: In order to execute this playground, please build the "Contentful_macOS" scheme to build the SDK.
//: As a first step, we again create an instance of `Client` connected to the space of interest.
let client = Client(spaceId: "cfexampleapi", accessToken: "b4c0n73n7fu1")

Expand Down
1 change: 0 additions & 1 deletion Contentful.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Pod::Spec.new do |spec|
spec.watchos.deployment_target = '2.0'
spec.tvos.deployment_target = '9.0'

spec.dependency 'ObjectMapper', '~> 2.2'
spec.dependency 'Interstellar', '~> 2.1.0'
end

Expand Down
Loading

0 comments on commit 624c6f3

Please sign in to comment.