WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: SHA256

Forums > Swift

Can anyone explain to me how to use SHA256. I tried the example on the website https://www.hackingwithswift.com/example-code/cryptokit/how-to-calculate-the-sha-hash-of-a-string-or-data-instance

import CryptoKit

let inputString = "Hello, world!"
let inputData = Data(inputString.utf8)

let hashed = SHA256.hash(data: inputData)

I just get an error in playgrounds of

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

   

It's an issue in the iOS playground. It will work in the Playgrounds app or using a macOS playground in Xcode.

   

But I am using macOS playground in Xcode

   

You followed the steps Quinn laid out in that thread and you still got an error? Worked just fine for me.

   

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.