访问元组数组 Swift 4

Accessing an array of tuples Swift 4

我正在尝试为自定义 collection 视图单元格的某些组件赋值。该数组与自定义 collection 视图单元位于同一 class 中,但我无法接缝访问该数组。任何意见,将不胜感激。

import UIKit
import CoreLocation
class eventCell: UICollectionViewCell {

    @IBOutlet private weak var eventTitle: UILabel!
    @IBOutlet private weak var descriptionLabel:UILabel!
    @IBOutlet private weak var eventImage: UIImageView!

    var eventArray = [(title:String, location:String, lat:CLLocationDegrees, long:CLLocationDegrees)]()   

    override func prepareForReuse() {
        eventImage.image = nil
    }

    func lool() {
        eventTitle.text = eventArray.title
    }
}

然而,当我尝试添加标题时,我总是收到此错误:

Value of type '[(title: String, location: String, lat: CLLocationDegrees, long: CLLocationDegrees)]' (aka 'Array<(title: String, location: String, lat: Double, long: Double)>') has no member 'title'

任何帮助都将非常有用,在此先感谢!

为什么不创建一些 Struct? 像这样简单:

struct Event {
   var title: String
   var location: String
   var lat: CLLocationDegrees
   var long: CLLocationDegrees
}

那就这样吧:

var eventArray = [Event]()

然后这样称呼它:

for event in eventArray{
  event.title = eventTitle.text
}

你应该这样做:

class eventCell: UICollectionViewCell {
    @IBOutlet private weak var eventTitle: UILabel!
    @IBOutlet private weak var descriptionLabel:UILabel!
    @IBOutlet private weak var eventImage: UIImageView!

    typealias Event = (title:String, location:String, lat:CLLocationDegrees, long:CLLocationDegrees)

    var eventArray = [Event]()


    override func prepareForReuse() {
        eventImage.image = nil
    }

    func lool() {
        var event = Event(title: "a", location:"b", lat:5, long:4)
        eventArray.append(event)
        eventTitle.text = eventArray[0].title
    }
}