Re: Advice on document handling
On Fri Jun 20 2014 12:58:11 GMT+1000 (PGT) Graham Cox wrote: On 20 Jun 2014, at 12:37 pm, John Brownie wrote: OK, thank you for the pointers. After a lot of refactoring, I've got things working without deadlocks, and cleaned up various things on the way. However, the autosave is getting too expensive for the bundled document. One strategy might to make it less expensive. How are you saving stuff? Archiving? Are you allowing it to save in the background? It's serialising a tree-structured document as XML (I don't control the format of the XML document) and then write it to disk. The writing seems to be taking the time, even if it's wrapped in a dispatch_async block. Well, you might have to end up rolling your own solution to tracking which files have changed. You probably can't rely on NSUndoManager, that's not really its job, and in any case it's a very opaque object. Your document could certainly manage a list of URLs that it knows have changed, and this list could be maintained in some simple manner by your code as it works, in addition to any normal undo. It's for you to figure it out though, as it will depend entirely on what your document does and how it does it. That's what I was afraid of. Looks like I need to keep a local flag for when the document gets changed and when it gets saved. Thanks, John -- John Brownie, john_brow...@sil.org or j.brow...@sil.org.pg Summer Institute of Linguistics | Mussau-Emira language, Mussau Is. Ukarumpa, Eastern Highlands Province | New Ireland Province Papua New Guinea | Papua New Guinea ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Advice on document handling
On 20 Jun 2014, at 12:37 pm, John Brownie wrote: > OK, thank you for the pointers. After a lot of refactoring, I've got things > working without deadlocks, and cleaned up various things on the way. > > However, the autosave is getting too expensive for the bundled document. One strategy might to make it less expensive. How are you saving stuff? Archiving? Are you allowing it to save in the background? > However, I haven't been able to find out how to determine if a particular > object has changed since the version on disk. In particular, there is only > one undo manager for the document, but there are several files that are > managed by the document, and I can't see how to see what has changed. > > I must be missing something obvious, so would welcome someone pointing me in > the right direction on this one. Well, you might have to end up rolling your own solution to tracking which files have changed. You probably can't rely on NSUndoManager, that's not really its job, and in any case it's a very opaque object. Your document could certainly manage a list of URLs that it knows have changed, and this list could be maintained in some simple manner by your code as it works, in addition to any normal undo. It's for you to figure it out though, as it will depend entirely on what your document does and how it does it. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Advice on document handling
OK, thank you for the pointers. After a lot of refactoring, I've got things working without deadlocks, and cleaned up various things on the way. However, the autosave is getting too expensive for the bundled document. I've done some testing to show this, so I need to be smarter about saving, only saving component files that have actually changed. I can see that I will get there by using writeToURL:ofType:forSaveOperation:originalContentsURL:error: and examining the existing bundle. However, I haven't been able to find out how to determine if a particular object has changed since the version on disk. In particular, there is only one undo manager for the document, but there are several files that are managed by the document, and I can't see how to see what has changed. I must be missing something obvious, so would welcome someone pointing me in the right direction on this one. John -- John Brownie, john_brow...@sil.org or j.brow...@sil.org.pg Summer Institute of Linguistics | Mussau-Emira language, Mussau Is. Ukarumpa, Eastern Highlands Province | New Ireland Province Papua New Guinea | Papua New Guinea ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSReleasePool issue
Hi All, I was playing around with OBJ_DEBUG_MISSING_POOL env variable and set it to YES. I was able to debug most of the issues in my code where I missed auto release pools. This is the last one remaining. However I am not sure where the leak is happening. It looks like NSApplicationMain, do that also need this auto release pool? objc[26109]: MISSING POOLS: Object 0x618410e0 of class NSUserDefaults autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug (lldb) bt * thread #1: tid = 0x3d3c5f, 0x7fff91da8604 libobjc.A.dylib`objc_autoreleaseNoPool, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x7fff91da8604 libobjc.A.dylib`objc_autoreleaseNoPool frame #1: 0x7fff91d95488 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::autoreleaseSlow(objc_object*) + 72 frame #2: 0x7fff91da8781 libobjc.A.dylib`_objc_rootAutorelease2(objc_object*) + 75 frame #3: 0x7fff895528a3 AppKit`_NSGetBoolAppConfig + 85 frame #4: 0x7fff89571566 AppKit`-[NSApplication _installMemoryPressureDispatchSources] + 161 frame #5: 0x7fff89565861 AppKit`-[NSApplication run] + 206 frame #6: 0x7fff895507a3 AppKit`NSApplicationMain + 940 * frame #7: 0x00012022 TOS`main(argc=3, argv=0x7fff5fbffa90) + 34 at main.m:13 (lldb) c Regards, Varun ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: supportedInterfaceOrientations in Swift
On 20 Jun, 2014, at 5:04 am, Greg Parker 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: supportedInterfaceOrientations in Swift
> On Jun 19, 2014, at 2:23 AM, Roland King wrote: > > 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. 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. > 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. UInt is just as basic as Int and is unrelated to NSNumber. The error message is incorrect (it's a known bug). I think the problem was that .value returns UInt and your method returns Int. > 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 The last should work assuming `a` is not negative. -- Greg Parker gpar...@apple.com Runtime Wrangler ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Any examples of -[NSScrollView addFloatingSubview:]? SOLVED
On Jun 14, 2014, at 3:18 PM, Bill Cheeseman wrote: > The -[NSScrollView addFloatingSubview:] method was added in OS X 10.9 > Mavericks. I can't find any usage examples, and the Mavericks release notes > and the reference document are not helpful to me. Playing around with it for > a few minutes has gotten me nowhere. > > Has anybody figured out how to use this? > > The reason I'm asking is that it seems like it might be one way to put a > button bar at the bottom of a source list outline and have the source list's > special color show through the button bar. Lots of Apple applications and > others show the source list background color through and around the buttons > at the bottom, but I can't find any examples of how they do it. Maybe they > just use regular colors that happen to match the system source list > background color. (I want to use the special "_sourceListBackgroundColor" > that automatically changes color when the window moves between active and > inactive states. It's easy to assign normal colors to the button bar, but > -[NSBox fillColor] won't accept special system colors like this.) I figured this one out just a few minutes later. In Interface Builder, I have a SourceListView nib file containing my source list view, which as usual is an NSScrollView containing an NSClipView containing an NSOutlineView. In my SourceListViewController, -awakeFromNib adds this source list view into the left pane of a vertical split view in my application's main window. To add a floating (non-scrolling) NSBox view containing gradient buttons to the bottom of the source list, I start by creating a freestanding NSBox view containing some gradient buttons in SourceListView.xib. This is a separate view object sitting alongside the source list view in the nib file. I select the NSBox view's Transparent checkbox. I connect the NSBox view to the sourceListButtonBox IBOutlet in my SourceListViewController class (file's owner). In SourceListViewController's -awakeFromNib method, I insert this code after setting up and configuring the source list: NSOutlineView *outlineView = [self sourceListOutlineView]; NSScrollView *scrollView = (NSScrollView *)[[outlineView superview] superview]; NSBox *buttonBox = [self sourcListButtonBox]; [scrollView addFloatingSubview:buttonBox forAxis:NSEventGestureAxisVertical]; [buttonBox setFrameOrigin:NSMakePoint(0.0, [scrollView bounds].size.height - [buttonBox bounds].size.height)]; And that's it. When I run it, the gradient buttons in the NSBox sit near the bottom of the source list, no matter how I resize the window or the left pane of the split view, and no matter how I scroll the source list. The special "_sourceListBackgroundColor" of the source list shows through the transparent NSBox view and around the opaque gradient buttons, and it turns from light blue to white when the window becomes inactive and back to light blue when it becomes active. The really funky part of this is that the rows of images and text fields in the source list are visible through the transparent NSBox view and around the gradient buttons as the source list scrolls. Once I figure out how to dim the source list rows while they scroll behind the gradient buttons (see my other message of today), I will have source list rows visible (but dimmed) behind the group rows at the top of the source list and behind the gradient buttons at the bottom of the source list, for a consistent visual appearance. Whether one likes this visual appearance is a matter of taste, I suppose. I am certainly uncomfortable with it, as I am with any new UI theme. But it does seem to be the wave of the future as seen in Yosemite. -- Bill Cheeseman - b...@cheeseman.name ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: iOS app restarting from screen one. Why?
On Jun 19, 2014, at 12:13 PM, Quincey Morris wrote: > On Jun 19, 2014, at 08:24 , Alex Zavatone wrote: > >> There is no message thrown in the console and the applicationWillTerminate: >> method isn't called at all. > > Generally, since iOS 4, applicationWillTerminate: is never invoked. You get > applicationDidEnterBackground, and that’s where you’re supposed to save your > state. (The exception is when you’re doing background processing.) > > This is clearly documented here: > > > https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html > Thanks. That's a good one I certainly missed. > and a couple of people already mentioned it in this thread. If you’re still > using applicationWillTerminate: in your app, you’re Doing It Wrong™. > Heh, thanks. I was simply putting an NSLog in there to see if I could determine what was happening - since I couldn't find that clearly documented anywhere. All is calm, all is well. Nothing to see here. Please move along. Cheers, - Alex Zavatone. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: iOS app restarting from screen one. Why?
On Jun 19, 2014, at 08:24 , Alex Zavatone wrote: > There is no message thrown in the console and the applicationWillTerminate: > method isn't called at all. Generally, since iOS 4, applicationWillTerminate: is never invoked. You get applicationDidEnterBackground, and that’s where you’re supposed to save your state. (The exception is when you’re doing background processing.) This is clearly documented here: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html and a couple of people already mentioned it in this thread. If you’re still using applicationWillTerminate: in your app, you’re Doing It Wrong™. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bindings setup with NSCollectionViews
Bind the Selection Indexes of the master collection view to selectionIndexes of the BoardArrayController. I would bind the Contents of the detail collection view to arrangedObjects of the ListArrayController. Willeke Op 18 jun 2014, om 03:40 heeft Hajder Rabiee het volgende geschreven: > Hi all > > I am having trouble getting the master-detail binding configuration setup > correctly. I've sat down far too many hours > trying to debug this and I hope anyone can give me a hint on how to solve > this issue. > > The full problem description can be found already at > http://stackoverflow.com/questions/24190299/nscollectionview-master-detail-binding-configuration > > Thank you > > -- > Med vänliga hälsningar / Best Regards > Hajder > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/willeke2007%40gmail.com > > This email sent to willeke2...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: iOS app restarting from screen one. Why?
Yeah, I just tried rebooting the device and while I'm running the app on the device through Xcode, the app definitely quits when the Personal Hotspot is toggled on or off, as Xcode states "No Debug Session". There is no message thrown in the console and the applicationWillTerminate: method isn't called at all. Finally, the debugger pulled up that a SIGSTOP is being sent. Sometimes, the app is just quit and not relaunched. I've just tested this with other apps and this appears to be an Xcode issue. This only happens when running an app on the device in a debug session in Xcode and the network configuration changes, such as turning on or off the Personal Hotspot. Hope this info will help someone else out. Cheers, - Alex Zavatone On Jun 19, 2014, at 10:25 AM, Alex Kac wrote: > Recently I hit the same issue. It was working just fine one day, and then the > next - every app from Mail to Safari to 3rd party apps - all were losing > their UI state when I’d switch between them. On an iPhone 5s. Reboot fixed it > for now. > > On Jun 19, 2014, at 5:19 AM, Jonathan Hull wrote: > >> My guess would be that Jens is correct. Your app is likely being killed by >> the system while it is in the background. I tend to run a lot of apps at >> once and switch between them often, so I run into this all the time. >> >> When your app is backgrounded, you should save your UI state and restore it >> when you get relaunched. It will appear to the user as if the app was >> running the whole time. >> >> Thanks, >> Jon >> > > Alex Kac - President and Founder > Web Information Solutions, Inc. > > > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: iOS app restarting from screen one. Why?
Recently I hit the same issue. It was working just fine one day, and then the next - every app from Mail to Safari to 3rd party apps - all were losing their UI state when I’d switch between them. On an iPhone 5s. Reboot fixed it for now. On Jun 19, 2014, at 5:19 AM, Jonathan Hull wrote: > My guess would be that Jens is correct. Your app is likely being killed by > the system while it is in the background. I tend to run a lot of apps at once > and switch between them often, so I run into this all the time. > > When your app is backgrounded, you should save your UI state and restore it > when you get relaunched. It will appear to the user as if the app was > running the whole time. > > Thanks, > Jon > Alex Kac - President and Founder Web Information Solutions, Inc. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Send msg to object by nameed NSString;
> > On 19 Jun 2014, at 3:30 pm, Trygve Inda wrote: > >> Should I be doing: >> >> self.myProperty = [coder decodeObjectForKey:kMyProperty]; >> >> (isn't that effectively the same as a getter/setter)? > > Yep, it's the same, so you will gain nothing there. > > >> Guessing it would be better as: >> >> myProperty = [[coder decodeObjectForKey:kMyProperty] retain]; > > > Yes, this is what I meant. If you have declared your own ivars, it's far > faster to set them directly. > >> >> 100x - 600x is a big hit. > > It only starts to become noticeable when you are dearchiving a big graph > though, so don't sweat it for one object. If you are relying on synthesizing > the actual ivar, not just the setters/getters, you have little choice, though > apparently you can rely on the ivar being the name of the property with a > leading underscore. I dislike that sort of hidden magic however. > > I saw one file come down from taking 11 minutes (!) to 1.5 seconds to open > with just this change. > > > --Graham > > > I declare all my ivars but this case is small so I can't imagine an improvement. I have one other place where it might help though. That one takes about 2-3 seconds to open/read a file. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: iOS app restarting from screen one. Why?
My guess would be that Jens is correct. Your app is likely being killed by the system while it is in the background. I tend to run a lot of apps at once and switch between them often, so I run into this all the time. When your app is backgrounded, you should save your UI state and restore it when you get relaunched. It will appear to the user as if the app was running the whole time. Thanks, Jon On Jun 18, 2014, at 12:59 PM, Alex Zavatone wrote: > Honestly, it seems like it's unrolling the navigation controller for some > strange reason when I toggle Personal Hotspot while the app is in the > background. > > Many times I've seen this happen and even when moving various iPhone's > Settings panels to the background, then bringing them to the front again. > > Never saw it before iOS 7, so I was wondering it anyone else has been seeing > this. > > Since many of our apps need to be run on a VPN, it's expected that the > network connection could change due to user action and it's really not > optimal if changing network access forces a nav stack unroll. > > I'm not even sure that's what's happening, but it sure appears to be after > looking at this happening over at least 5 apps for about 9 months. > > Has anyone else seen this type of behaviour? > > On Jun 18, 2014, at 2:42 PM, Jens Alfke wrote: > >> >> On Jun 18, 2014, at 11:22 AM, Alex Zavatone wrote: >> >>> Does anyone have any info on what causes the app to seemingly unroll it's >>> Navigation Controller stack and start from the first screen again? >> >> Probably because the OS quit the app while it was backgrounded, and it’s >> being relaunched? >> >> Back in the day, before app processes persisted in the background, it was >> important to explicitly save your UI state (controller stack) and restore it >> on startup, but I suspect a lot of apps don’t pay attention to this anymore >> since the relaunch doesn’t happen very often. >> >> —Jens > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/jhull%40gbis.com > > This email sent to jh...@gbis.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
supportedInterfaceOrientations in Swift
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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com