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

Enable storing of asset metadata and fetching binary data #56

Merged
merged 6 commits into from
Apr 6, 2018
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_PERSISTENCE_VERSION=0.9.1
CONTENTFUL_PERSISTENCE_VERSION=0.10.0
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export CONTENTFUL_PERSISTENCE_VERSION=0.9.1
export CONTENTFUL_PERSISTENCE_VERSION=0.10.0
20 changes: 16 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,35 @@ 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
> - Assets that contained media files that were not images failed to deserialize the metadata about the file properly, see [contentful.swift #182](https://github.com/contentful/contentful.swift/pull/182)

> 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.8.x` Releases - [0.8.0](#080)
- `0.7.x` Releases - [0.7.0](#070)
- `0.6.x` Releases - [0.6.0](#060) | [0.6.1](#061) | [0.6.2](#062)
- `0.5.x` Releases - [0.5.0](#050)
- `0.4.x` Releases - [0.4.0](#040)

---

## [`0.10.0`](https://github.com/contentful/contentful-persistence.swift/releases/tag/0.10.0)
Released on 2018-04-05

#### Added
- **BREAKING:** Ability to store _all_ asset metadata in `AssetPersistable` has been added. Conforming to the new protocol contstraints is a breaking change and you should make sure to resync all data to ensure this metedata is stored properly.
- You can now use the `fetchData(for:with:)` method from contentful.swift on `AssetPersistable` instances

#### Changed
- **BREAKING:** The library is now upgraded to Swift 4.1 and Xcode 9.3

#### FIXED
- Assets that contained media files that were not images failed to deserialize the metadata about the file properly, see [contentful.swift #182](https://github.com/contentful/contentful.swift/pull/182)

---

Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "contentful/contentful.swift" "2.0.0-alpha2"
github "contentful/contentful.swift" "2.0.0-alpha3"

2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "AliSoftware/OHHTTPStubs" "6.1.0"
github "JensRavens/Interstellar" "2.1.0"
github "Quick/Nimble" "v7.0.3"
github "contentful/contentful.swift" "2.0.0-alpha2"
github "contentful/contentful.swift" "2.0.0-alpha3"
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_PERSISTENCE_VERSION=0.9.1
CONTENTFUL_PERSISTENCE_VERSION=0.10.0
6 changes: 5 additions & 1 deletion ContentfulPersistence.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Contentful GmbH";
TargetAttributes = {
A1A9FBE21CABE8EA00430734 = {
Expand Down Expand Up @@ -1184,12 +1184,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -1242,12 +1244,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion ContentfulPersistenceSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ Pod::Spec.new do |spec|
spec.watchos.deployment_target = '2.0'
spec.tvos.deployment_target = '9.0'

spec.dependency 'Contentful', '~> 2.0.0-alpha2'
spec.dependency 'Contentful', '~> 2.0.0-alpha3'
end

4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/contentful/contentful.swift",
"state": {
"branch": null,
"revision": "609cda82ae88c3dc8c459c8f411e4c7b80e9b42b",
"version": "2.0.0-alpha2"
"revision": "80c6c02bf0d5f2dfda32dfb837fd383ff3f25ffd",
"version": "2.0.0-alpha3"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
targets: ["ContentfulPersistence"])
],
dependencies: [
.package(url: "https://github.com/contentful/contentful.swift", .upToNextMinor(from: "2.0.0-alpha2"))
.package(url: "https://github.com/contentful/contentful.swift", .upToNextMinor(from: "2.0.0-alpha3"))
],
targets: [
.target(
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ platform :ios, '8.0'
use_frameworks!

target :MyApp do
pod 'ContentfulPersistenceSwift', '~> 0.9.1'
pod 'ContentfulPersistenceSwift', '~> 0.10.0'
end
```

Expand All @@ -123,7 +123,7 @@ end
You can also use [Carthage][6] for integration by adding the following to your `Cartfile`:

```
github "contentful/contentful.swift" ~> 0.9.1
github "contentful/contentful.swift" ~> 0.10.0
```

## Unit Tests
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContentfulPersistence/CoreDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class CoreDataStore: PersistenceStore {
public func fetchAll<T>(type: Any.Type, predicate: NSPredicate) throws -> [T] {
let request = try fetchRequest(for: type, predicate: predicate)
let items: [T] = try context.fetch(request) as! [T]
return items.flatMap { $0 as? T }
return items
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContentfulPersistence/DataCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NoDataCache: DataCacheProtocol {
fileprivate func itemsOf(_ types: [ContentSysPersistable.Type], identifier: String) -> EntryPersistable? {
let predicate = ContentfulPersistence.predicate(for: identifier)

let items: [EntryPersistable] = types.flatMap {
let items: [EntryPersistable] = types.compactMap {
if let result = try? store.fetchAll(type: $0, predicate: predicate) as [EntryPersistable] {
return result.first
}
Expand Down
28 changes: 22 additions & 6 deletions Sources/ContentfulPersistence/Persistable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public protocol ContentSysPersistable: class {
/// The unique identifier of the Resource.
var id: String { get set }

/// The code which represents which locale the Resource of interest contains data for.
var localeCode: String { get set }

/// The date representing the last time the Contentful Resource was updated.
var updatedAt: Date? { get set }

/// The date that the Contentful Resource was first created.
var createdAt: Date? { get set }

/// The code which represents which locale the Resource of interest contains data for.
var localeCode: String { get set }
}

/**
Expand All @@ -64,16 +64,32 @@ public protocol SyncSpacePersistable: class {
Conform to `AssetPersistable` protocol to enable mapping of your Contentful media Assets to
your `NSManagedObject` subclass.
*/
public protocol AssetPersistable: ContentSysPersistable, Media {
/// URL of the Asset.
var urlString: String? { get set }
public protocol AssetPersistable: ContentSysPersistable, AssetProtocol {

/// The title of the Asset.
var title: String? { get set }

/// The description of the asset. Named `assetDescription` to avoid clashing with `description`
/// property that all NSObject's have.
var assetDescription: String? { get set }

/// URL of the Asset.
var urlString: String? { get set }

/// The name of the underlying binary media file.
var fileName: String? { get set }

/// The type of the underlying binary media file: e.g. `image/png`
var fileType: String? { get set }

/// The byte size of the underlying binary media file.
var size: NSNumber? { get set }

/// If the binary media file is an image, this property describes the images width in pixels.
var width: NSNumber? { get set }

/// If the binary media file is an image, this property describes the images height in pixels.
var height: NSNumber? { get set }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public extension SynchronizationManager {
- Returns: The full string path for the underlying media file associated with the passed in `Asset` or `AssetPersistabl`.
Will return `nil` if no directory exists at your directory name, or if the `Media` does not have a valid `urlString` associated with it.
*/
public static func pathInBundle(for media: Media, inDirectoryNamed directory: String, in bundle: Bundle) -> String? {
public static func pathInBundle(for media: AssetProtocol, inDirectoryNamed directory: String, in bundle: Bundle) -> String? {
let fileName = SynchronizationManager.fileName(for: media)
return bundle.path(forResource: fileName, ofType: nil, inDirectory: directory)
}
Expand All @@ -89,7 +89,7 @@ public extension SynchronizationManager {
- Returns: The `Data` object for your media file. Will return `nil` if no directory exists at your directory name,
or if the `Media` does not have a `urlString` associated with it.
*/
public static func bundledData(for media: Media, inDirectoryNamed directory: String, in bundle: Bundle) -> Data? {
public static func bundledData(for media: AssetProtocol, inDirectoryNamed directory: String, in bundle: Bundle) -> Data? {
guard let path = pathInBundle(for: media, inDirectoryNamed: directory, in: bundle) else { return nil }
let data = FileManager.default.contents(atPath: path)
return data
Expand All @@ -102,7 +102,7 @@ public extension SynchronizationManager {
- Returns: A filename for the underlying media file. Will return `nil` if the Asset or AssetPersistable
does not have a `urlString` associated with it.
*/
public static func fileName(for media: Media) -> String? {
public static func fileName(for media: AssetProtocol) -> String? {
guard let urlString = media.urlString, let url = URL(string: urlString) else { return nil }
let pathExtension = url.pathExtension.isEmpty ? "data" : url.pathExtension
let fileName = "cache_" + media.id + "." + pathExtension
Expand All @@ -126,15 +126,3 @@ public extension SynchronizationManager {

}
}

/**
A simple protocol to bridge `Contentful.Asset` and `ContentfulPersistence.AssetPersistable` to enable
consistent local storage patterns.
*/
public protocol Media {

var id: String { get }
var urlString: String? { get }
}

extension Contentful.Asset: Media {}
Loading