我已經更新了我的代碼從SWIFT 2.3至3迅速得到&許多錯誤移除所有的人,但來到這裏卡住問題,同時迅速從2.3遷移到SWIFT 3
我得到錯誤的didSelectRowAt indexPath:中IndexPath UITableView的
任務:我打了數據API和實現代碼如下其工作正常填充數據,但我想保存這一切是在swift2.3爲我工作在didSelectRowAtIndexPath方法數據
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected ")
//print(self.searchflightsandfares[indexPath.row] as SearchFlightsAndFares)
let data: NSData
// data = NSKeyedArchiver.archivedData(withRootObject: self.searchflightsandfares[indexPath.row].airlineCodeOneWay)
data = NSKeyedArchiver.archivedData(withRootObject: self.searchflightsandfares[indexPath.row]) as SearchFlightsAndFares
//Set Data
UserDefaults.standard.set(data, forKey: "selectedFlightDetailData")
SelectedFlightDetailsVC()
}
模型類是:
import UIKit
import Foundation
class SearchFlightsAndFares:NSObject{
//segment data
var segmentaDataForDetailScreen:[NSDictionary]
var fareDataFromFlight:Dictionary<String, AnyObject>
//Flight Details -One Way
var airlineCodeOneWay: String? //for list view
var airlineNameOneWay: String? //for list view
var airlineCodeOneWaySegment:String? //for Detail view
var airlineNameOneWaySegment:String? //for Detail view
….more code …
init(fareDataFromFlight: Dictionary<String, AnyObject>,
segmentaDataForDetailScreen: [NSDictionary],
airlineCodeOneWay: String, //for list view
airlineNameOneWay: String, //for list view
airlineCodeOneWaySegment: String, //Flight Number one way
airlineNameOneWaySegment: String,
….more code …
{
self.fareDataFromFlight = fareDataFromFlight
self.segmentaDataForDetailScreen = segmentaDataForDetailScreen
//One Way
self.airlineCodeOneWay = airlineCodeOneWay
self.airlineNameOneWay = airlineNameOneWay
self.airlineCodeOneWaySegment = airlineCodeOneWaySegment
}
init(espDictionary: [String : AnyObject])
{
logic for assignment from API to InIt Variables //….more code …
}
required init(coder aDecoder: NSCoder) {
self.fareDataFromFlight = (aDecoder.decodeObject(forKey: "fareDataFromFlight") as? Dictionary<String, AnyObject>)!
self.segmentaDataForDetailScreen = (aDecoder.decodeObject(forKey: "segmentaDataForDetailScreen") as? [NSDictionary])!
//One Way
self.airlineCodeOneWay = aDecoder.decodeObject(forKey: "airlineCodeOneWay") as? String
self.airlineNameOneWay = aDecoder.decodeObject(forKey: "airlineNameOneWay") as? String
self.airlineCodeOneWaySegment = aDecoder.decodeObject(forKey: "airlineCodeOneWaySegment") as? String
self.airlineNameOneWaySegment = aDecoder.decodeObject(forKey: "airlineNameOneWaySegment") as? String
….more code …
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encode(self.fareDataFromFlight, forKey: "fareDataFromFlight")
aCoder.encode(self.segmentaDataForDetailScreen, forKey: "segmentaDataForDetailScreen")
//One way
aCoder.encode(self.airlineCodeOneWay, forKey: "airlineCodeOneWay")
aCoder.encode(self.airlineNameOneWay, forKey: "airlineNameOneWay")
aCoder.encode(self.airlineCodeOneWaySegment, forKey: "airlineCodeOneWaySegment")
aCoder.encode(self.airlineNameOneWaySegment, forKey: "airlineNameOneWaySegment")
….more code …
}
加減速碼 –