Array Variable has no members in one section of code?

This is an Xcode 11 macOS project. I have a global variable called rowsFetched and it is a standard swift array, So for testing I have the following line of code after it has been set.
print("name = " + rowsFetched.CustName!)
In the function that sets rowsFetched it compiles fine and prints the line as expected.
However I tried to use the same line in my tableview delegate and it gets a compiler error saying no 'CustName' member. Also, in the tableview using debug I can see the rowsFetched array as expected and using print(rowsFetched) instead of print(rowsFetched.CustName!) and of course this prints the entire array.

What am I missing and any ideas how to to resolve this?


I was thinking some more specifics would help. So,Here is the code for the variable in question.

import Foundation
import GRDB

struct Customers {
    var id: Int64?
    var CustNumber: String?
    var CustName: String?
    var CustAddr: String?
    var CustCity: String?
    var CustState: String?
    var CustZip: String?
    var CustMobile: String?
    var CustEmail: String?
    var CustNotes: String?
    var CustAdded: Date?

extension Customers: Codable, FetchableRecord, MutablePersistableRecord {

    mutating func didInsert(with rowID: Int64, for column: String?) {
        id = rowID
extension Customers {

        private enum Columns {
            static let id = Column(
            static let CustName = Column(CodingKeys.CustName)
            static let CustAddr = Column(CodingKeys.CustAddr)
            static let CustCity = Column(CodingKeys.CustCity)
            static let CustState = Column(CodingKeys.CustState)
            static let CustZip = Column(CodingKeys.CustZip)
            static let CustMobile = Column(CodingKeys.CustMobile)
            static let CustEmail = Column(CodingKeys.CustEmail)
            static let CustNotes = Column(CodingKeys.CustNotes)
            static let CustAdded = Column(CodingKeys.CustAdded)
            static func custInit() -> [Customers] {
                let currentDate = Date()
                return ([Customers(id: 1, CustName: "", CustAddr: "", CustCity: "",
                                 CustState: "", CustZip: "", CustMobile: "",
                                 CustEmail: "", CustNotes: "", CustAdded: currentDate) ])

Here is where it is declared, in the ViewController as a global variable:

var rowsFetched: [Customers] = Customers.custInit()

Here is the function where it is set with customer rows and works as expected.

func getAllCustomers() -> [Customers] {

    do {
        try { db in
            let custlist = try Customers.fetchAll(db)
            rowsFetched = custlist
            //      print("name = " + rowsFetched.CustName!)
           //     print("Address = " + rowsFetched.CustAddr!)
    } catch {

So, if I try to use rowsFetched inside the code below it has no members
extension ViewController: NSTableViewDelegate {


All this code is attempting to do is get all the rows in customer database and populate a tableview.

Your array (rowsFetched) contains multiple Customers, and each customer has a CustName property, but the array itself does not have a CustName property. That's what the error message is telling you.

It's not clear what you're trying to print. An array of the customer names? In that case, you either need to iterate through the array, printing individual names. For example:

for customer in rowsFetched {

Or, create a temporary array of names, and print that array. For example:


Note that "member" in the error message refers to properties of the array type. It doesn't mean that the array value has no contents (elements). By contrast, your Customers struct type does have a CustName member.

Thanks Quincey, I now see where I was going wrong.