dimanche 14 juin 2020

How to fix EXC_BAD_ACCESS when referencing a different file (Xcode-swift)?

I hope this here question provides you with enough info - if not I can clarify anything up! Be sure, I'll be super grateful to anyone who does help me - thanks so much in advance!

Some background:

The background of this problem / project is that I'm trying to use a design pattern in Xcode for the first time - exciting... - and more specifically MVPVM. Therefore, I'm trying to reference different scripts within my code which is where I am getting my errors.

What I want?

Quite obviously, I just want to get rid of my errors which so that in my code I can reference any variable or function whenever I want - within reason :)

There error itself

The full error: Thread 1: EXC_BAD_ACCESS (code=2, address=xxxxxxxxxxxxxx)

An image of the error - if you need it for some reason...

What I think the problem is

I'm almost certain that the error is the way that I'm referencing the other scripts - the reason I can't figure out how to do this is it appears to literally be NOWHERE online.

What I've tried

At this point, I've tried a lot of stuff such as...

let CalendarViewControllerPlace: CalendarViewController // and then initialising it - which DID NOT WORK...


let CalendarViewControllerPlace: CalendarViewController? 


let CalendarViewControllerPlace = CalendarViewController? // AND ! etc. etc.

And a whole bunch of initialisation....

override init(){
    self.CalendarViewControllerPlace = CalendarViewController()
    self.CalendarViewModelScript = CalendarViewModel()
}

Among others, but none of them worked so.... (Also these don't work if that was a confusing statement)

The code:

This is the code that I currently am using - spoiler alert: It does not work...

import Foundation
import FSCalendar

class CalendarPresenter: NSObject, FSCalendarDelegate{

let CalendarViewControllerPlace = CalendarViewController()
let CalendarViewModelScript = CalendarViewModel()

/*
override init(){
    self.CalendarViewControllerPlace = CalendarViewController()
    self.CalendarViewModelScript = CalendarViewModel()
}
*/

func goToToday(){
    CalendarViewControllerPlace.calendar.select(CalendarViewControllerPlace.calendar)
    //calendar.select(calendar.today)
}

func Start(){
    //Not sure that this will work but...........
    CalendarViewControllerPlace.calendar.delegate = CalendarViewControllerPlace.self
    CalendarViewControllerPlace.calendar.pagingEnabled = false
    CalendarViewControllerPlace.calendar.scrollDirection = .vertical
    /*
    calendar.delegate = self
    calendar.pagingEnabled = false
    calendar.scrollDirection = .vertical
     */
}

func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
    CalendarViewModelScript.formatter.dateFormat = "EEEE MM-dd-YYYY"
    CalendarViewModelScript.output = CalendarViewModelScript.formatter.string(from: date)
    //let output = formatter.string(from: date)
    print("\(CalendarViewModelScript.output)")
}

}

Along with the other files, the Calendar View Controller currently having a FSCalendarDelegate - if that's permanent...

What, kind of flaws, I already know about my project

I know that I need to rename my variables involving the referencing in particular, and I know that the code needs to be cleaned up and of course I know that ll of the completely useless comments need to go (they're there because I'm migrating this from a previously not design patterned project to a project with MVPVM)

Extra info

In case it's relevant - which I don't think it is and you can see at the top of the code anyway - I'm using FScalendar...

AND A HUGE THANK YOU TO ANYONE IN ADVANCE TO ANYONE WHO EVEN ATTEMPTS TO HELP ME!

And be rest assured that I can most certainly clear anything up - if necessary

Aucun commentaire:

Enregistrer un commentaire