[swift-users] Using withUnsafePointer on char arrays within C structs

2017-02-22 Thread Russell Finn via swift-users
Greetings — I haven't found this specific topic in the archives; apologies if this has come up before. Suppose I have a C struct with an embedded char array: struct fileinfo_t { char path[256]; }; and I want to convert the path to a Swift String (in order to implement `description`, say). I

Re: [swift-users] Using withUnsafePointer on char arrays within C structs

2017-03-01 Thread Russell Finn via swift-users
Thanks to Joe and Quinn for their answers. I have a related followup — a co-worker learning Swift wrote the following function: func allZerosUUID() -> String { var allZeros = [UInt8](repeating: 0, count: 32) return withUnsafePointer(to: &allZeros) { zerosPtr in retu

Re: [swift-users] Using withUnsafePointer on char arrays within C structs

2017-03-02 Thread Russell Finn via swift-users
hUnsafeBufferPointer { NSUUID(uuidBytes: $0. > baseAddress).uuidString } > } > > > On Mar 1, 2017, at 2:35 PM, Russell Finn via swift-users < > swift-users@swift.org> wrote: > > Thanks to Joe and Quinn for their answers. I have a related followup — a > co-worker

Re: [swift-users] Using withUnsafePointer on char arrays within C structs

2017-03-03 Thread Russell Finn via swift-users
entation details of allZeros array. >> >> Here is the correct way to do it: >> >> func allZerosUUID() -> String { >> >> let allZeros = [UInt8](repeating: 0, count: 32) >> >> return allZeros.withUnsafeBufferPointer { NSUUID(uuidBytes: $0. >&

[swift-users] NSDictionary passed through Swift loses access to category methods

2017-05-23 Thread Russell Finn via swift-users
I'm having an issue with an NSDictionary that is passing through Swift code and back to Objective-C losing access to a method implemented by a category on NSDictionary. There is clearly some subtlety about bridged dictionaries that I'm missing, and I'd appreciate any clarification that the list can

Re: [swift-users] NSDictionary passed through Swift loses access to category methods

2017-06-01 Thread Russell Finn via swift-users
3 PM, Greg Parker wrote: > > > On May 23, 2017, at 1:10 PM, Russell Finn via swift-users < > swift-users@swift.org> wrote: > > I'm having an issue with an NSDictionary that is passing through Swift > code and back to Objective-C losing access to a method implemented