Skip to content
This repository has been archived by the owner on Dec 10, 2017. It is now read-only.

Commit

Permalink
Create Release for Swift 2.3
Browse files Browse the repository at this point in the history
- Remove #if(swift) checks
- Remove `Package.swift`. SwiftPM support is dropped.
- Add SWIFT_VERSION = 2.3, aka., "Use Legacy Swift Version" set to Yes
  • Loading branch information
bhargavg committed Sep 15, 2016
1 parent 86ceae1 commit e4827bc
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 203 deletions.
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
language: objective-c
osx_image: xcode7.3
before_install:
- brew update
- brew uninstall xctool && brew install --HEAD xctool
osx_image: xcode8
env:
matrix:
- TEST_TYPE=iOS
- TEST_TYPE=macOS
script:
- xctool test -project Banana.xcodeproj -scheme 'Banana-iOS' -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
- xctool test -project Banana.xcodeproj -scheme 'Banana-Mac' -sdk macosx ONLY_ACTIVE_ARCH=NO
- set -o pipefail
- if [ "$TEST_TYPE" = "iOS" ]; then
xcodebuild test -verbose -workspace Banana.xcworkspace -scheme Banana-iOS -sdk iphonesimulator -destination "platform=iOS Simulator,OS=10.0,name=iPhone 7" ONLY_ACTIVE_ARCH=NO;
elif [ "$TEST_TYPE" = "macOS" ]; then
xcodebuild test -verbose -workspace Banana.xcworkspace -scheme Banana-Mac -sdk macosx;
fi
18 changes: 8 additions & 10 deletions Banana.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
7C76D4331CBE594A00363423 /* Banana.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CC8CCA01CBC107200896C9C /* Banana.framework */; };
7CA20E9C1CBCFB8F0098EC8E /* Banana.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CA20E9B1CBCFB8F0098EC8E /* Banana.h */; settings = {ATTRIBUTES = (Public, ); }; };
7CA2DF3B1CBFB3FA00E91622 /* Banana.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA2DF3A1CBFB3FA00E91622 /* Banana.swift */; };
7CC16FCD1CE9D7FE00AFA40A /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CC16FCC1CE9D7FE00AFA40A /* Utils.swift */; };
7CC16FCE1CE9D7FE00AFA40A /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CC16FCC1CE9D7FE00AFA40A /* Utils.swift */; };
7CC8CCB91CBC176600896C9C /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CC8CCB61CBC176600896C9C /* Types.swift */; };
7CC8CCBA1CBC176600896C9C /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CC8CCB71CBC176600896C9C /* Operators.swift */; };
7CC8CCBB1CBC176600896C9C /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CC8CCB81CBC176600896C9C /* Functions.swift */; };
Expand Down Expand Up @@ -57,7 +55,6 @@
7C76D42E1CBE594A00363423 /* Banana-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Banana-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
7CA20E9B1CBCFB8F0098EC8E /* Banana.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Banana.h; path = Support/Banana.h; sourceTree = SOURCE_ROOT; };
7CA2DF3A1CBFB3FA00E91622 /* Banana.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Banana.swift; path = Sources/Banana.swift; sourceTree = "<group>"; };
7CC16FCC1CE9D7FE00AFA40A /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Utils.swift; path = Sources/Utils.swift; sourceTree = "<group>"; };
7CC8CCA01CBC107200896C9C /* Banana.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Banana.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7CC8CCA51CBC107200896C9C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info.plist; path = Support/Info.plist; sourceTree = "<group>"; };
7CC8CCB61CBC176600896C9C /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Types.swift; path = Sources/Types.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -161,7 +158,6 @@
7CC8CCB71CBC176600896C9C /* Operators.swift */,
7CC8CCB81CBC176600896C9C /* Functions.swift */,
7CA2DF3A1CBFB3FA00E91622 /* Banana.swift */,
7CC16FCC1CE9D7FE00AFA40A /* Utils.swift */,
);
name = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -273,10 +269,12 @@
7C76D42D1CBE594A00363423 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
ProvisioningStyle = Manual;
};
7CC8CC9F1CBC107200896C9C = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
ProvisioningStyle = Manual;
};
7CE5B6BF1CC69CDE009D355F = {
CreatedOnToolsVersion = 7.3;
Expand Down Expand Up @@ -358,7 +356,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7CC16FCD1CE9D7FE00AFA40A /* Utils.swift in Sources */,
7CA2DF3B1CBFB3FA00E91622 /* Banana.swift in Sources */,
7CC8CCB91CBC176600896C9C /* Types.swift in Sources */,
7CC8CCBA1CBC176600896C9C /* Operators.swift in Sources */,
Expand All @@ -370,7 +367,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7CC16FCE1CE9D7FE00AFA40A /* Utils.swift in Sources */,
7CE5B6D71CC69DBD009D355F /* Types.swift in Sources */,
7CE5B6D81CC69DBD009D355F /* Operators.swift in Sources */,
7CE5B6D91CC69DBD009D355F /* Functions.swift in Sources */,
Expand Down Expand Up @@ -408,22 +404,22 @@
7C76D4361CBE594A00363423 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.bhargavg.BananaTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
};
name = Debug;
};
7C76D4371CBE594A00363423 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.bhargavg.BananaTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
};
name = Release;
};
Expand Down Expand Up @@ -470,6 +466,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -511,6 +508,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 2.3;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -522,6 +520,7 @@
isa = XCBuildConfiguration;
buildSettings = {
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -532,14 +531,14 @@
PRODUCT_BUNDLE_IDENTIFIER = com.bhargavg.Banana;
PRODUCT_NAME = Banana;
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
};
name = Debug;
};
7CC8CCAA1CBC107200896C9C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -550,7 +549,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.bhargavg.Banana;
PRODUCT_NAME = Banana;
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
};
name = Release;
};
Expand Down
6 changes: 0 additions & 6 deletions Package.swift

