4

This code used to work in our today extension, but now EXC_BAD_ACCESS with using Xcode 6.3. What is the new problem?

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    coordinator.animateAlongsideTransition({ context in
        self.tableView.frame = CGRectMake(0, 0, size.width, size.height)
        }, completion: nil)
}
Jason Hocker
  • 6,879
  • 9
  • 46
  • 79

1 Answers1

3

Someone mentioned to me they think this is an Apple bug. Here's a workaround (or the solution):

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
{
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

    if let safeCoordinator = coordinator as UIViewControllerTransitionCoordinator?
    {
        println("coordinator != nil")
        safeCoordinator.animateAlongsideTransition({ context in
            self.tableView.frame = CGRectMake(0, 0, size.width, size.height)
            }, completion: nil)

    }
    else
    {
        println("coordinator == nil")
    }
}
Jason Hocker
  • 6,879
  • 9
  • 46
  • 79
  • Unfortunately I get `"coordinator == nil"` every time in my Today Widget which prevents the crash but also prevents access to `size` which is my goal. Are you getting `safeCoordinator ` set to a non nil value each time? – John Erck May 06 '15 at 21:40
  • Sometimes it was nil. I dont understand it – Jason Hocker May 06 '15 at 22:17