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

Relese/v2.2.0 #30

Merged
merged 13 commits into from
Nov 15, 2019
Prev Previous commit
Next Next commit
PR naming fixes
  • Loading branch information
Truba committed Nov 15, 2019
commit eed6996a3315bd3f9211cd3a3ee01607d64f7acb
81 changes: 30 additions & 51 deletions Example/Japx/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="duV-sn-OWJ">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="duV-sn-OWJ">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -194,56 +195,34 @@
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" keyboardDismissMode="onDrag" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="sfS-kD-zsN">
<rect key="frame" x="0.0" y="50" width="343" height="553"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<mutableString key="text">{
"data": [
{
"id": "33",
"type": "time_off_request",
"attributes": {
"status": "approved",
"start_date": "2019-01-14",
"end_date": "2019-01-31"
},
"relationships": {
"user": {
"data": {
"id": "25",
"type": "user"
}
},
"policy": {
"data": [{
"id": "24",
"type": "time_off_policy"
}, {
"id": "25",
"type": "time_off_policy"
}]
}
}
}
],
"included": [
{
"id": "25",
"type": "user",
"attributes": {
"id": 20550,
"name": "user name",
"email": "[email protected]",
"avatar": "",
"avatar_url": null
}
}
],
"meta": {
"total_pages": 1,
"total_count": 1
<string key="text">{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
},
"links": {
"self": "url link"
"relationships": {
"author": {
"data": {"id": "42", "type": "people"}
}
}
}],
"included": [
{
"type": "people",
"id": "42",
"attributes": {
"name": "John",
"age": 80,
"gender": "male"
}
}
}</mutableString>
]
}</string>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
Expand Down Expand Up @@ -286,6 +265,6 @@
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="Vjg-iL-wIa"/>
<segue reference="l1x-NH-VqX"/>
</inferredMetricsTieBreakers>
</document>
2 changes: 1 addition & 1 deletion Japx.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It works by transfering Dictionary to Dictionary, so you can use Codable, Unbox,
s.platform = :ios, :osx
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.10'
s.swift_version = '5.1'
s.swift_version = '5.0'

s.default_subspec = 'Core'

Expand Down
9 changes: 4 additions & 5 deletions Japx/Classes/Core/Japx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public enum JapxError: Error {
case unableToConvertDataToJson(data: Any)
}

