emmm
由于没啥人解答 我动了动脑子 试出了这个办法
刚学 swift 和 swiftui 3 天 代码水平一言难尽 希望大家多提意见
pwnedInfo:
{
data = "Passwords, Email addresses";
date = "2017-04-15";
title = Youku;
url = "
https://monitor.firefox.com/breach-details/Youku";
},
{
data = "Email addresses";
date = "2016-06-30";
title = Tianya;
url = "
https://monitor.firefox.com/breach-details/Tianya";
},
{
data = "Passwords, IP addresses";
date = "2015-10-26";
title = 000webhost;
url = "
https://monitor.firefox.com/breach-details/000webhost";
}
var pwnedInfo: NSMutableArray = []
var pwnedInfoDict: [String: [String: String]] = [:]
var id: Int = 0
for i in pwnedInfo {
pwnedInfoDict[String(id)] = (i as? [String: String])
id = id + 1
}
swiftUI 相关代码:
struct showInfo: View {
@
Binding var popoverIsShown: Bool
var body: some View {
let keys = pwnedInfoDict.map { $0.key }
let values = pwnedInfoDict.map { $0.value }
List {
ForEach(keys.indices) { index in
// var x = print((values[index]))
let title = (values[index]["title"]!)
if values[index]["date"] != nil {
let date = (values[index]["date"]!)
}
if values[index]["data"] != nil {
let data = (values[index]["data"]!)
}
let url = (values[index]["url"]!)
}
}
}
}