Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Martin committed Mar 23, 2022
2 parents 3cf6943 + f652218 commit af5c001
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Harmony.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Harmony'
s.version = '2.0.1'
s.version = '2.0.2'
s.summary = 'Mobile Jazz Harmony'
s.swift_version = '5'

Expand Down
4 changes: 2 additions & 2 deletions HarmonyTesting.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'HarmonyTesting'
s.version = '2.0.1'
s.version = '2.0.2'
s.summary = 'Mobile Jazz Harmony Testing'
s.swift_version = '5'

Expand All @@ -33,6 +33,6 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '12.0'

s.source_files = 'Sources/HarmonyTesting/**/*'
s.dependency 'Harmony', '2.0.1'
s.dependency 'Harmony', '2.0.2'

end
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ Harmony is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod 'Harmony', '~> 2.0.1'
pod 'Harmony', '~> 2.0.2'
```
For unit test, you can use the following pod:
```ruby
pod 'HarmonyTesting', '~> 2.0.1'
pod 'HarmonyTesting', '~> 2.0.2'
```

### Carthage

```ruby
github "mobilejazz/harmony-swift" "2.0.1"
github "mobilejazz/harmony-swift" "2.0.2"
```

Resolve dependencies `carthage update --use-xcframeworks --platform iOS` and add `Harmony.xcframework` to your project. For unit test, add `HarmonyTesting.xcframework` in your build phase of your testing target.
Expand All @@ -57,7 +57,7 @@ Resolve dependencies `carthage update --use-xcframeworks --platform iOS` and add

```ruby
dependencies: [
.package(url: "https://github.com/mobilejazz/harmony-swift", .upToNextMajor(from: "2.0.1"))
.package(url: "https://github.com/mobilejazz/harmony-swift", .upToNextMajor(from: "2.0.2"))
]
```
This package includes two libraries: `Harmony` and `HarmonyTesting`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public class FileSystemStorageDataSource : GetDataSource, PutDataSource, DeleteD
throw CoreError.NotFound("Data not found at path: \(url.path)")
}
// Attempting to unarchive in case it was an array
if let datas = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, NSData.self], from: data) as? [Data] {
// if let datas = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, NSData.self], from: data) as? [Data] {
if let datas = NSKeyedUnarchiver.unarchiveObject(with: data) as? [Data] {
// it was an array!
array.append(contentsOf: datas)
} else {
Expand All @@ -134,7 +135,8 @@ public class FileSystemStorageDataSource : GetDataSource, PutDataSource, DeleteD
guard let data = fileManager.contents(atPath: path) else {
return Future(CoreError.NotFound("Data not found at path: \(path)"))
}
guard let array = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, NSData.self], from: data) as? [Data] else {
// guard let array = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, NSData.self], from: data) as? [Data] else {
guard let array = NSKeyedUnarchiver.unarchiveObject(with: data) as? [Data] else {
return Future(CoreError.NotFound("Data not found at path: \(path)"))
}
return Future(array)
Expand Down Expand Up @@ -185,7 +187,8 @@ public class FileSystemStorageDataSource : GetDataSource, PutDataSource, DeleteD
if fileManager.fileExists(atPath: folderURL.path) == false {
try fileManager.createDirectory(atPath: folderURL.path, withIntermediateDirectories: true, attributes: nil)
}
let data = try NSKeyedArchiver.archivedData(withRootObject: array, requiringSecureCoding: false)
// let data = try NSKeyedArchiver.archivedData(withRootObject: array, requiringSecureCoding: false)
let data = NSKeyedArchiver.archivedData(withRootObject: array)
try data.write(to: fileURL, options: writingOptions)
r.set(array)
}
Expand Down
8 changes: 5 additions & 3 deletions Sources/Harmony/Data/Mapper/Mapper+NSCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import Foundation

public class NSCodingToDataMapper <T:NSCoding> : Mapper <T, Data> {
public override func map(_ from: T) -> Data {
return try! NSKeyedArchiver.archivedData(withRootObject: from, requiringSecureCoding: false)
// return try! NSKeyedArchiver.archivedData(withRootObject: from, requiringSecureCoding: false)
return NSKeyedArchiver.archivedData(withRootObject: from)
}
}

public class DataToNSCodingMapper <T:NSCoding> : Mapper <Data, T> where T:NSObject {
public class DataToNSCodingMapper <T:NSCoding> : Mapper <Data, T> { // where T:NSObject {
public override func map(_ from: Data) -> T {
return try! NSKeyedUnarchiver.unarchivedObject(ofClass: T.self, from: from)!
// return try! NSKeyedUnarchiver.unarchivedObject(ofClass: T.self, from: from)!
return NSKeyedUnarchiver.unarchiveObject(with: from) as! T
}
}
11 changes: 7 additions & 4 deletions Sources/Harmony/Security/KeychainService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ public extension KeychainService {
/// - Returns: The NSCoding conforming type stored in the keychain or nil.
func get<T>(_ key: String) -> T? where T: NSCoding, T: NSObject {
if let data : Data = get(key) {
if let value = try? NSKeyedUnarchiver.unarchivedObject(ofClass: T.self, from: data) {
return value
// if let value = try? NSKeyedUnarchiver.unarchivedObject(ofClass: T.self, from: data) {
// return value
if let value = NSKeyedUnarchiver.unarchiveObject(with: data) {
return (value as! T)
} else {
return nil
}
Expand All @@ -173,8 +175,9 @@ public extension KeychainService {
/// - key: The key.
/// - Returns: The operation result.
@discardableResult
func set<T>(_ value: T, forKey key: String) throws -> Result where T: NSCoding {
let data = try NSKeyedArchiver.archivedData(withRootObject: value, requiringSecureCoding: false)
func set<T>(_ value: T, forKey key: String) throws -> Result { // where T: NSCoding {
// let data = try NSKeyedArchiver.archivedData(withRootObject: value, requiringSecureCoding: false)
let data = NSKeyedArchiver.archivedData(withRootObject: value)
return set(data, forKey: key)
}
}

0 comments on commit af5c001

Please sign in to comment.