You’ll need to explicitly add the “as NSNumber” now.

https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md
 
<https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md>

> On Sep 9, 2016, at 1:55 PM, Rick Mann via swift-users <swift-users@swift.org> 
> wrote:
> 
> I've seen old (pre-Swift 3) posts online (e.g. 
> http://stackoverflow.com/questions/28920232/why-do-integers-not-conform-to-the-anyobject-protocol)
>  that address this, but my code worked yesterday before I used Xcode 8 GM to 
> migrate it to Swift 3, and now it doesn't, so I'm trying to understand what's 
> going on.
> 
> In this case, I have this code:
> 
> open class HttpServer
> {
>    let clientSocketsLock = 0
> 
>    open func start()
>    {
>        ...some stuff...
>        {
>            HttpServer.lock(self.clientSocketsLock) //  ERROR HERE
>            {
>                self.clientSockets.remove(socket)
>            }
>        }
>    }
> 
>    open class func lock(_ handle: AnyObject, closure: () -> ())
>    {
>        objc_sync_enter(handle)
>        closure()
>        objc_sync_exit(handle)
>    }
> }
> 
> I get the error "Argument type 'Int' does not conform to expected type 
> 'AnyObject'" at the line marked above. What has changed here?  Did Int's 
> behavior change? Is that described somewhere? I tried googling "Swift 3 Int" 
> and variations without much luck.
> 
> I did see one discussion that talked about how when passing an Int to 
> AnyObject, it was implicitly converted to NSNumber, and that this behavior 
> only applied to certain types (e.g. not Int32). How can I tell when this kind 
> of behavior exists? Is there a way to look at the type's declaration to see 
> (e.g. it conforms to a protocol, or has a compiler attribute, or something)?
> 
> Thanks,
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to