Unified Contacts

15 April, 2015

Default Behavior of UIPopoverPresentationController Changed in iOS 8.3

I have working with an adaptive app that can run on all size class. Before updating to iOS 8.3, the popover behavior is the same in iPad and iPhone 6 Plus landscape mode. However, after updating to iOS 8.3, the popover in iPhone 6 Plus has changed to FormSheet. This is because the popover now not only check the horizontal size class, but also the vertical size class. Popover will present normally in vertical regular like iPad, and present as FormSheet in vertical compact. So how can we fix it?

Below is the old method to disable the adaptivity of popover in horizontal compact. But it not enough in iOS 8.3.

In the demo of WWDC 2014 Session 214 "View Controller Advancements in iOS 8", Bruce explained a trick that let you present popover in horizontal compact environment (e.g. iPhone). Without this trick, the popover will be presented in modal. Let take a look what is the trick.

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

This function in UIAdaptivePresentationControllerDelegate can modify the UIModalPresentationSytle when the device is changed from horizontal regular to horizontal compact. By return .None, popover will no longer adaptive to horizontal compact and will presented in popover just like that in horizontal regular.

Okay, we now know that popover check now check both horizontal and vertical size class. Therefore, we need to use a new funcation. Apple introduced a new function in iOS 8.3 which let you determine the UIModalPresentationStyle by the TraitCollection.

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None

}

This new function can be used to replace the old function. I have disabled the adaptivity of popover in whatever size class and everything works just like in iOS 8.2.

Reference: iOS 8.3 API Diffs

12 April, 2015

Problem When Appending Tuple into Array

I've got the following error message when trying to append a tuple into an array.

Missing argument for parameter #2 in call

Here is my tuple
    (String, UInt64, NSDate?)

I get the tuple from another function and then append to the array

var fileRecords: [(String, UInt64, NSDate?)]?

var tuple = createArchive()
self.records!.append(tuple!)    <- error here

However, if I assign the tuple to a constant first and then append that constant to array. It is work.

var tuple = createArchive()
let aTuple = tuple!
self.records!.append(aTuple)    <- Okay