Skip to content

Commit 94aa6d7

Browse files
author
Joan Martin
committed
Removing deprecation warnings
1 parent 14b7ac6 commit 94aa6d7

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

Sources/Harmony/Data/DataSource/FileSystemStorageDataSource.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public class FileSystemStorageDataSource : GetDataSource, PutDataSource, DeleteD
119119
throw CoreError.NotFound("Data not found at path: \(url.path)")
120120
}
121121
// Attempting to unarchive in case it was an array
122-
if let datas = NSKeyedUnarchiver.unarchiveObject(with: data) as? [Data] {
122+
if let datas = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, NSData.self], from: data) as? [Data] {
123123
// it was an array!
124124
array.append(contentsOf: datas)
125125
} else {
@@ -134,7 +134,7 @@ public class FileSystemStorageDataSource : GetDataSource, PutDataSource, DeleteD
134134
guard let data = fileManager.contents(atPath: path) else {
135135
return Future(CoreError.NotFound("Data not found at path: \(path)"))
136136
}
137-
guard let array = NSKeyedUnarchiver.unarchiveObject(with: data) as? [Data] else {
137+
guard let array = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, NSData.self], from: data) as? [Data] else {
138138
return Future(CoreError.NotFound("Data not found at path: \(path)"))
139139
}
140140
return Future(array)
@@ -185,7 +185,7 @@ public class FileSystemStorageDataSource : GetDataSource, PutDataSource, DeleteD
185185
if fileManager.fileExists(atPath: folderURL.path) == false {
186186
try fileManager.createDirectory(atPath: folderURL.path, withIntermediateDirectories: true, attributes: nil)
187187
}
188-
let data = NSKeyedArchiver.archivedData(withRootObject: array)
188+
let data = try NSKeyedArchiver.archivedData(withRootObject: array, requiringSecureCoding: false)
189189
try data.write(to: fileURL, options: writingOptions)
190190
r.set(array)
191191
}

Sources/Harmony/Data/Mapper/Mapper+NSCoding.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import Foundation
1818

1919
public class NSCodingToDataMapper <T:NSCoding> : Mapper <T, Data> {
2020
public override func map(_ from: T) -> Data {
21-
return NSKeyedArchiver.archivedData(withRootObject: from)
21+
return try! NSKeyedArchiver.archivedData(withRootObject: from, requiringSecureCoding: false)
2222
}
2323
}
2424

25-
public class DataToNSCodingMapper <T:NSCoding> : Mapper <Data, T> {
25+
public class DataToNSCodingMapper <T:NSCoding> : Mapper <Data, T> where T:NSObject {
2626
public override func map(_ from: Data) -> T {
27-
return NSKeyedUnarchiver.unarchiveObject(with: from) as! T
27+
return try! NSKeyedUnarchiver.unarchivedObject(ofClass: T.self, from: from)!
2828
}
2929
}

Sources/Harmony/Security/KeychainDataSource.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ public class KeychainDataSource<T> : GetDataSource, PutDataSource, DeleteDataSou
7777
switch query {
7878
case let query as KeyQuery:
7979
let nsarray = array as NSArray
80-
switch keychain.set(nsarray, forKey: query.key) {
81-
case .success:
82-
return Future(array)
83-
case .failed(let status):
84-
return Future(CoreError.OSStatusFailure(status, "Keychain failed to set value for key \(query.key) (OSStatus \(status))"))
80+
return Future { r in
81+
switch try keychain.set(nsarray, forKey: query.key) {
82+
case .success:
83+
r.set(array)
84+
case .failed(let status):
85+
throw CoreError.OSStatusFailure(status, "Keychain failed to set value for key \(query.key) (OSStatus \(status))")
86+
}
8587
}
8688
default:
8789
query.fatalError(.putAll, self)

Sources/Harmony/Security/KeychainService.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ public extension KeychainService {
155155
///
156156
/// - Parameter key: The key.
157157
/// - Returns: The NSCoding conforming type stored in the keychain or nil.
158-
func get<T>(_ key: String) -> T? where T: NSCoding {
158+
func get<T>(_ key: String) -> T? where T: NSCoding, T: NSObject {
159159
if let data : Data = get(key) {
160-
if let value = NSKeyedUnarchiver.unarchiveObject(with: data) {
161-
return (value as! T)
160+
if let value = try? NSKeyedUnarchiver.unarchivedObject(ofClass: T.self, from: data) {
161+
return value
162162
} else {
163163
return nil
164164
}
@@ -173,8 +173,8 @@ public extension KeychainService {
173173
/// - key: The key.
174174
/// - Returns: The operation result.
175175
@discardableResult
176-
func set<T>(_ value: T, forKey key: String) -> Result where T: NSCoding {
177-
let data = NSKeyedArchiver.archivedData(withRootObject: value)
176+
func set<T>(_ value: T, forKey key: String) throws -> Result where T: NSCoding {
177+
let data = try NSKeyedArchiver.archivedData(withRootObject: value, requiringSecureCoding: false)
178178
return set(data, forKey: key)
179179
}
180180
}

0 commit comments

Comments
 (0)