我有一个用Objective c编写的代码,那么如何在swift中使用这段代码
NSString *dateString = [dic2 objectForKey:@"time"];
NSTimeInterval interval = [dateString doubleValue];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
NSDateFormatter *format = [[NSDateFormatter alloc]init];
[format setDateFormat:@"dd MMM, YYYY"];
NSString *datenewString = [format stringFromDate:date];
cellNotification.lbldatenotificationN.text = [NSString stringWithFormat:@"%@", datenewString];
任何帮助将不胜感激......
答案 0 :(得分:1)
您可以使用以下代码。
Swift 2.3
new Vue({
el: '#app',
data: {
skin: ''
},
methods: {
setSkin: function() {
this.skin = ...;
},
saveSkin: function() { // call this function when you need to save skin data into localStorage
window.localStorage.setItem("skin", this.skin);
....
}
},
mounted() {
this.setSkin(); // retrieve skin data from localStorage, etc.
}
});
swift 3.1
var dateString = (dic2["time"] as! String)
var interval = dateString.doubleValue
var date = NSDate(timeIntervalSince1970: interval)
var format = NSDateFormatter()
format.dateFormat = "dd MMM, YYYY"
var datenewString = format.stringFromDate(date)
cellNotification.lbldatenotificationN.text = "\(datenewString)"