How do you convert a String to a CString in the Swift Language?

前端 未结 4 780
你的背包
你的背包 2020-12-10 02:45

I am trying to use dispatch_queue_create with a dynamic String that I am creating at runtime as the first parameter. The compiler complains because it expects a standard c

4条回答
  •  感动是毒
    2020-12-10 03:30

    You can get a CString as follows:

    import Foundation
    
    var str = "Hello, World"
    
    var cstr = str.bridgeToObjectiveC().UTF8String
    

    EDIT: Beta 5 Update - bridgeToObjectiveC() no longer exists (thanks @Sam):

    var cstr = (str as NSString).UTF8String
    

提交回复
热议问题