I am trying to show a random item of an array, I have this file :
//VerseModel.swift
import Foundation
struct VerseModel {
var verse = ""
var reference = ""
var date = Date()
}
this file:
//VersesMock.swift
import Foundation
struct VersesMock {
var verses: Array<VerseModel> = [
VerseModel(verse: "Teste 1", reference: "Mt 13:2", date: Date()),
VerseModel(verse: "Teste 2", reference: "Mt 14:2", date: Date()),
VerseModel(verse: "Teste 3", reference: "Mt 15:2", date: Date()),
VerseModel(verse: "Teste 4", reference: "Mt 16:2", date: Date()),
VerseModel(verse: "Teste 5", reference: "Mt 17:2", date: Date()),
VerseModel(verse: "Teste 6", reference: "Mt 18:2", date: Date()),
VerseModel(verse: "Teste 7", reference: "Mt 19:2", date: Date()),
VerseModel(verse: "Teste 8", reference: "Mt 20:2", date: Date()),
VerseModel(verse: "Teste 9", reference: "Mt 21:2", date: Date())
]
}
and this:
import UIKit
final class HomeViewController: UIViewController {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var verseLbl: UILabel!
var user = UserMock()
var verses = VersesMock().verses
override func viewDidLoad() {
super.viewDidLoad()
nameLabel.text = user.name
verseLbl.text = verseModel
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I am trying to do something like this, but it says
"Cannot assign value of type '[VerseModel]' to type 'String?'"
Yeah, I know I can't assign they because are from different types, so how can I assign them ?
My English is very bad, so if you see any grammatical error tell me in the comments.
Aucun commentaire:
Enregistrer un commentaire