Search code examples
swiftkeywordself

What is the meaning of CFString.self?


I've seen the Q/A here about the self keyword in Swift.

However, to me this doesn't explain the use of .self in the following code fragment from this question

let attributes: [String: Any] =
    [kSecAttrKeyType as String:CFString.self,
     kSecAttrKeySizeInBits as String:numberOfBits]

What does self do in this case?


Solution

  • Type.self is the type as a value.

    There is a difference between

    let s : String = "hello world"
    

    where String is declaring the type of s, and

    let sometype : Any = String.self
    

    where we are assigning the String type itself as the value to be stored. That's called the metatype.