hello I am new to programming. So I have some basic questions and then I need the solution of the problem which I am having.
I have created a Model Class
class Trip: NSObject {
var tripTitle: String
var tripSummary: String
static var trips = [Trip]()
init(tripTitle: String, tripSummary: String) {
self.tripTitle = tripTitle
self.tripSummary = tripSummary
}
class func addTrip(tripTitle: String, tripSummary: String){
let t = Trip(tripTitle: tripTitle, tripSummary: tripSummary)
trips.append(t)
}
}
TripsDetailController
@IBAction func previewButtomPressed(sender: UIButton) {
let tripTitle = tripTitleTxt.text!
let tripSummary = tripSummaryTxt.text!
Trip.addTrip(tripTitle, tripSummary: tripSummary)
// let optionaltrip = Trip(tripTitle: tripTitle, tripSummary: tripSummary)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowTripPreviewTableViewController" {
let tripPreviewTableViewController = segue.destinationViewController as! TripPreviewTableViewController
// how can I pass the object here
}
}
how can I pass the object in segue
tripPreviewTableViewController
In this class I know I have to declare a variable here also but don't know what would be the datatype and also how can I access the value
and also I want to know what would be the best approach from these two
Trip.addTrip(tripTitle, tripSummary: tripSummary)
or
let trip = Trip(tripTitle: tripTitle, tripSummary: tripSummary)
should I have to create an array and assign values or go to the second method of creating an object