Re: supportedInterfaceOrientations in Swift
Re: supportedInterfaceOrientations in Swift
- Subject: Re: supportedInterfaceOrientations in Swift
- From: Roland King <email@hidden>
- Date: Fri, 20 Jun 2014 08:39:00 +0800
On 20 Jun, 2014, at 5:04 am, Greg Parker <email@hidden> wrote:
>>
>> override func supportedInterfaceOrientations() -> Int
>> {
>> }
>>
>> which makes some sense. I'm tripping over myself trying however to return the correct Int without casting my casts to casts of casts.
>
> Please file a bug report. -supportedInterfaceOrientations should be declared to return UIInterfaceOrientationMask, not Int. This sort of loose typing works in C but not in Swift.
>
OK I've filed (rdar://17387641) - although in this case I'm not sure it would have made life much better as the constructor takes a UInt the best I would have been able to do is
return UIInterfaceOrientationMask( UIInterfaceOrientationMask.Portrait.value + UIInterfaceOrientationMask.PortraitUpsideDown.value )
which isn't much prettier. I do agree however that returning a UIIntefaceOrientationMask would be semantically better and it's not hard to define the '+' and '|' operators on them myself to do the right thing which would lead to
return UIInterfaceOrientationMask.Portrait + UIInterfaceOrientationMask.PortraitUpsideDown
which would be very nice (and i suggested in the radar)
>
>>
>> PS in the course of trying things out I tried various ways of initializing a UInt and failed dismally often with evil stack traces in the console.
>>
>> var a : Int = 123
>> var b : UInt = 123 // fail
>> var c : UInt = a // fail
>> var d : UInt = UInt( a ) // fail
>
> The last should work assuming `a` is not negative.
>
Ah it does - when I compile and run it - it doesn't work in a playground because a playground with the following code and nothing else in it
let a = 123
let b = UInt( a )
crashes with
fatal error: Can't unwrap Optional.none
when it's trying to format the output for writing. In fact it seems lots of my 'failed experiments' from yesterday were just the playground crashing. (rdar://17387985). The command-line REPL works fine.
Thanks for the reply.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden