Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. extension URLRequest {
  2.  
  3. func property(forKey key: String) -> Any? {
  4. return URLProtocol.property(forKey: key, in: self)
  5. }
  6.  
  7. mutating func setProperty(_ value: Any, forKey key: String) {
  8. mutate { URLProtocol.setProperty(value, forKey: key, in: $0) }
  9. }
  10.  
  11. mutating func removeProperty(forKey key: String) {
  12. mutate { URLProtocol.removeProperty(forKey: key, in: $0) }
  13. }
  14.  
  15. private mutating func mutate(_ block: (NSMutableURLRequest) -> Void) {
  16. let mutableURLRequest = self as! NSMutableURLRequest
  17. block(mutableURLRequest)
  18. self = mutableURLRequest as URLRequest
  19. }
  20. }
Add Comment
Please, Sign In to add comment