Re: [swift-users] Closure typing changed in Swift 3

2016-09-09 Thread Rick Mann via swift-users
I figured it out. The real problem is that .json accepts AnyObject, and the 
Dictionary is not AnyObject (not sure what this change is, since it worked in 
Swift 2). Anyway, that confused the type inference, which resulted in the red 
herring error message about the closure assignment.


> On Sep 9, 2016, at 14:34 , Rick Mann via swift-users  
> wrote:
> 
> I have some code that implements an HTTP server. You use it like this:
> 
> server["/some/path"] =
> { inReq in
>   return .ok(.json(["key" : "value"]))
> }
> 
> ".ok" is a case in the HttpResponse enum.
> 
> The subscript on "server" above looks like this:
> 
> class HttpServer {
>   typealias Handler = (HttpRequest) -> HttpResponse
> 
>   subscript (path: String) -> Handler?
>   {
>   get { return nil }
>   set ( newValue )
>   {
>   ...store in dictionary of path:Handler...
>   }
>   }
> }
> 
> Unfortunately, in Swift 3, I get "Cannot assign value of type '(_) -> _' to 
> type 'HttpServer.Handler?'"
> 
> It seems the type inference is working differently? I tried { (inReq: 
> HttpRequest) in ... }, but I got the same error with a slightly different 
> type signature.
> 
> Can anyone tell me what's changed?
> 
> TIA,
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users


-- 
Rick




-- 
Rick Mann
rm...@latencyzero.com


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


[swift-users] Swift 3.0 GM Candidate for Ubuntu

2016-09-09 Thread Chris Lattner via swift-users
I’m not sure if this got mentioned anywhere yet, but the Swift 3.0 GM candidate 
build is now up for Ubuntu:
https://swift.org/download/#releases

-Chris (just the messenger, not the person who did all the hard work to make 
this happen!)

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


Re: [swift-users] Argument type 'Int' does not conform to expected type 'AnyObject'

2016-09-09 Thread Roderick Mann via swift-users

> On Sep 9, 2016, at 15:46 , Joe Groff  wrote:
> 
> 
>> On Sep 9, 2016, at 2:02 PM, Kevin Nattinger via swift-users 
>>  wrote:
>> 
>> 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
> 
> Or even better, you should now be able to use `Any` in Swift 3 in most places 
> Swift 2 required `AnyObject`. Swift now handles the object conversion as part 
> of the runtime Objective-C bridge, so these weird special-case implicit 
> conversions should not be necessary in most cases anymore.

Thank you both for the answers.

In the end, I changed the method to take "Any" instead of "AnyObject", since it 
just passed it on to a system call that accepted "Any".


-- 
Rick Mann
rm...@latencyzero.com


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


Re: [swift-users] Argument type 'Int' does not conform to expected type 'AnyObject'

2016-09-09 Thread Joe Groff via swift-users

> On Sep 9, 2016, at 2:02 PM, Kevin Nattinger via swift-users 
>  wrote:
> 
> 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

Or even better, you should now be able to use `Any` in Swift 3 in most places 
Swift 2 required `AnyObject`. Swift now handles the object conversion as part 
of the runtime Objective-C bridge, so these weird special-case implicit 
conversions should not be necessary in most cases anymore.

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


[swift-users] Closure typing changed in Swift 3

2016-09-09 Thread Rick Mann via swift-users
I have some code that implements an HTTP server. You use it like this:

server["/some/path"] =
{ inReq in
return .ok(.json(["key" : "value"]))
}

".ok" is a case in the HttpResponse enum.

The subscript on "server" above looks like this:

class HttpServer {
typealias Handler = (HttpRequest) -> HttpResponse

subscript (path: String) -> Handler?
{
get { return nil }
set ( newValue )
{
...store in dictionary of path:Handler...
}
}
}

Unfortunately, in Swift 3, I get "Cannot assign value of type '(_) -> _' to 
type 'HttpServer.Handler?'"

It seems the type inference is working differently? I tried { (inReq: 
HttpRequest) in ... }, but I got the same error with a slightly different type 
signature.

Can anyone tell me what's changed?

TIA,

-- 
Rick Mann
rm...@latencyzero.com


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


Re: [swift-users] Argument type 'Int' does not conform to expected type 'AnyObject'

2016-09-09 Thread Kevin Nattinger via swift-users
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
 


