设置当前代理设置

时间:2016-03-23 10:25:09

标签: macos cocoa

我使用SCDynamicStoreCopyProxies来检索代理信息。我希望,一旦我有了字典,我就可以设置当前的代理设置。原来,SCDynamicStoreCopyProxies返回的字典是只读的。如何更改当前的代理设置?

到目前为止我尝试过:

 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
            }
        }
}

1 个答案:

答案 0 :(得分:0)

要更改“只读”(又名非变异)字典,请使用func mutableCopy() -> AnyObject