import CryptoKit seems to not work in playground Xcode 13.2.1

Can't seem to get CryptoKit to import. Is there some other configuration setting, etc. I need to fix? I though all you need to do in a playground is the import statement.

My code looks like this:

import UIKit
import CryptoKit

let string = "Hello world"
let data = Data(string.utf8)
let digest = SHA256.hash(data: data)

let hash = digest.compactMap { String(format: "%02x", $0)}.joined()

print("The hash is \(hash)")

Basically, I can't use any method from CryptoKit although when I was typing the import statement, soon as I typed 'Cr' I was prompted with the fill of 'CryptoKit'. It also working in an IoS project in Swift. So I know it's there. Just won't work in the playground. I get the following error message:

error: Couldn't lookup symbols:
  static CryptoKit.HashFunction.hash<τ_0_0 where τ_1_0: Foundation.DataProtocol>(data: τ_1_0) -> τ_0_0.Digest
  static CryptoKit.HashFunction.hash<τ_0_0 where τ_1_0: Foundation.DataProtocol>(data: τ_1_0) -> τ_0_0.Digest
  static CryptoKit.HashFunction.hash<τ_0_0 where τ_1_0: Foundation.DataProtocol>(data: τ_1_0) -> τ_0_0.Digest
  static CryptoKit.HashFunction.hash<τ_0_0 where τ_1_0: Foundation.DataProtocol>(data: τ_1_0) -> τ_0_0.Digest
  static CryptoKit.HashFunction.hash<τ_0_0 where τ_1_0: Foundation.DataProtocol>(data: τ_1_0) -> τ_0_0.Digest

Appreciate any insights.
Thanks

Yeah, that’s weird. I see the same thing (with Xcode 13.2 on macOS 11.6.1). I encourage you to file a bug based on your experience. Please post your bug number, just for the record.

As to what you can do now, I usually do this sort of testing using a macOS playground because it’s simpler and more reliable. Your code works just fine when I tested it in a macOS playground here (replace UIKit with Foundation).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Seeing the same issue with macOS 12.0.1 and Xcode 13.2 in a playground! Even when doing a macOS playground with Foundation instead of UIKit. Was trying to use a MD5 hash like so:

   private func MD5(string: String) -> String {
    return Insecure
      .MD5
      .hash(data: string.data(using: .utf8) ?? Data())
      .map { String(format: "%02hhx", $0) }
      .joined()
  }

Seeing the same issue with macOS 12.0.1 and Xcode 13.2 in a playground!

This is working fine for me. Specifically, I did this:

  1. On macOS 12.1, I launched Xcode 13.2.1 and created a new playground from the macOS > Blank template.

  2. I replaced the code with your code, slightly tweaked so it imports the necessary frameworks and prints the MD5 result. My actual code is pasted in below.

  3. I ran it.

  4. It printed the expected result.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

import Foundation
import CryptoKit

private func MD5(string: String) -> String {
    return Insecure
      .MD5
      .hash(data: string.data(using: .utf8) ?? Data())
      .map { String(format: "%02hhx", $0) }
      .joined()
}

let digest = MD5(string: "Hello Cruel World!")
print(digest)
// prints: c8ba47bf213417e61105ebd33cfca2ef

Update: It started to work. I put it down to computer gremlin. I had not updated anything.

I have the same issue. Using the example from eskimo returns the same "error: Couldn't lookup symbols:" error in Playground.

I have the same issue. Using the example from eskimo returns the same "error: Couldn't lookup symbols:" error in Playground.

XCode 13.2.1

macOS 11.4

Output:

error: Couldn't lookup symbols:
  static CryptoKit.HashFunction.hash<τ_0_0 where τ_1_0: Foundation.DataProtocol>(data: τ_1_0) -> τ_0_0.Digest
  static CryptoKit.HashFunction.hash<τ_0_0 where τ_1_0: Foundation.DataProtocol>(data: τ_1_0) -> τ_0_0.Digest

(sorry for not familiar with forum syntax)

As another data point, running Xcode 13.2.1 I can reproduce the "Couldn't lookup symbols" error with an iOS playground. With a Mac playground it works fine.

-- Bennett

Same error as everyone else - any likelihood of a fix ?

Did anyone file a bug about this? If so, please post your bug number.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Just for your happiness: adding my similar issue but with a different kit (StoreKit) and in lldb.

(lldb) po product
error: expression failed to parse:
error: Couldn't lookup symbols:
 type metadata accessor for StoreKit.Product
(lldb) po product.subscription
error: expression failed to parse:
error: Couldn't lookup symbols:
 StoreKit.Product.subscription.getter : Swift.Optional<StoreKit.Product.SubscriptionInfo>
(lldb) po product.subscription?.promotionalOffers
error: expression failed to parse:
error: Couldn't lookup symbols:
 StoreKit.Product.subscription.getter : Swift.Optional<StoreKit.Product.SubscriptionInfo>
import CryptoKit seems to not work in playground Xcode 13.2.1
 
 
Q