-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Fix SwiftLint Errors #9
Conversation
ParseSwift.playground/Pages/3- Users.xcplaygroundpage/Contents.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you address the comments please? I’d like to keep the setters non discardable to force the call sites to not ignore if setting a value failed
@@ -45,7 +44,16 @@ struct KeychainStore: SecureStorage { | |||
return NSKeyedUnarchiver.unarchiveObject(with: data) as? T | |||
} | |||
|
|||
func set<T>(object: T?, forKey key: String) -> Bool where T: Encodable { | |||
func object<T>(forKey key: String) -> [T]? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding this implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added one subscript and two functions to set and get an [Any] to subscript in KeychainStore for pass testSetComplextObject
Test Cases. But I would love to get your feedback. Thank you
subscript<T>(key: String) -> [T]?
func object<T>(forKey key: String) -> [T]?
func set<T>(object: [T]?, forKey key: String) -> Bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no need for that, as a T can be an [U] if you specify it so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for advice me. I removed these implement.
I got an error message below
testStore["complexObject"] = complexObject //Cannot assign value of type '[Any]' to type '_?'
guard let retrievedObject: [Any] = testStore["complexObject"] else {
return XCTFail("Should retrieve the object")
} //Value of optional type 'KeychainStore?' must be unwrapped to refer to member 'subscript' of wrapped base type 'KeychainStore'
So I removed where T: Decodable
where T: Codable
where T: Encodable
Is it ok? It works fine..
func object<T>(forKey key: String) -> T? {
guard let data = synchronizationQueue.sync(execute: { () -> Data? in
return self.data(forKey: key)
}) else {
return nil
}
if T.self is Decodable {
return NSKeyedUnarchiver.unarchiveObject(with: data) as? T
}
else {
return nil
}
}
func set<T>(object: T?, forKey key: String) -> Bool {
guard let object = object, object is Encodable else {
return removeObject(forKey: key)
}
let data = NSKeyedArchiver.archivedData(withRootObject: object)
let query = keychainQuery(forKey: key)
let update = [
kSecValueData as String: data
]
let status = synchronizationQueue.sync(flags: .barrier) { () -> OSStatus in
if self.data(forKey: key) != nil {
return SecItemUpdate(query as CFDictionary, update as CFDictionary)
}
let mergedQuery = query.merging(update) { (_, otherValue) -> Any in otherValue }
return SecItemAdd(mergedQuery as CFDictionary, nil)
}
return status == errSecSuccess
}
subscript<T>(key: String) -> T? {
get {
return object(forKey: key)
}
set (object) {
_ = set(object: object, forKey: key)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I removed where T: Decodable where T: Codable where T: Encodable
Is it ok? It works fine..
It is not OK, as we do not want at compile time to store non Codable entries.
Do we really need array support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need [Any] object support.
ParseSwift.playground/Pages/3- Users.xcplaygroundpage/Contents.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will also check for the cocoapods failure in the CI. Thank for getting this out :)
@@ -45,7 +44,16 @@ struct KeychainStore: SecureStorage { | |||
return NSKeyedUnarchiver.unarchiveObject(with: data) as? T | |||
} | |||
|
|||
func set<T>(object: T?, forKey key: String) -> Bool where T: Encodable { | |||
func object<T>(forKey key: String) -> [T]? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no need for that, as a T can be an [U] if you specify it so.
@ShawnBaek for the pods, you can try: |
@ShawnBaek that was for you to debug the error :) |
Ah Ok Sorry I revert it. 👍 |
@flovilmart I think we need to add version tag 0.0.1 to pass Cocoapod lint check. Pod::Spec.new do |s|
s.name = "ParseSwift"
s.version = "0.0.1"
s.summary = "Parse Pure Swift SDK"
s.homepage = "https://github.com/parse-community/Parse-Swift"
s.author = {
"[Name]" => "[Mail Address]"
}
s.source = {
:git => "#{s.homepage}.git",
:tag => "#{s.version}",
}
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.2' }
s.ios.deployment_target = "10.0"
s.osx.deployment_target = "10.10"
s.tvos.deployment_target = "9.0"
s.source_files = "Sources/ParseSwift/**/*.swift"
s.license = {
:type => "MIT",
:text => <<-LICENSE
Copyright (c) 2016 parse-community
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
LICENSE
}
end |
@ShawnBaek this is unlikely, one should be able to lint the lib without having any tag published |
comment the testComplexObject.
…to upstream-master
class KeychainStoreTests: XCTestCase { | ||
struct ComplexObject<T: Codable> : Codable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what is being tested initially. What was tested was supporting storing arrays of Codables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flovilmart Thank you. I'm sorry for too many commits in here without considering all test cases. I am going to remove the nested structure.
} | ||
//MARK:- Todo | ||
// func testSetComplextObject() { | ||
// let complexObject: [Any] = [["key": "value"], "string2", 1234, NSNull()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flovilmart How about use AnyCodable for complexObject?
Reference : https://github.com/Flight-School/AnyCodable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? Seems like a decent idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'm going to use AnyCodable in Parse-Swift Project.
I changed the shortest names like an r, t, and e to fix SwiftLint Errors.
I fixed deprecated warnings.
CocoaPod
This Repo doesn't have any version tag. So We need to add version tag.
Considering the Test Cases for [Any]
I think subscript for [Any] is not allowed in Parse-Swift
Because of the generic type of T is not a
Codable
in Swift4.I don't want to change
set
andget
functions in KeychainStore.How can we re-write testSetComplextObject?
I need some advice from reviewers