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

后端 未结 7 2333
青春惊慌失措
青春惊慌失措 2021-02-20 13:05

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:38

    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)

提交回复
热议问题