Permalink
Browse files

swift4适配

Signed-off-by: lettleprince <tong.decula@163.com>
  • Loading branch information...
lettleprince committed Nov 9, 2017
1 parent f820e6e commit 57efac72381e1b2bea670a98ba7c3dacc77692f9
@@ -40,7 +40,7 @@ class ProxySelectionViewController: FormViewController {
func generateForm() {
form.delegate = nil
form.removeAll()
proxies = defaultRealm.objects(Proxy).sorted(byProperty: "createAt").map{ $0 }
proxies = defaultRealm.objects(Proxy).sorted(byKeyPath: "createAt").map{ $0 }
form +++ Section("Proxy".localized())
let sets = proxies.filter { $0.name != nil }
for proxy in sets {
@@ -52,7 +52,7 @@ class RuleSetsSelectionViewController: FormViewController {
func generateForm() {
form.delegate = nil
form.removeAll()
ruleSets = defaultRealm.objects(RuleSet.self).sorted(byProperty: "createAt").map({ $0 })
ruleSets = defaultRealm.objects(RuleSet.self).sorted(byKeyPath: "createAt").map({ $0 })
form +++ Section("Rule Set".localized())
for ruleSet in ruleSets {
form[0]
@@ -94,7 +94,7 @@ class ConfigGroupChooseVC: UIViewController, UITableViewDataSource, UITableViewD
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateUI()
token = groups.addNotificationBlock { [unowned self] (changed) in
token = groups.observe { [unowned self] (changed) in
switch changed {
case let .update(_, deletions: deletions, insertions: insertions, modifications: modifications):
self.tableView.beginUpdates()
@@ -113,7 +113,7 @@ class ConfigGroupChooseVC: UIViewController, UITableViewDataSource, UITableViewD
override func viewWillDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
token?.stop()
token?.invalidate()
}
func onVPNStatusChanged() {
@@ -38,7 +38,7 @@ class RuleSetListViewController: UIViewController, UITableViewDataSource, UITabl
navigationItem.title = "Rule Set".localized()
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(add))
reloadData()
token = ruleSets.addNotificationBlock { [unowned self] (changed) in
token = ruleSets.observe { [unowned self] (changed) in
switch changed {
case let .update(_, deletions: deletions, insertions: insertions, modifications: modifications):
self.tableView.beginUpdates()
@@ -58,7 +58,7 @@ class RuleSetListViewController: UIViewController, UITableViewDataSource, UITabl
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
token?.stop()
token?.invalidate()
}
func reloadData() {
@@ -238,40 +238,40 @@ extension Manager {
}
func generateSocksConfig() throws {
let root = NSXMLElement.element(withName: "antinatconfig") as! NSXMLElement
let interface = NSXMLElement.element(withName: "interface", children: nil, attributes: [NSXMLNode.attribute(withName: "value", stringValue: "127.0.0.1") as! DDXMLNode]) as! NSXMLElement
let root = XMLElement.element(withName: "antinatconfig") as! XMLElement
let interface = XMLElement.element(withName: "interface", children: nil, attributes: [XMLNode.attribute(withName: "value", stringValue: "127.0.0.1") as! DDXMLNode]) as! XMLElement
root.addChild(interface)
let port = NSXMLElement.element(withName: "port", children: nil, attributes: [NSXMLNode.attribute(withName: "value", stringValue: "0") as! DDXMLNode]) as! NSXMLElement
let port = XMLElement.element(withName: "port", children: nil, attributes: [XMLNode.attribute(withName: "value", stringValue: "0") as! DDXMLNode]) as! XMLElement
root.addChild(port)
let maxbindwait = NSXMLElement.element(withName: "maxbindwait", children: nil, attributes: [NSXMLNode.attribute(withName: "value", stringValue: "10") as! DDXMLNode]) as! NSXMLElement
let maxbindwait = XMLElement.element(withName: "maxbindwait", children: nil, attributes: [XMLNode.attribute(withName: "value", stringValue: "10") as! DDXMLNode]) as! XMLElement
root.addChild(maxbindwait)
let authchoice = NSXMLElement.element(withName: "authchoice") as! NSXMLElement
let select = NSXMLElement.element(withName: "select", children: nil, attributes: [NSXMLNode.attribute(withName: "mechanism", stringValue: "anonymous") as! DDXMLNode]) as! NSXMLElement
let authchoice = XMLElement.element(withName: "authchoice") as! XMLElement
let select = XMLElement.element(withName: "select", children: nil, attributes: [XMLNode.attribute(withName: "mechanism", stringValue: "anonymous") as! DDXMLNode]) as! XMLElement
authchoice.addChild(select)
root.addChild(authchoice)
let filter = NSXMLElement.element(withName: "filter") as! NSXMLElement
let filter = XMLElement.element(withName: "filter") as! XMLElement
if let upstreamProxy = upstreamProxy {
let chain = NSXMLElement.element(withName: "chain", children: nil, attributes: [NSXMLNode.attribute(withName: "name", stringValue: upstreamProxy.name) as! DDXMLNode]) as! NSXMLElement
let chain = XMLElement.element(withName: "chain", children: nil, attributes: [XMLNode.attribute(withName: "name", stringValue: upstreamProxy.name) as! DDXMLNode]) as! XMLElement
switch upstreamProxy.type {
case .Shadowsocks:
let uriString = "socks5://127.0.0.1:${ssport}"
let uri = NSXMLElement.element(withName: "uri", children: nil, attributes: [NSXMLNode.attribute(withName: "value", stringValue: uriString) as! DDXMLNode]) as! NSXMLElement
let uri = XMLElement.element(withName: "uri", children: nil, attributes: [XMLNode.attribute(withName: "value", stringValue: uriString) as! DDXMLNode]) as! XMLElement
chain.addChild(uri)
let authscheme = NSXMLElement.element(withName: "authscheme", children: nil, attributes: [NSXMLNode.attribute(withName: "value", stringValue: "anonymous") as! DDXMLNode]) as! NSXMLElement
let authscheme = XMLElement.element(withName: "authscheme", children: nil, attributes: [XMLNode.attribute(withName: "value", stringValue: "anonymous") as! DDXMLNode]) as! XMLElement
chain.addChild(authscheme)
default:
break
}
root.addChild(chain)
}
let accept = NSXMLElement.element(withName: "accept") as! NSXMLElement
let accept = XMLElement.element(withName: "accept") as! XMLElement
filter.addChild(accept)
root.addChild(filter)
@@ -121,7 +121,7 @@ extension DBUtils {
res = res.filter(filter)
}
if let sorted = sorted {
res = res.sorted(byProperty: sorted)
res = res.sorted(byKeyPath: sorted)
}
return res
}
@@ -134,7 +134,7 @@ extension DBUtils {
}
var res = mRealm.objects(type).filter(mFilter)
if let sorted = sorted {
res = res.sorted(byProperty: sorted)
res = res.sorted(byKeyPath: sorted)
}
return res.first
}

0 comments on commit 57efac7

Please sign in to comment.