I am working in xCode 10.2 with swift. I have created global variables in my first view controller for 6 tableviews. In storyboard, I have 6 tableViewControllers
. In a separate swift file, I have created a table struct to hold an array and display the data in each corresponding cell. In each view controller in didSelectRowAt
connects the next table view. My problem is when I get to the last table view. I need to associate website URLs to the array on the fifth table. I keep getting an error stating cannot convert string to URL. Please Help!
var fifthArray = [
FifthTableStruct(FifthTitle: ["Energy Guide", "https://www.google.com", "Warranty Page", "Use & Care Guide", "Specification Sheet", "FIT System", "Installation Instructions"]),
FifthTableStruct(FifthTitle: ["Energy Guide", "Warranty Page", "Use & Care Guide", "Specification Sheet", "FIT System", "Installation Instructions"])
]
var sixthArray = [
SixthTableStruct(SixthTitle: ["https://www.whirlpool.com/content/dam/global/documents/201708/EnergyGuide-W11037203-RevA.pdf", "https://www.whirlpool.com/content/dam/global/documents/201708/WarrantyPage-W11037201-W.pdf", "https://www.whirlpool.com/content/dam/global/documents/201708/UseandCareGuide-W11037201-RevA.pdf", "https://www.whirlpool.com/content/dam/global/documents/201711/WL170160A_p2.pdf", "https://www.whirlpool.com/content/dam/global/documents/201901/wash-performance-guarantee-en.pdf", "https://www.whirlpool.com/content/dam/global/documents/201711/InstallationInstructions-W10682737-RevA.pdf"])
]
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let urlString = self.sixthArray[indexPath.row]
if let url = URL(fileURLWithPath: urlString)
{
UIApplication.shared.openURL(url)
}
}
I have the code for the tableStruct in an Array file separate from the viewController.
import Foundation
import UIKit
struct SecondTableStruct {
var SecondTitle = [String]()
}
struct ThirdTableStruct {
var ThirdTitle = [String]()
}
struct FourthTableStruct {
var FourthTitle = [String]()
}
struct FifthTableStruct {
var FifthTitle = [String]()
}
struct SixthTableStruct {
var SixthTitle = [String]()
}