Re: [swift-users] FileManager.copyItem not throwing?

2017-11-11 Thread John Brownie via swift-users
And that's the point. The throw does not happen. An error is logged, but execution continues as though there was no error. John Howard Lovatt 12 November 2017 at 07:43 I don’t have any inside knowledge on this, i.e. I am not certain I am correct, but my underst

[swift-users] FileManager.copyItem not throwing?

2017-11-10 Thread John Brownie via swift-users
I have code as follows: let fileManager = FileManager.default do { try fileManager.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true, attributes: nil) try fileManager.copyItem(at: source, to: destination) handler(true, nil) } catch let t

Re: [swift-users] Callback in Swift

2017-01-25 Thread John Brownie via swift-users
Thanks, that does it for me, though I had to qualify the Unmanaged with a type in the first part. Rien wrote: For the context I passed in: UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()) And to get the context back inside the callback: let ourself = Unmanaged< … your type

[swift-users] Callback in Swift

2017-01-24 Thread John Brownie via swift-users
My macOS app shows a representation of the contents of various folders, so using FSEvents to track modifications from outside the app seemed to be the way to go. I am running into difficulty with writing the code with a callback, all in Swift. I must be doing something wrong, as I get a crash i

Re: [swift-users] Passing a pointer to self to C function

2016-09-30 Thread John Brownie via swift-users
Thanks! That works just as it should. It's all compiling and unit tests are passing, so I can move on now. Mike Ferenduros 30 September 2016 at 14:14 The way to do this is via Unmanaged: let raw = Unmanaged.passUnretained(expat).toOpaque() gets you an Unsafe

[swift-users] Passing a pointer to self to C function

2016-09-30 Thread John Brownie via swift-users
Still working on the expat wrapper. The thing I need to do is to pass a pointer to self to be stored in the userData that will be passed to callbacks, allowing me to get at the local instance. I did this in Swift 2.2 as: XML_SetUserData(parser, unsafeBitCast(self, UnsafeMutablePointer.self))

[swift-users] Swift 3 version of creating a string from a pointer, length and encoding?

2016-09-29 Thread John Brownie via swift-users
Next question in my migration. How do I do what this did in Swift 2.2? let theData = String.init(bytes: data.memory, length: length, encoding: NSUTF8StringEncoding) The only initialisers that have a length are init?(bytesNoCopy: UnsafeMutableRawPointer, length: Int, encoding: String.Encoding

Re: [swift-users] Updating C-wrapper to Swift 3

2016-09-28 Thread John Brownie via swift-users
Thanks for the pointers. Good reading, but I'm still confused. I think that the first issue is clear to me now, but I don't know what I have to do to make the closure be seen as satisfying the type of the function pointer. It worked in Swift 2.2 as XML_SetEndElementHandler(parser)

[swift-users] Updating C-wrapper to Swift 3

2016-09-27 Thread John Brownie via swift-users
I have a Swift wrapper for the expat XML parser, and I just went through the update to Swift 3, and I'm thrown a series of errors that mostly appear to be of two types. Here is a representative function of the first type: func parse() throws { var done = false while !done {