> On Sep 9, 2016, at 1:55 PM, Rick Mann via swift-users  
> 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


[swift-users] Argument type 'Int' does not conform to expected type 'AnyObject'

2016-09-09 Thread Rick Mann via swift-users
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


Re: [swift-users] Migrating to Swift 3 using Xcode fails

2016-09-09 Thread Saagar Jha via swift-users
Thanks, I’ve filed rdar://problem/28230945  with the 
xcodeproj.

Saagar Jha



> On Sep 9, 2016, at 10:03, Jordan Rose  wrote:
> 
> Xcode and migration aren't part of the Swift open source project, but this is 
> something I've heard other people complaining about. Can you please file a 
> Radar if you haven't already (bugreport.apple.com 
> ) and include your project file, then send me 
> the bug number? (For this particular issue, I think we can get away with just 
> the xcodeproj rather than the entire project sources that we'd usually need.)
> 
> Thanks,
> Jordan
> 
> 
>> On Sep 8, 2016, at 19:51, Saagar Jha via swift-users > > wrote:
>> 
>> Ok, here’s what happened:
>> 
>> 1. I had a project that used Swift 2.3 with Xcode 7.
>> 2. I downloaded Xcode 8 beta 1 and used the migrator to migrate to Swift 3 
>> (successfully).
>> 3. I downloaded the Xcode 8 betas, fixing errors as they cropped up due to 
>> new proposals.
>> 4. I downloaded Xcode 8 GM, and the project now fails to build due to it 
>> reverting back to the 2.3 compiler when I right when opened it (I have no 
>> idea how this happened).
>> 5. I trigger the migrator manually, which warns that the project is already 
>> on Swift 3. I force it to go through anyways, hoping to have it swap the 
>> compiler. It proposes no source changes (since I’ve already done this in 
>> previous betas) and it then “fails” for whatever reason.
>> 6. It’s still using the old compiler and my code fails to build.
>> 
>> Saagar Jha
>> 
>> 
>> 
>>> On Sep 8, 2016, at 19:33, Zhao Xin >> > wrote:
>>> 
>>> I​ am confused with your situation. You said, "I’ve migrated one of my 
>>> projects to Swift 3 previously, with an earlier beta of Xcode.". Then in 
>>> Xcode should not using Swift 2.3. Assuming ​X​code using 2.3 wrongly, you 
>>> should use Xcode migration tool again, after that Xcode will use Swift 3.0. 
>>> You manually change code will not cause Xcode using Swift 3.0 automatically.
>>> 
>>> Zhaoxin​
>>> 
>>> On Fri, Sep 9, 2016 at 10:26 AM, Saagar Jha >> > wrote:
>>> I am aware that there were new proposals, and I’ve been following along and 
>>> manually migrating. The errors are due to Xcode using the Swift 2.3 
>>> compiler, which doesn’t like the new Swift 3 syntax (for example, it’s 
>>> complaining that it can’t find the new types that have the NS- prefix 
>>> dropped). I’m just looking for the flag in build settings that switches the 
>>> compilers.
>>> 
>>> Saagar Jha
>>> 
>>> 
>>> 
 On Sep 8, 2016, at 16:47, Zhao Xin >>> > wrote:
 
 ​I think you can just use Xcode's tool that you upgrade to Swift 3.0. 
 However, I suggest you do a backup of your project first in case this is 
 not helpful.
 
 Also, the errors you saw were probably not because of Xcode converted you 
 code to 2.3 automatically. It wouldn't do that. The real reason is that in 
 Xcode 6 beta6, a lot of Swift 3.0 accepted proposals were implemented and 
 released, which made the Swift 3.0 far more different from the previous 
 3.0. 
 
 Xcode's migration tool is closed sourced and is not part of Swift. ​If you 
 have further questions, I suggest you to ask it in Apple's developer forum.
 
 Zhaoxin
 
 On Fri, Sep 9, 2016 at 5:01 AM, Saagar Jha via swift-users 
 mailto:swift-users@swift.org>> wrote:
 Hi,
 
 I’ve migrated one of my projects to Swift 3 previously, with an earlier 
 beta of Xcode. However, after downloading the GM seed, hundreds of errors 
 pop up in my code, since it appears that Xcode has somehow reverted the 
 compiler back to 2.3. Manually migrating using Edit>Convert>To Current 
 Swift Syntax… always fails, due to the fact that the code had been 
 previously migrated. Is there any way to “manually” migrate the code (i.e. 
 change the compiler settings?)
 
 Thanks,
 Saagar Jha
 
 
 
 
 ___
 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
> 

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


Re: [swift-users] Migrating to Swift 3 using Xcode fails

2016-09-09 Thread Jordan Rose via swift-users
Xcode and migration aren't part of the Swift open source project, but this is 
something I've heard other people complaining about. Can you please file a 
Radar if you haven't already (bugreport.apple.com) and include your project 
file, then send me the bug number? (For this particular issue, I think we can 
get away with just the xcodeproj rather than the entire project sources that 
we'd usually need.)

Thanks,
Jordan


> On Sep 8, 2016, at 19:51, Saagar Jha via swift-users  
> wrote:
> 
> Ok, here’s what happened:
> 
> 1. I had a project that used Swift 2.3 with Xcode 7.
> 2. I downloaded Xcode 8 beta 1 and used the migrator to migrate to Swift 3 
> (successfully).
> 3. I downloaded the Xcode 8 betas, fixing errors as they cropped up due to 
> new proposals.
> 4. I downloaded Xcode 8 GM, and the project now fails to build due to it 
> reverting back to the 2.3 compiler when I right when opened it (I have no 
> idea how this happened).
> 5. I trigger the migrator manually, which warns that the project is already 
> on Swift 3. I force it to go through anyways, hoping to have it swap the 
> compiler. It proposes no source changes (since I’ve already done this in 
> previous betas) and it then “fails” for whatever reason.
> 6. It’s still using the old compiler and my code fails to build.
> 
> Saagar Jha
> 
> 
> 
>> On Sep 8, 2016, at 19:33, Zhao Xin > > wrote:
>> 
>> I​ am confused with your situation. You said, "I’ve migrated one of my 
>> projects to Swift 3 previously, with an earlier beta of Xcode.". Then in 
>> Xcode should not using Swift 2.3. Assuming ​X​code using 2.3 wrongly, you 
>> should use Xcode migration tool again, after that Xcode will use Swift 3.0. 
>> You manually change code will not cause Xcode using Swift 3.0 automatically.
>> 
>> Zhaoxin​
>> 
>> On Fri, Sep 9, 2016 at 10:26 AM, Saagar Jha > > wrote:
>> I am aware that there were new proposals, and I’ve been following along and 
>> manually migrating. The errors are due to Xcode using the Swift 2.3 
>> compiler, which doesn’t like the new Swift 3 syntax (for example, it’s 
>> complaining that it can’t find the new types that have the NS- prefix 
>> dropped). I’m just looking for the flag in build settings that switches the 
>> compilers.
>> 
>> Saagar Jha
>> 
>> 
>> 
>>> On Sep 8, 2016, at 16:47, Zhao Xin >> > wrote:
>>> 
>>> ​I think you can just use Xcode's tool that you upgrade to Swift 3.0. 
>>> However, I suggest you do a backup of your project first in case this is 
>>> not helpful.
>>> 
>>> Also, the errors you saw were probably not because of Xcode converted you 
>>> code to 2.3 automatically. It wouldn't do that. The real reason is that in 
>>> Xcode 6 beta6, a lot of Swift 3.0 accepted proposals were implemented and 
>>> released, which made the Swift 3.0 far more different from the previous 
>>> 3.0. 
>>> 
>>> Xcode's migration tool is closed sourced and is not part of Swift. ​If you 
>>> have further questions, I suggest you to ask it in Apple's developer forum.
>>> 
>>> Zhaoxin
>>> 
>>> On Fri, Sep 9, 2016 at 5:01 AM, Saagar Jha via swift-users 
>>> mailto:swift-users@swift.org>> wrote:
>>> Hi,
>>> 
>>> I’ve migrated one of my projects to Swift 3 previously, with an earlier 
>>> beta of Xcode. However, after downloading the GM seed, hundreds of errors 
>>> pop up in my code, since it appears that Xcode has somehow reverted the 
>>> compiler back to 2.3. Manually migrating using Edit>Convert>To Current 
>>> Swift Syntax… always fails, due to the fact that the code had been 
>>> previously migrated. Is there any way to “manually” migrate the code (i.e. 
>>> change the compiler settings?)
>>> 
>>> Thanks,
>>> Saagar Jha
>>> 
>>> 
>>> 
>>> 
>>> ___
>>> 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

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