Change coder signatures
This commit is contained in:
parent
06e576418c
commit
53b3413131
|
@ -18,7 +18,7 @@ public class Base64StringCoder: StringCoder {
|
|||
/**
|
||||
Decode a base64 encoded string.
|
||||
*/
|
||||
public func decode(string: String) -> String? {
|
||||
public func decode(_ string: String) -> String? {
|
||||
guard let data = Data(base64Encoded: string, options: .ignoreUnknownCharacters) else { return nil }
|
||||
return String(data: data, encoding: .utf8)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class Base64StringCoder: StringCoder {
|
|||
/**
|
||||
Encode a string to base64.
|
||||
*/
|
||||
public func encode(string: String) -> String? {
|
||||
public func encode(_ string: String) -> String? {
|
||||
let data = string.data(using: .utf8)
|
||||
let encoded = data?.base64EncodedData(options: .endLineWithLineFeed)
|
||||
guard let encodedData = encoded else { return nil }
|
||||
|
|
|
@ -14,5 +14,5 @@ import Foundation
|
|||
*/
|
||||
public protocol StringDecoder: AnyObject {
|
||||
|
||||
func decode(string: String) -> String?
|
||||
func decode(_ string: String) -> String?
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ import Foundation
|
|||
*/
|
||||
public protocol StringEncoder: AnyObject {
|
||||
|
||||
func encode(string: String) -> String?
|
||||
func encode(_ string: String) -> String?
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -48,13 +48,13 @@ extension CodingScreen {
|
|||
|
||||
func base64Decode() {
|
||||
let string = coder.encode(string: "This is a string")!
|
||||
let result = coder.decode(string: string)!
|
||||
let result = coder.decode(string)!
|
||||
resultText = "\"\(string)\" was decoded to \"\(result)\""
|
||||
}
|
||||
|
||||
func base64Encode() {
|
||||
let string = "This is a string"
|
||||
let result = coder.encode(string: string)!
|
||||
let result = coder.encode(string)!
|
||||
resultText = "\"\(string)\" was encoded to \"\(result)\""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class Base64StringEncoderTests: QuickSpec {
|
|||
foo
|
||||
bar
|
||||
"""
|
||||
let encoded = coder.encode(string: string)
|
||||
let encoded = coder.encode(string)
|
||||
expect(encoded).to(equal("Zm9vCmJhcg=="))
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ bar
|
|||
|
||||
it("fails for non-encoded string") {
|
||||
let string = "test"
|
||||
let decoded = coder.decode(string: string)
|
||||
let decoded = coder.decode(string)
|
||||
expect(decoded).to(beNil())
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@ bar
|
|||
foo
|
||||
bar
|
||||
"""
|
||||
let encoded = coder.encode(string: string)!
|
||||
let decoded = coder.decode(string: encoded)
|
||||
let encoded = coder.encode(string)!
|
||||
let decoded = coder.decode(encoded)
|
||||
expect(decoded).to(equal(string))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue