Adding items to NSArrayController causes EXC_BAD_INSTRUCTION

I've had the same problem for a few days now and it's been killing me. Whenever I run my script, I get a EXC_BAD_INSTRUCTION. It happens when I add an array of objects to an NSArrayController, bount to an NSTableView. Below is my code:


import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var window: NSWindow!

@IBOutlet weak var mainTabView: NSTabView!

@IBOutlet weak var tracksAC: NSArrayController!
@IBOutlet weak var albumsAC: NSArrayController!

func checkIfFileExists(atPath path: String, isDirectory: Bool = false, createIfNeeded createNew: Bool = false) -> Int {
    var isDir: ObjCBool = ObjCBool(isDirectory)

    if !FileManager.default.fileExists(atPath: path, isDirectory: &isDir) {
        if createNew {
            do {
                if isDirectory {
                    try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true)

                    FileManager.default.createFile(atPath: path, contents: nil)


                return 2

                return 3

            return 0


    return 1

func applicationDidFinishLaunching(_ aNotification: Notification) {
    //Create application support folder if it's not existent and populate with all needed files
    let paths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)
    let appSupportDir = paths[0] + "/Project Alpha"

    //Create application folder if needed
    let folderStatus = checkIfFileExists(atPath: appSupportDir, isDirectory: true, createIfNeeded: true)

    if folderStatus == 1 || folderStatus == 2 {
        _ = checkIfFileExists(atPath: appSupportDir + "/Songs.txt", createIfNeeded: true)
        _ = checkIfFileExists(atPath: appSupportDir + "/Albums.txt", createIfNeeded: true)
        _ = checkIfFileExists(atPath: appSupportDir + "/Genres.txt", createIfNeeded: true)

    //Populate tracks table view
    let tracks = getTracks()


    tracksAC.add(contentsOf: tracks) //This is where the error occures every time

func applicationWillTerminate(_ aNotification: Notification) {
    // Insert code here to tear down your application

@IBAction func openAlbumsTab(_ sender: NSToolbarItem) {
    mainTabView.selectTabViewItem(at: 1)



import Cocoa

class Track: NSObject {
func getLine() -> String? {
    let songsFilePath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)[0] + "/Project Alpha/Songs.txt"
    do {
        let content = try String(contentsOfFile: songsFilePath)

        let lines = content.components(separatedBy: "---===---")

        let line = lines.first(where: {$0.hasPrefix(String(self.identifier) + ";")})
        return line
        return nil

var identifier: Int

var name: String
var artist: String
var album: String
var genre: String
var vocals: String
var trackNumber: Int

init(line: String) {
    let items = line.components(separatedBy: ";")


    self.identifier = Int(items[0])! = String(items[1])
    self.artist = String(items[2])
    self.genre = String(items[3])
    self.vocals = String(items[4])
    self.album = String(items[5])
    self.trackNumber = Int(items[6])!


I have checked the getTracks function and normally it does return a list of Track objects, so I really don't know what's causing the error. The columns are bound to the array controller as shown via the link below: screenshot

Any help would be greatly appreciated. Thanks in advance.