Swift equivalent to Objective-C FourCharCode single quote literals (e.g. 'TEXT')

后端 未结 7 2580
天命终不由人
天命终不由人 2021-02-20 12:54

I am trying replicate some Objective C cocoa in Swift. All is good until I come across the following:

// Set a new type and creator:
unsigned long type = \'TEXT\         


        
7条回答
  •  长发绾君心
    2021-02-20 13:36

    Note: this should work but doesn't actually work - must be a bug. I am leaving this here to document that it doesn't work, may work in the future, but for time being best to use the accepted answer.

    I found the following typealiases from the Swift API:

    typealias FourCharCode = UInt32
    typealias OSType = FourCharCode
    

    And the following functions:

    func NSFileTypeForHFSTypeCode(hfsFileTypeCode: OSType) -> String!
    func NSHFSTypeCodeFromFileType(fileTypeString: String!) -> OSType
    

    This should allow me to create the equivalent code:

    let type : UInt32 = UInt32(NSHFSTypeCodeFromFileType("TEXT"))
    let creator : UInt32 = UInt32(NSHFSTypeCodeFromFileType("pdos"))
    

    WARNING: But it doesn't work on Xcode 7.0 beta (7A121l)

提交回复
热议问题