Я новичок в программировании XCode, и я столкнулся с этой ошибкой, работая над проектом Dictionary UISplitViewController.Я создал класс «Word» и функцию, однако, когда я пытаюсь собрать их в AppDelegate.swift, я получаю следующую ошибку: «Значение типа DetailViewController не имеет члена« word »».
Каждый выход уже правильно связан с каждой их меткой в контроллере подробного представления на главной доске.
//"Word" class
class Word {
let name: String
let meaning: String
let numberOfTimesTapped: String
init(name: String, meaning: String, numberOfTimesTapped: String) {
self.name = name
self.meaning = meaning
self.numberOfTimesTapped = numberOfTimesTapped
}
}
//"words" function in the DetailViewController.swift
import UIKit
let words = [
Word(name: "Home", meaning: "A place where one lives", numberOfTimesTapped: "5"),
Word(name: "Place", meaning: "A particular position, point, or area in space; a location.", numberOfTimesTapped: "3"),
Word(name: "Like", meaning: "Having the same characteristics or qualities as; similar to.", numberOfTimesTapped: "1")
]
class DetailViewController: UIViewController {
class Word {
let name: String
let meaning: String
let numberOfTimesTapped: String
init(name: String, meaning: String, numberOfTimesTapped: String) {
self.name = name
self.meaning = meaning
self.numberOfTimesTapped = numberOfTimesTapped
}
}
@IBOutlet weak var WordLabel: UILabel!
@IBOutlet weak var DescriptionLabel: UILabel!
@IBOutlet weak var NumberOfTimesTappedLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
var word: Word? {
didSet {
refreshUI()
}
}
func refreshUI() {
loadViewIfNeeded()
WordLabel.text = word?.name
DescriptionLabel.text = word?.meaning
NumberOfTimesTappedLabel.text = word?.numberOfTimesTapped
}
//Content inside of MasterViewController.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
guard let splitViewController = window?.rootViewController as? UISplitViewController,
let leftNavController = splitViewController.viewControllers.first as? UINavigationController,
let masterViewController = leftNavController.topViewController as? MasterViewController,
let detailViewController = splitViewController.viewControllers.last as? DetailViewController
else { fatalError() }
let firstWord = masterViewController.words.first
detailViewController.word = firstWord //THIS IS WHERE I GET THE ERROR "Value of type 'DetailViewController' has no member 'word'"
return true
}