设置当前代理设置 [英] set current proxy settings
本文介绍了设置当前代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 SCDynamicStoreCopyProxies
来检索代理信息。我希望,一旦我有字典,我将能够设置当前代理设置。原来,由 SCDynamicStoreCopyProxies
返回的字典是只读的。如何更改当前的代理设置?
我到目前为止所做的是什么:
func setNet(){
let ds:SCDynamicStoreRef = SCDynamicStoreCreate(nil,setNetas
CFString,nil,nil)!
let list = SCDynamicStoreCopyProxies(ds)
print(list!)
如果let list = SCDynamicStoreCopyProxies(ds)as NSDictionary? {
如果let port = list [HTTPPort] as? Int {
print(HTTPPort:,port)
list [HTTPPort] = 8088; //错误,下标是get-only
}
}
}
要改变一个只读(aka不可变)字典使用 func mutableCopy() - > AnyObject
。
I used SCDynamicStoreCopyProxies
to retrieve proxy information. I was hoping that once I had the dictionary, I would be able to set current proxy settings. It turned out that the dictionary returned by SCDynamicStoreCopyProxies
is read only. How can I change current proxy settings?
What I have tried so far:
func setNet(){
let ds: SCDynamicStoreRef = SCDynamicStoreCreate(nil, "setNet" as
CFString, nil, nil)!
let list = SCDynamicStoreCopyProxies(ds)
print(list!)
if let list = SCDynamicStoreCopyProxies(ds) as NSDictionary? {
if let port = list["HTTPPort"] as? Int {
print("HTTPPort:", port)
list["HTTPPort"] = 8088; // error, subscript is get-only
}
}
}
解决方案
To change a "read only" (aka non-mutable) dictionary use func mutableCopy() -> AnyObject
.
这篇关于设置当前代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文