Swift3 URL不接受带有或(|)参数swift 3的查询字符串

Swift3 URL不接受带有或(|)参数swift 3的查询字符串,swift3,nsurl,Swift3,Nsurl,我正在尝试使用多种类型实现nearbysearch Google web服务,如查询type=department\u store |杂货店|或超市 所以,我准备了一个查询字符串,如下所述,它在浏览器上运行良好 let query = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.965198333333333,77.98569833333333&radius=3218&type

我正在尝试使用多种类型实现nearbysearch Google web服务,如查询type=department\u store |杂货店|或超市

所以,我准备了一个查询字符串,如下所述,它在浏览器上运行良好

let query = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.965198333333333,77.98569833333333&radius=3218&type=department_store|grocery_or_supermarket&key=API_KEY"
当我试图将其转换为下面提到的URL时,会出现错误“URL无效”,因为URL不接受带有或(|)参数的查询字符串

guard let url = URL(string: query) else { return completion(.Failure("URL invalid")) }
虽然它可以很好地与单一类型 类型=百货商店

let query = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.965198333333333,77.98569833333333&radius=3218&type=grocery_or_supermarket&key=API_KEY"
请建议,如何在nearbysearch web服务中使用多种类型

提前感谢。

添加百分比编码:

guard let escapedQuery = query.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed),
      let url = URL(string: escapedQuery) else { return completion(.Failure("URL invalid")) }