String+Extension.swift 537 B

1234567891011121314151617181920212223
  1. //
  2. // String+Extension.swift
  3. // Bark
  4. //
  5. // Created by huangfeng on 2018/6/26.
  6. // Copyright © 2018 Fin. All rights reserved.
  7. //
  8. import UIKit
  9. extension String {
  10. // 将原始的url编码为合法的url
  11. func urlEncoded() -> String {
  12. let encodeUrlString = self.addingPercentEncoding(withAllowedCharacters:
  13. .urlQueryAllowed)
  14. return encodeUrlString ?? ""
  15. }
  16. // 将编码后的url转换回原始的url
  17. func urlDecoded() -> String {
  18. return self.removingPercentEncoding ?? ""
  19. }
  20. }