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
    
  
  
    
  | // Very slightly adapted from http://stackoverflow.com/a/30141700/106244 | |
| // 99.99% Credit to Martin R! | |
| // Mapping from XML/HTML character entity reference to character | |
| // From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references | |
| private let characterEntities : [String: Character] = [ | |
| // XML predefined entities: | |
| """ : "\"", | |
| "&" : "&", | 
  
    
      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
    
  
  
    
  | // Line Height Bookmarklet | |
| // javascript:(function(lineHeight) %7B%0A if (window.guide) %7B%0A document.body.removeChild(window.guide)%3B%0A window.guide %3D null%3B%0A %7D else %7B%0A window.guide %3D document.createElement("div")%3B%0A guide.style.id %3D "grid_overlay"%3B%0A guide.style.position %3D "absolute"%3B%0A guide.style.left %3D "0"%3B%0A guide.style.top %3D "-1px"%3B%0A guide.style.width %3D "100%25"%3B%0A guide.style.height %3D (document.body.clientHeight > document.documentElement.clientHeight) %3F document.body.clientHeight %2B "px" %3A "100%25"%3B%0A guide.style.pointerEvents %3D "none"%3B%0A guide.style.userSelect %3D "none"%3B%0A guide.style.background %3D "linear-gradient(rgba(0%2C 119%2C 179%2C 0.2) 1px%2C transparent 1px) left top %2F " %2B lineHeight %2B " " %2B lineHeight%3B%0A document.body.appendChild(guide)%0A %7D%0A%7D)("27px")%3B%0A | |
| (function(lineHeight) { | |
| if (window.guide) { | |
| document.body.removeChild(window.guide); | |
| window.guide = | 
  
    
      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
    
  
  
    
  | struct ImageDescriptor<ImageReference> { | |
| var imageReference: ImageReference | |
| var properties: UIImageView.Properties | |
| } | |
| extension UIImageView { | |
| struct Properties { | |
| var contentMode: UIViewContentMode | |
| var backgroundColor: UIColor | |
| var tintColor: UIColor | 
  
    
      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 UIImageView { | |
| func apply(_ imageDescriptor: ImageDescriptor<UIImage>) | |
| func apply( | |
| _ imageDescriptor: ImageDescriptor<URL>, | |
| loading loadingImageDescriptor: ImageDescriptor<UIImage>? = nil, | |
| failure failureImageDescriptor: ImageDescriptor<UIImage>? = nil | |
| ) | |
| } | 
  
    
      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 UIImageView { | |
| func apply(_ imageDescriptor: ImageDescriptor<UIImage>) { | |
| cancelAnyExistingFetches() | |
| accessibilityIdentifier = imageDescriptor.properties.accessibilityIdentifier | |
| backgroundColor = imageDescriptor.properties.backgroundColor | |
| contentMode = imageDescriptor.properties.contentMode | |
| tintColor = imageDescriptor.properties.tintColor | |
| image = imageDescriptor.imageReference | |
| } | 
  
    
      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 ImageDescriptor where ImageReference == UIImage { | |
| static let logo = ImageDescriptor<UIImage>( | |
| imageReference: UIImage(named: "logo")!.withRenderingMode(.alwaysTemplate), | |
| properties: UIImageView.Properties( | |
| contentMode: .center, | |
| backgroundColor: .white, | |
| tintColor: .lightGray, | |
| accessibilityIdentifier: "logoImage" | |
| ) | |
| ) | 
  
    
      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
    
  
  
    
  | imageView.apply(.logo) | |
| imageView.apply( | |
| .productImage(with: URL(string: "http://my-image-url")!), | |
| loading: .loading, | |
| failure: .failure | |
| ) | 
  
    
      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
    
  
  
    
  | enum Material: String, Codable { | |
| case wood, metal, glass, other | |
| } | 
  
    
      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 Material { | |
| init(from decoder: Decoder) throws { | |
| let container = try decoder.singleValueContainer() | |
| let rawMaterial = try container.decode(String.self) | |
| self = Material(rawValue: rawMaterial) ?? .other | |
| } | |
| } | 
  
    
      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 RawRepresentable where RawValue: Decodable { | |
| init(from decoder: Decoder, default: Self) throws { | |
| let container = try decoder.singleValueContainer() | |
| let rawValue = try container.decode(RawValue.self) | |
| self = Self(rawValue: rawValue) ?? `default` | |
| } | |
| } |