/// `JapxDecodingOptions` is a set of options affecting the decoding of JSON:API into JSON you requested from `Japx.Decoder`.
/// `JapxDecodingOptions` is a set of options affecting the decoding of JSON:API into JSON you request from `Japx.Decoder`.
public struct JapxDecodingOptions {
Truba marked this conversation as resolved.
Show resolved Hide resolved

/// Defines if a relationship that doesn't heve related object stored in `included`
/// shoud be parsed as a dictionary of only `type` and `id`.
/// If `false` ti will be parsed as `nil`.
/// If `false` it will be parsed as `nil`.
///
/// Defaults to false.
///
Expand All @@ -58,7 +58,7 @@ public extension JapxDecodingOptions {
/// `JapxEncodingOptions` is a set of options affecting the encoding of JSON into JSON:API you requested from `Japx.Encoder`.
public struct JapxEncodingOptions {
Truba marked this conversation as resolved.
Show resolved Hide resolved

/// Common namespace inclued all attribute names, relationship names, `type` and `id`.
/// Common namespace includes all attribute names, relationship names, `type` and `id`.
/// If enabled it will include keyword `meta` into common namepace, expecit the not to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what did you say here after into common namepace, (typo namepace -> namespace), so please reformulate. I'm not sure if you are trying to say that client should not expect to have meta as an attribute or relationship name or something else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, please check if it look ok now?

/// have `mata` as an attribute or renationship name.
/// It will then encode meta on the same level as `attributes` and `relationships`
Expand Down Expand Up @@ -338,13 +338,13 @@ private extension Japx.Decoder {

let relationshipsReferences = object.asDictionary(from: Consts.APIKeys.relationships) ?? Parameters()

//Force cast here is ok since it is taken from include list string

let extractRelationship = resolveRelationship(
from: allObjects,
parseNotIncludedRelationships: options.parseNotIncludedRelationships
)

//Force cast here is ok since it is taken from include list string
let relationships = try paramsDict.allKeys.map({ $0 as! String }).reduce(into: Parameters(), { (result, relationshipsKey) in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let relationships = try paramsDict.allKeys.map({ $0 as! String }).reduce(into: Parameters(), { (result, relationshipsKey) in
let relationships = try paramsDict.allKeys.compactMap { $0 as? String }.reduce(into: Parameters(), { (result, relationshipsKey) in

Copy link
Member Author

@Truba Truba Nov 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one ⬆️ :)
I wouldn't leave it like this in my usual code, but I'm reclined on leaving it here as is. Trying to do every little thing (that doesn't include writing code in C) to try to boost CPU performance.
What do you think?

guard let relationship = relationshipsReferences.asDictionary(from: relationshipsKey) else { return }
guard let otherObjectsData = try relationship.array(from: Consts.APIKeys.data) else {
Expand Down Expand Up @@ -438,7 +438,6 @@ private extension Japx.Decoder {

// In case that relationship object is not in objects list, then check should
// we fallback to relationship key itself

static func resolveRelationship(
from objects: [TypeIdPair: Parameters],
parseNotIncludedRelationships: Bool
Expand Down
18 changes: 5 additions & 13 deletions Japx/Classes/ObjC/JapxObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import Foundation

/// Objc bride for `JapxDecodingOptions`
@objc
/// ObjC bride for `JapxDecodingOptions`
@objcMembers
public class JAPXDecodingOptions: NSObject {

// MARK: - Private options reference
Expand All @@ -17,15 +17,14 @@ public class JAPXDecodingOptions: NSObject {

// MARK: - Propery forwarding

/// Objc bridge for [`JAPXDecodingOptions.parseNotIncludedRelationships`](x-source-tag:https://parseNotIncludedRelationships)
@objc
/// ObjC bridge for [`JAPXDecodingOptions.parseNotIncludedRelationships`](x-source-tag:https://parseNotIncludedRelationships)
public var parseNotIncludedRelationships: Bool {
get { options.parseNotIncludedRelationships }
set { options.parseNotIncludedRelationships = newValue }
}
}

@objc
@objcMembers
@available(swift, obsoleted: 1.0)
public class JAPXDecoder: NSObject {

Expand All @@ -44,7 +43,6 @@ public class JAPXDecoder: NSObject {
/// - parameter options: The options specifying how `JAPXDecoder` should decode JSON:API into JSON.
///
/// - returns: JSON object.
@objc
public static func jsonObject(withJSONAPIObject object: Parameters, includeList: String?, options: JAPXDecodingOptions) throws -> Parameters {
do {
return try Japx.Decoder.jsonObject(withJSONAPIObject: object, includeList: includeList, options: options.options)
Expand All @@ -60,7 +58,6 @@ public class JAPXDecoder: NSObject {
/// - parameter options: The options specifying how `JAPXDecoder` should decode JSON:API into JSON.
///
/// - returns: JSON object as Data.
@objc
public static func data(withJSONAPIObject object: Parameters, includeList: String?, options: JAPXDecodingOptions) throws -> Data {
do {
return try Japx.Decoder.data(withJSONAPIObject: object, includeList: includeList, options: options.options)
Expand All @@ -76,7 +73,6 @@ public class JAPXDecoder: NSObject {
/// - parameter options: The options specifying how `JAPXDecoder` should decode JSON:API into JSON.
///
/// - returns: JSON object.
@objc
public static func jsonObject(withData data: Data, includeList: String?, options: JAPXDecodingOptions) throws -> Parameters {
do {
return try Japx.Decoder.jsonObject(with: data, includeList: includeList, options: options.options)
Expand All @@ -92,7 +88,6 @@ public class JAPXDecoder: NSObject {
/// - parameter options: The options specifying how `JAPXDecoder` should decode JSON:API into JSON.
///
/// - returns: JSON object as Data.
@objc
public static func data(withData data: Data, includeList: String?, options: JAPXDecodingOptions) throws -> Data {
do {
return try Japx.Decoder.data(with: data, includeList: includeList, options: options.options)
Expand All @@ -105,7 +100,7 @@ public class JAPXDecoder: NSObject {
// MARK: - Encoder

/// Defines a list of methods for converting simple JSON objects to JSON:API object.
@objc
@objcMembers
@available(swift, obsoleted: 1.0)
public class JAPXEncoder: NSObject {

Expand All @@ -123,7 +118,6 @@ public class JAPXEncoder: NSObject {
/// - parameter additionalParams: Additional [String: Any] to add with `data` to JSON:API object.
///
/// - returns: JSON:API object.
@objc
public static func encode(data: Data, additionalParams: Parameters?) throws -> Parameters {
do {
return try Japx.Encoder.encode(data: data, additionalParams: additionalParams)
Expand All @@ -138,7 +132,6 @@ public class JAPXEncoder: NSObject {
/// - parameter additionalParams: Additional [String: Any] to add with `data` to JSON:API object.
///
/// - returns: JSON:API object.
@objc
public static func encode(jsonParameter: Parameters, additionalParams: Parameters?) throws -> Parameters {
do {
return try Japx.Encoder.encode(json: jsonParameter, additionalParams: additionalParams)
Expand All @@ -153,7 +146,6 @@ public class JAPXEncoder: NSObject {
/// - parameter additionalParams: Additional [String: Any] to add with `data` to JSON:API object.
///
/// - returns: JSON:API object.
@objc
public static func encode(jsonParameters: [Parameters], additionalParams: Parameters?) throws -> Parameters {
do {
return try Japx.Encoder.encode(json: jsonParameters, additionalParams: additionalParams)
Expand Down