1

I just finished my first app. I was about to submit it when I figured out a (10MB) memory leak. According to this post it is caused by the segues I am using.

As I understand it, currently my app generates a new view every time I perform a segue. I have been reading a lot of posts that ended up confusing me. Should I use dissmissViewController? Unwind Segue?

This post was really helpful regarding unwind segue. But on a UI point of view, I like the current performSegueWithIdentifier solution as I have made nice horizontal sliding segues. Is there a way to customize transition when using an unwind segue?

I wish there was a possibility to simply "kill" the previous ViewController in the custom segue code...

ps: Here is the code of one of the segue:

import UIKit

class FirstCustomSegueUnwind: UIStoryboardSegue {
override func perform() {
    var firstVCView = self.sourceViewController.view as UIView!
    var secondVCView = self.destinationViewController.view as UIView!


    let screenWidth = UIScreen.mainScreen().bounds.size.width
    let screenHeight = UIScreen.mainScreen().bounds.size.height

    secondVCView.frame = CGRectMake(-screenWidth, 0.0, screenWidth, screenHeight)

    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(secondVCView, aboveSubview: firstVCView)

    UIView.animateWithDuration(0.4, animations: { () -> Void in
        firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0)
        secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0)


        }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, animated: false, completion: nil)

    }


}
}
Community
  • 1
  • 1
Quentin Malgaud
  • 405
  • 6
  • 21
  • There's no difference in how you dismiss your `UIViewController` as long as you don't have something holding a pointer on to it. – Schemetrical May 11 '15 at 22:52
  • Hi @Schemetrical, thank you for your comment. Do you mean that I can use normal segues or that there is no difference between using dismissViewController and unwind segue? Also, what do you mean by a pointer? I do in some cases pass value to this new viewController, even though most of the times the value is nill. – Quentin Malgaud May 11 '15 at 23:07
  • An unwind segue is a dismissViewController but it passes data back to the main controller. dismissViewController simply performs the unwind segue without passing data back. If you want to do custom animations, I suggest you read on better ways to use a custom segue, because the code you just pasted is a horrible and hacky solution to custom segue. – Schemetrical May 12 '15 at 00:02

0 Answers0