MacOS Structs, Constants, TableView Delegate (Implement a Variable) Question

The question: Is it possible to have a tableView delegate access a variable … ?

The applications sample test code is trying to do the following:

1.	The application is trying to make the first column number (a variable), requested by the applications main viewController, visibly stand out in the secondary viewControllers tableView with a large bold different colour font.

The application code:

1.	The applications main viewController (the engine) searches the tableView data source for column numbers, requested by the (USER).
2.	The applications secondary viewController receives the first column number with a (Notification) sent by the main viewController in viewDidLoad.
3.	The applications secondary viewController also identifies the (first column number) as a (Struct Constant) from (MyApplicationConstants_File.swift) in the tableView Delegate.
4.	The applications secondary viewController tableView (extension FirstViewController: NSTableViewDelegate) identifies the (first column number Notification) as zero (0).
5.	The applications secondary viewController tableView (extension FirstViewController: NSTableViewDelegate) identifies the (Struct Constant first column number).

I have not found literature to illustrate how to make a (variable) visible to the tableView with protocols or delegation, then again, I am not sure, just yet, whether implementing a protocol / delegate class design is the correct path to follow. A literature source with possible suggestions to modify a (variable) to behave like a (Struct Constant) within the tableView delegate would be welcome, and or the comment (not possible).

(Not possible) would allow me to shutdown this avenue of pursuit, gracefully.

Again as always, thank you, and best regards,

jim_k

The secondary viewController code:


The secondary tableView (first column number) code snippet:

                } else if tableColumn?.identifier == NSUserInterfaceItemIdentifier(rawValue: "firstColumn") {
                    /// The (USER) entered the number (10).
                    /// Identify the (STRUCT CONSTANT) for the (FIRST NUMBER).
                    /// This (STRUCT CONSTANT) from the constants Swift file is recognized.
                    let someFirstNumber = TheRequestedNumbersToFind.theFirstNumber
                    print("First Number Struct Constant Received :: \(someFirstNumber)")
                    // Prints :
                    // First Number Struct Constant Received :: 10

//                    /// Identify the (TRANSFERRED NOTIFICATION NUMBER) for the (FIRST NUMBER).
//                    /// The (TRANSFERRED NOTIFICATION NUMBER) is (10) but recognized as Zero (0).
//                    let someFirstNumber = theFirstNumberReceived
//                    print("THE TRANSFERRED NOTIFICATION NUMBER :: \(someFirstNumber)")
//                    // Prints :
//                    // THE TRANSFERRED NOTIFICATION NUMBER :: 0

                    /// Identify the tableView (theFirstNumberTextField)
                    let theFirstNumberTextField = Int32(twoNewArrayData[row].first)

                    /// Test the condition.
                    if (theFirstNumberTextField) != someFirstNumber {
                        /// This code identifies the (NOT EQUAL) correctly.  <=== No errors.
                        print("The (someFirstNumber) is (NOT EQUAL) to the (theFirstNumberTextField).")

                        /// Therefore continue to leave the (theFirstNumberTextField) unchanged.
                        cellView.textField?.intValue = Int32(twoNewArrayData[row].first)

                    } else {

                        /// The application is here because the condition was met, 
                        /// therefore change the (theFirstNumberTextField) font.
                        /// This code identifies the (EQUAL) correctly.
                        print("The (someFirstNumber) is (EQUAL) to the (theFirstNumberTextField).")

                        /// A few numbers (6, 12, 5) are marked incorrectly (Do not know why.)
                        /// Identify the (theFirstNumberTextField) to change.
                        cellView.textField?.intValue = Int32(twoNewArrayData[row].first)

                        /// Change the (TEXT FIELD COLOUR TO BLACK).
                        cellView.textField?.textColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)

                        /// Change the (TEXTFIELD FONT SIZE) with CGFloat.
                        /// The (ORIGINAL FONT SIZE) is set to (11).
                        let fontSize = 14
                        cellView.textField?.font = NSFont.boldSystemFont(ofSize: CGFloat(fontSize))

                    }   //  <=== End of *** if (theFirstNumberTextField) != someFirstNumber ***
                 } else if tableColumn?.identifier == NSUserInterfaceItemIdentifier(rawValue: "secondColumn") {
				  // (code continues for other column textFields)
			    }
				return nil
 } //  <=== End of *** func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? ***