This file was deleted.

17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

Banana is a library that allows conversion of parsed JSON into typed objects.

Why another JSON mapper right?
Why another JSON mapper right?

The idea behind creating Banana is to show that JSON mapping is not as complicated.

Simplicity and no-black-magic are the key design principles. The name Banana is chosen to signify this.
Simplicity and no-black-magic are the key design principles. The name Banana is chosen to signify this.

If you are interested in how this libary has evolved, please read [this blog post series](http://bhargavg.com/swift/2016/03/29/functional-json-parsing-in-swift.html)

Expand All @@ -16,13 +16,16 @@ If you are interested in how this libary has evolved, please read [this blog pos
- Handles Optionals
- Supports Keypaths

## Installation
## Understanding Version Numbers
`Banana` supports both legacy Swift 2.3 and latest Swift 3.0. To achieve this, the following release strategy is followed:

Only `Carthage` is supported as of now. Adding `CocoaPods` support is in pipeline.
* Odd number versions for `Swift 2.3` releases
* Even number versions for `Swift 3` releases

### [Carthage]
## Installation
Only `Carthage` is supported as of now.

[Carthage]: https://github.com/Carthage/Carthage
### [Carthage](https://github.com/Carthage/Carthage)

To add this library to your project, just add the following to your `Cartfile`

Expand Down Expand Up @@ -80,7 +83,7 @@ print(jsonString)
## Todo:
- [x] Carthage Support
- [ ] CocoaPods Support
- [x] SwiftPM Support
- [x] ~~SwiftPM Support~~ (Only supported with Swift-3 branch, ie., `master` branch)
- [x] OS X, iOS Targets
- [ ] Watch, TvOS Targets

Expand Down
48 changes: 0 additions & 48 deletions Sources/Banana.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ public struct Banana {
- returns: An object of type T. This T is determined by the receiver. It tries to cast the AnyObject from `JSONObjectWithData` to a type that receiver expects.
- throws: Throws `BananaError` if file couldn't be loaded or the value cannot be casted
*/
#if swift(>=3.0)
public static func load<T>(file: String, fileExtension: String = "json", bundle: Bundle = Bundle.main, options: JSONSerialization.ReadingOptions = []) throws -> T {
guard let path = bundle.pathForResource(file, ofType: fileExtension),
let data = NSData(contentsOfFile: path) else {
throw BananaError<String, String>.Custom("Couldn't load JSON file: \(file)")
}

return try load(data: data, options: options)
}
#else
public static func load<T>(file file: String, fileExtension: String = "json", bundle: NSBundle = NSBundle.mainBundle(), options: NSJSONReadingOptions = []) throws -> T {
guard let path = bundle.pathForResource(file, ofType: fileExtension),
let data = NSData(contentsOfFile: path) else {
Expand All @@ -33,7 +23,6 @@ public struct Banana {

return try load(data: data, options: options)
}
#endif

/**
Parse the given data into a JSON object.
Expand All @@ -47,15 +36,9 @@ public struct Banana {
- returns: An object of type T. This T is determined by the receiver. It tries to cast the AnyObject from `JSONObjectWithData` to a type that receiver expects.
- throws: Throws `BananaError` if JSON couldn't be parsed, or, the value cannot be casted
*/
#if swift(>=3.0)
public static func load<T>(data: NSData, options: JSONSerialization.ReadingOptions = []) throws -> T {
return try JSONSerialization.jsonObject(with: data as Data, options: options) <~~ get
}
#else
public static func load<T>(data data: NSData, options: NSJSONReadingOptions = []) throws -> T {
return try NSJSONSerialization.JSONObjectWithData(data, options: options) <~~ get
}
#endif

/**
Encode the given `jsonObject` into NSData
Expand All @@ -72,20 +55,11 @@ public struct Banana {

- throws: `BananaError` if the value cannot be encoded
*/
#if swift(>=3.0)
public static func dump(options: JSONSerialization.WritingOptions) -> (jsonObject: AnyObject) throws -> NSData {
return { jsonObject in
return try Banana.dump(JSONObject: jsonObject, options: options)
}
}
#else
public static func dump(options options: NSJSONWritingOptions) -> (jsonObject: AnyObject) throws -> NSData {
return { jsonObject in
return try Banana.dump(JSONObject: jsonObject, options: options)
}
}
#endif


/**
Encode the given `jsonObject` into NSData
Expand All @@ -99,23 +73,13 @@ public struct Banana {

- throws: `BananaError` if the value cannot be encoded
*/
#if swift(>=3.0)
public static func dump(JSONObject jsonObject: AnyObject, options: JSONSerialization.WritingOptions) throws -> NSData {
guard let jsonData = try? JSONSerialization.data(withJSONObject: jsonObject, options: options) else {
throw BananaError<String, String>.Custom("Couldn't convert JSON Object to NSData")
}

return jsonData
}
#else
public static func dump(JSONObject jsonObject: AnyObject, options: NSJSONWritingOptions) throws -> NSData {
guard let jsonData = try? NSJSONSerialization.dataWithJSONObject(jsonObject, options: options) else {
throw BananaError<String, String>.Custom("Couldn't convert JSON Object to NSData")
}

return jsonData
}
#endif


/**
Expand All @@ -133,17 +97,6 @@ public struct Banana {

- throws: `BananaError` if `NSString` object cannot be made
*/
#if swift(>=3.0)
public static func toString(encoding: String.Encoding) -> (data: NSData) throws -> NSString {
return { data in
guard let string = NSString(data: data as Data, encoding: encoding.rawValue) else {
throw BananaError<String, String>.Custom("Couldn't convert to NSString")
}

return string
}
}
#else
public static func toString(encoding encoding: NSStringEncoding) -> (data: NSData) throws -> NSString {
return { data in
guard let string = NSString(data: data, encoding: encoding) else {
Expand All @@ -153,5 +106,4 @@ public struct Banana {
return string
}
}
#endif
}
Loading

0 comments on commit e4827bc

Please sign in to comment.