1

I building my first app in swift and created a custom segue so the slides of my storyboard are presented (sliding) from left to right. The code in my custom segue class, which I got from iOS Segue - Left to Right -, is below:

import UIKit
class SegueFromLeft: UIStoryboardSegue {
    override func perform() {
        let src = self.source
        let dst = self.destination

        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
        dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)

        UIView.animate(withDuration: 0.25,
                              delay: 0.0,
                            options: .curveEaseInOut,
                         animations: {
                                dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
                                },
                        completion: { finished in
                                src.present(dst, animated: false, completion: nil)
                                    }
                        )
    }
}

I changed some of the segues in my storyboard to this custom segue. The segue connecting my initial view controller to a navigation controller which then connected to another view controller functions correctly. However, when a different segue is executed, the animation occurs, but the screen freezes immediately after.

This snapshot of my storyboard that shows the functioning and dysfunctional segues

After the simulator freezes, an error marks this line in the SegueFromLeft class :
src.present(dst, animated: false, completion: nil)

The error message states "Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee5c39fb8)", which I believe has something to do with memory allocation, but don't know how to fix it or why it is occurring.

All help in alleviating this error is greatly appreciated.

Thanks!

  • Could you please post the full stack trace? All we can say now is that somewhere in your program that it attempted to access a location in memory that’s no longer available. – xinkecf35 Apr 10 '20 at 00:44
  • Actually small correction to the above, according to this [link](https://stackoverflow.com/questions/19741409/whats-the-difference-between-code-1-and-code-2-in-exc-bad-access), somewhere in your code you’re trying to manipulate the data in such way that is not supported, most likely a read only variable. – xinkecf35 Apr 10 '20 at 00:52
  • Okay thank you. I don't believe I implemented any read-only variables so I don't know how I'm trying to manipulate the data in a way that's not supported. Also, the full stack trace is long, like thousands of lines of code. – Ben Svoboda Apr 10 '20 at 01:14
  • It might be worth inspecting the source and destination viewcontrollers themselves as a quick sanity check and make sure they are not nil – xinkecf35 Apr 10 '20 at 01:21
  • 1
    I printed the source and destination view controllers and here's what I got: For working segue: Source : Dest: For the non-working segue (one after the first registration screen):Source: Dest: . **Looks right to me** – Ben Svoboda Apr 10 '20 at 01:25
  • Okay that’s good. At this point you will need to work out in the places you accessing a property or manipulating it that you are allowed to do so. – xinkecf35 Apr 10 '20 at 02:48
  • Wait so what should be my plan of action in looking for the property that I currently can't access but need to? – Ben Svoboda Apr 10 '20 at 22:09
  • Not quite. You’ll be looking for a property access where it is improper. You might be trying to assign a value to a read only property. You might also be trying to read a nil value (in obj-c terms trying to dereference a nil/null value) though I am not sure if that would this particular code for this exception. You might also have an empty identifier for one of your viewcontrollers that you created in Storyboards that could be causing the issue. – xinkecf35 Apr 11 '20 at 01:18

0 Answers0