I know that you have a working solution now but I thought I'd chime in with something a bit more general.
If you want more control over which parameters to append a minus sign to, you should look into the NSURLQueryItem
class (documented here).
You separate the URL into components by using the NSURLComponents
class (documented here) and can then get access to the queryItems
array.
So something like:
if let components = NSURLComponents(string: "http://www.corpebl.com/blog.php?show=250"),
let queryItems = components.queryItems {
}
Will give you a URL, split into components from your string and you have the query items in an array. Now you are ready to look at the individual queryItems:
for item in queryItems where item.value != nil {
//here you can check on the item.name
//and if that matches whatever you need, you can do your magic
}
So, a function that will just add a minus sign to all parameters and return a URL string from that could look something like this:
func addMinusToParameters(inURLString urlString: String) -> String? {
guard let components = NSURLComponents(string: urlString),
let queryItems = components.queryItems else {
return nil
}
var minusItems = [NSURLQueryItem]()
for item in queryItems where item.value != nil {
minusItems.append(NSURLQueryItem(name: item.name, value: "-\(item.value!)"))
}
components.queryItems = minusItems
guard let minusUrl = components.URL else {
return nil
}
return minusUrl.absoluteString
}
And an example:
if let minusString = addMinusToParameters(inURLString: "http://www.corpebl.com/blog.php?show=250&id=23") {
print(minusString) //gives you "http://www.corpebl.com/blog.php?show=-250&id=-23"
}
And yes, it might seem like more work but I think it is more flexible as well.
Hope you can use this.