Re: [swift-users] Referencing Swift Functions from the Objective-C Runtime

2016-11-20 Thread Jacob Bandes-Storch via swift-users
"throws" is the part that's not representable in Obj-C. Why are you using it? If you're interacting with method_getImplementation, you need to think like the Obj-C runtime. https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtHowMessagingWorks.ht

Re: [swift-users] Referencing Swift Functions from the Objective-C Runtime

2016-11-20 Thread Jeff Kelley via swift-users
Still trying on this (copied the code directly, Foo is actually XCTestCase): typealias TestMethod = @convention(c) (XCTestCase) throws -> Void This seagulls the compiler with “error: '(XCTestCase) throws -> Void' is not representable in Objective-C, so it cannot be used with '@convention(c)’”. I

Re: [swift-users] Bool to Int

2016-11-20 Thread Marco S Hyman via swift-users
> Is there a way that avoids branching? Don’t know. Have you profiled let r = a > b ? 1 : 0 to know it is an issue? > > So, according to Xcode, "true" and "a > b" both have type "Bool". I don't > know why the compiler allows one and not the other, except that it's literal, > and I guess ther

Re: [swift-users] Referencing Swift Functions from the Objective-C Runtime

2016-11-20 Thread Jacob Bandes-Storch via swift-users
For a function such as bar() above, the type you want to cast the IMP to would probably be "@convention(c) (Foo, Selector) -> ()". On Sun, Nov 20, 2016 at 9:05 PM, Jeff Kelley wrote: > Thanks Jacob! I tried using unsafeBitCast, but it fails with the > following: “fatal error: can't unsafeBitCast

Re: [swift-users] Referencing Swift Functions from the Objective-C Runtime

2016-11-20 Thread Jeff Kelley via swift-users
Thanks Jacob! I tried using unsafeBitCast, but it fails with the following: “fatal error: can't unsafeBitCast between types of different sizes”. I considered wrapping every call in a closure that calls objc_msgSend(), but alas, that’s not exposed to Swift. I have another approach in mind, so I’l

Re: [swift-users] Bool to Int

2016-11-20 Thread Rick Mann via swift-users
> On Nov 20, 2016, at 19:52 , Jon Shier wrote: > > Except in that case true isn’t a Bool but an NSNumber, which is why you can > initialize an Int from it. It seems trivially easy to add an Int extension to > do what you want though. Is there a way that avoids branching? So, according to Xco

Re: [swift-users] Bool to Int

2016-11-20 Thread Jon Shier via swift-users
Except in that case true isn’t a Bool but an NSNumber, which is why you can initialize an Int from it. It seems trivially easy to add an Int extension to do what you want though. Jon > On Nov 20, 2016, at 10:48 PM, Rick Mann via swift-users > wrote: > > It seems I can't do this: > > let r

[swift-users] Bool to Int

2016-11-20 Thread Rick Mann via swift-users
It seems I can't do this: let r = Int(a > b) but I can do it with a literal: let r = Int(true) I'd like to do this to implement signum without branching, but perhaps that's not possible. -- Rick Mann rm...@latencyzero.com ___ swift-users mailing

Re: [swift-users] Implementing signum

2016-11-20 Thread Rick Mann via swift-users
Thank you, Hooman, that's very educational. > On Nov 20, 2016, at 10:09 , Hooman Mehr wrote: > > Let me explain this a bit further: > > Swift generic programming is very different from C++ template programming. > Swift compiler needs to type-check generic code on spot, not while > instantiati

Re: [swift-users] Implementing signum

2016-11-20 Thread Hooman Mehr via swift-users
Let me explain this a bit further: Swift generic programming is very different from C++ template programming. Swift compiler needs to type-check generic code on spot, not while instantiating the template (because in Swift, instantiation can occur at runtime if the generic code is from a differe