HungCLo HungCLo - 9 months ago 64
iOS Question

Ambiguous Use of 'SubScript' in Swift-2.2, Xcode 7.3.1

I'm trying a App with CommonCrypto,

so I download a SHA256.swift from CryptoCoinSwift/SHA256-Swift, and add it into my project.

In my unit test, I create a function to test whether the file is good or not ?

Here is my code in unit test :

func testCrypto() {
let a: String = "123456"
let b = SHA256.hexStringDigest(a) <- error line

Error line

Ambiguous use of 'hexStringDigest'

Could anyone tell me, what's wrong with my code ?



So going through the GitHub project you cited, I found 2 functions named hexStringDigest, both accept a string as input:

public static func hexStringDigest (input : String) -> NSData
public static func hexStringDigest (input : String) -> String

Swift was confused which one you wanted. Give the compiler a hint:

let b: String = SHA256.hexStringDigest(a)