如果想从[CChar]数组中获取一上String字符串,则可以使用String的fromCString方法,其声明如下: 1 2 3 4 5 6 7 /// Creates a new `String` by copying the nul-terminated UTF-8 data /// referenced by a `CString`. /// /// Returns `nil` if the `CString` is `NULL` or if it contains il...
2、获取当前类的名称 String.fromCString(object_getClassName(self)) 注意:通过_stdlib_getDemangledTypeName也能取到,但是如果在父类里面去就只能取到父类的名称 3、 国际化 find. \( -name'*.m'-o -name'*.h'\) -print0 |xargs-0genstrings -o en.lproj 凡是使用了NSLocalizedString的字符串都能被找到...
import Glibc func getGitRevision(dirname:String) -> String { let BUFSIZE = 128 let cwd = String.fromCString(getcwd(nil, 0))! var rc = chdir(dirname) guard rc == 0 else { return "ERROR" } var rev = "" let pipe = popen("/usr/bin/git rev-parse HEAD", "r") var buf = [CC...
testString.withCString { (ptr: UnsafePointer<Int8>) -> Void in // Do something with ptr functionThatExpectsAConstCharPointer(ptr) } 可以直接把一个 C 字符串转换成一个 Swift 字符串,只需要使用 String 静态方法fromCString,需要注意的是,C 字符串必须有空终止字符串。(译者注:字符串以 "0" 结束)...
let wgetCommand = "wget -qO- http://api.mymemory.translated.net/get\\?q\\=" + String.fromCString(escapedText)! + "\\&langpair\\=" + langPair let pp = popen(wgetCommand, "r") var buf = [CChar](count:BUFSIZE, repeatedValue:CChar(0)) ...
let propertyKey = String.fromCString(property_getName(property))! //属性名称 if propertyKey == "description"{ continue } //description是Foundation中的计算型属性,是实例的描述信息 var value:AnyObject! = dict[propertyKey] //取得字典中的值 ...
// Error: Cannot convert value of type 'String' to expected argument type '[CChar]' length2(str)实际上,在C语⾔中,我们在使⽤数组参数时,很少以数组的形式来定义参数,则⼤多是通过指针⽅式来定义数组参数。如果想从[CChar]数组中获取⼀上String字符串,则可以使⽤String的fromCString⽅法...
let dateFormat = String(CString: buffer, encoding: NSUTF8StringEncoding)! But I can't figure out how to get my tmValue from an NSDate object. Also, I'm feeling like there should be an "withUnsafeMutablePointer" type block in here somewhere. To answer the "Just use NSDateFormatter".....
= sqlite3_bind_parameter_name(stmt, index + 1) let strBindedParameterName = String(cString: bindedParameterName) let key = (strBindedParameterName as NSString).substring(from: 1) let value = values[key] let bindResult = bind(value as! SQLiteDataType, for: stmt!, at: index+1) if bin...
let name = String(cString: sqlite3_column_text(selectStmt, 1)) let age = sqlite3_column_int(selectStmt, 2) print("User: \(id), Name: \(name), Age: \(age)") } } sqlite3_finalize(selectStmt) // 关闭数据库 sqlite3_close(db) ...