As fate would have it, I managed to solve the issue a few hours after I posted the question :]

I changed my Struct code in the applications (Constants File) to new base values (I probably did not need to make the change.):

struct TheRequestedNumbersToFind {
    static var theFirstNumber  = 0      // <=== Previous value = (10)
    static let theSecondNumber = 0      // <=== Previous value = (13)
    static let theThirdNumber  = 0      // <=== Previous value = (15)
    static let theFourthNumber = 0      // <=== Previous value = (22)
    static let theFifthNumber  = 0      // <=== Previous value = (29)
    static let theSixthNumber  = 0      // <=== Previous value = (46)
    static let theSeventhNumber  = 0    // <=== Previous value = (3)
}

I discovered I could change the (Struct Static Variable) to equal the received variable in the applications (Notification):

         /// Identify the received (Notification) information for the tableView textField.
         let theTransferredFirstNumberReceived = notification.object
         if let theFirstNumberReceived = (theTransferredFirstNumberReceived as AnyObject) as? Int32 {
         /// Note: The (USER) entered the number (10).
         print("THE FIRST NUMBER RECEIVED :: \(Int32(theFirstNumberReceived)) \n")
         //  Prints: THE FIRST NUMBER RECEIVED = 10

         /// ASSIGN THE REQUESTED NUMBER TO THE (STRUCT VARIABLE) TO CHANGE THE (CONSTANTS FILE STRUCT VARIABLE).
         /// The "Int(theFirstNumberReceived)" must remain as "Int".
         TheRequestedNumbersToFind.theFirstNumber = Int(theFirstNumberReceived)
         print("THE REVISED FIRST STRUCT NUMBER RECEIVED :: \(Int32(TheRequestedNumbersToFind.theFirstNumber)) \n")
         // Prints :
         // THE REVISED FIRST STRUCT NUMBER RECEIVED :: 10
         }

I modified the tableView code for the (first column) to be :

       /// Identify the (STRUCT CONSTANT) for the (FIRST NUMBER).
       /// This (STRUCT CONSTANT) works because the constant is recognized
       /// Change the (STRUCT STATIC VARIABLE) to (EQUAL THE REQUESTED NUMBER).
       let someFirstNumber = TheRequestedNumbersToFind.theFirstNumber
       print("First Number Struct Variable Received :: \(someFirstNumber) \n")
       // Prints :
       // First Number Struct Variable Received :: 10

This change also removed the incremental errors with the static number (10), which allowed a few numbers not equal to (10), to be erroneously displayed as equal to (10).

I can now close this issue ... :]

Best regards,

jim_k

The code to illustrate better:


/// Keep the cellView.textField [AS THE ORIGINAL (IB) VALUES] when each [GREATER THAN] or [LESS THAN] conditional is met:
cellView.textField?.textColor = NSColor.white
/// Keep the cell font size at [11].
let fontSize = 11
cellView.textField?.font = NSFont.systemFont(ofSize: CGFloat(fontSize))

// Compared to the changed cellView.textField:

// Change the [TEXT FIELD COLOUR TO YELLOW] when the [cellView.textField IS EQUAL TO THE COMMON NUMBER] condition is met:
cellView.textField?.textColor = NSColor.systemYellow
// Change the (TEXTFIELD FONT SIZE) with CGFloat.
let fontSize = 12
cellView.textField?.font = NSFont.boldSystemFont(ofSize: CGFloat(fontSize))
MacOS Structs, Constants, TableView Delegate (Implement a Variable) Question
 
 
Q