szu szu - 4 months ago 30
iOS Question

How to define char array in Swift language

Here is my C code in an Objective-C method


char addressBuffer[100];


But how to define this char in Swift language?

I try something like this but this doesn't work:


var addressBuffer : CChar(100)


Here is the documentation https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/buildingcocoaapps/InteractingWithCAPIs.html

Answer

that is the way to get a nice unicode character array in Swfit:

var charArray: Array<Character> = Array(count: 100, repeatedValue: "?")

if fills your array with 100 question marks, initially.

update

with CChar, for instance:

var charArray: Array<CChar> = Array(count: 100, repeatedValue: 32) // 32 is the ascii space