• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
supportedInterfaceOrientations in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

supportedInterfaceOrientations in Swift


  • Subject: supportedInterfaceOrientations in Swift
  • From: Roland King <email@hidden>
  • Date: Thu, 19 Jun 2014 17:23:07 +0800

I'm overriding supportedInterfaceOrientations in my view controller because I want it to return Portrait + PortraitUpsideDown, and on iPhone PortraitUpsideDown is not included in the standard return.

The Objective-C method would look something like this

-(NSUInteger)supportedInterfaceOrientations
{
	return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

Swift has stubbed out the method thus

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. UIInterfaceOrientationMask is a struct with a number of Type properties, so you can write

	UIInterfaceOrientationMask.Portrait

to get its value however that's a struct so you need to ask for the 'value' property, which is defined to return a UInt and seems to do the same as toRaw(). Trying to return UIInterfaceOrientationMask.Portrait.value however gives the error

	'NSNumber is not a subtype of Int'

Odd as I thought UInt was a basic type like Int, but clearly it's an NSNumber. A bit of luck with autocompletion threw up the asSigned() method, which seems to do the same as constructing an Int using Int( .. )

That appears to work but the final line is now

return UIInterfaceOrientationMask.Portrait.value.asSigned() + UIInterfaceOrientationMask.PortraitUpsideDown.value.asSigned()

Surely there's something a little less unwieldy, anyone have something? Or is this just a case where Swift's strong typing meets Cocoa's C background and ends up in knots?

Roland

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

how do you even make one of these things?

_______________________________________________

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


  • Follow-Ups:
    • Re: supportedInterfaceOrientations in Swift
      • From: Greg Parker <email@hidden>
  • Prev by Date: Re: Send msg to object by nameed NSString;
  • Next by Date: Re: iOS app restarting from screen one. Why?
  • Previous by thread: Re: Send msg to object by nameed NSString;
  • Next by thread: Re: supportedInterfaceOrientations in Swift
  • Index(es):
    • Date
    • Thread