Sorry for vague title.
Recent retiree, new to Mac (for photo purposes) and Swift. I have long history of coding for personal use, very comfortable with C#.Net.
I have a personal project that began as an Excel VBA workbook and grew into a standalone C# application. I changed to a Macbook and started to try to recreate it in Swift macOS. Then I quickly realized the shortage of current macOS info/tutorials compared to all the iOS stuff. Enough backstory.
I recreated the ‘macOS NSTableView Tutorial’ on this site with no trouble (nice explanations, btw) as well as from another site. My problem is I have a 2D 3 column array from a CSV file that I want to manipulate the data and display it in a table. I have everything fine, just trying to get the array as a data source.
@IBAction func openText(_ sender: Any) {
var fileOpened: String = ""
var fileOpened2: String = ""
let openPanel = NSOpenPanel()
openPanel.allowsMultipleSelection = true
openPanel.canChooseDirectories = false
openPanel.canChooseFiles = true
if (openPanel.runModal() == NSApplication.ModalResponse.OK) {
// Results contains an array with all the selected paths
let results = openPanel.urls
let myFile_a: String = results[0].path
let myFile_b: String = results[1].path
do {
fileOpened = try String(contentsOfFile: String("\(results[0].path)"))
fileOpened2 = try String(contentsOfFile: String("\(results[1].path)"))
} catch {
print("Error file couldn't be found")
}
var wholeArr = fileToArr(name:fileOpened)
var wholeArr2 = fileToArr(name:fileOpened2)
print("wholeArr: ",wholeArr[0][1])
print("wholeArr: ",wholeArr[1][1])
print("wholeArr2: ",wholeArr2[0][1])
print("wholeArr2: ",wholeArr2[1][1])
} else {
// "Canceled"
return
}
I have these in ViewDidLoad() as they’ve been there in every demo I’ve seen:
tableView.delegate = self
tableView.dataSource = self
This code (it’s a sloppy first draft, recreating the concept) only shows the arrays wholeArr and wholeArr2 that are returned from a function that reduces a 6 column row (with blank items) to 3. There are two because I’ll join two similar arrays. The print is there for debugging.
I tried to figure out how using the above mentioned tutorial, as well as several online docs. Apple makes great hardware, documentation isn’t their strong suit, unless you have a background in OS-X code.
Thanks in advance. Dan