2

What I used to do in obj-c:

unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];

what I tried in swift found here unsigned char in Swift:

let cHMAC = [CUnsignedChar](count: CC_SHA1_DIGEST_LENGTH)

However this does not build because extra argument count in call

Any ideas how I can translate the first code to swift?

Community
  • 1
  • 1
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

1 Answers1

5

You are calling the Array constructor

init(count: Int, repeatedValue: T)

and there two errors: You forgot the repeatedValue: argument, and CC_SHA1_DIGEST_LENGTH, which is mapped to Swift as an Int32, needs to be cast to Int:

let cHMAC = [CUnsignedChar](count: Int(CC_SHA1_DIGEST_LENGTH), repeatedValue: 0)

See also https://stackoverflow.com/a/25762128/1187415 for a full example.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • maybe you can help me out on another related question: http://stackoverflow.com/questions/26655999/create-hash-in-swift-using-key-and-message – DarkLeafyGreen Oct 30 '14 at 14:44