Created
          June 20, 2018 09:34 
        
      - 
      
 - 
        
Save Alexander-Ignition/450c5fb39040729f817d4fb83d9c97d5 to your computer and use it in GitHub Desktop.  
    Set additional property to URLRequest
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | extension URLRequest { | |
| func property(forKey key: String) -> Any? { | |
| return URLProtocol.property(forKey: key, in: self) | |
| } | |
| mutating func setProperty(_ value: Any, forKey key: String) { | |
| mutate { URLProtocol.setProperty(value, forKey: key, in: $0) } | |
| } | |
| mutating func removeProperty(forKey key: String) { | |
| mutate { URLProtocol.removeProperty(forKey: key, in: $0) } | |
| } | |
| private mutating func mutate(_ block: (NSMutableURLRequest) -> Void) { | |
| let mutableURLRequest = self as! NSMutableURLRequest | |
| block(mutableURLRequest) | |
| self = mutableURLRequest as URLRequest | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment