uncleFedEx uncleFedEx - 3 months ago 22
Swift Question

Swift: How to pass NSView's array data to AppDelegate?

I need to pass an array of CGPoints from NSView.swift to AppDelegate.swift. What is the robust method to do that?

Answer

Update your AppDelegate.swift like this:

import Cocoa    
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

        var myArray : Array = [] // add this variable definition

    ...

This you will need to do in NSView.swift, when passing data to appDelegate.

let appDelegate = NSApplication.shared().delegate as! AppDelegate        
appDelegate.myArray = myArray