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
    
  
  
    
  | // known confusing on Swift 2.1, Xcode 7.1 | |
| import Foundation | |
| public class InnerMutator { | |
| var f:(() -> Void)? | |
| } | |
| public struct MutableValue | |
| { | 
  
    
      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
    
  
  
    
  | /// Exposes all colors in a gradient, which is defined as usual by a finite number of color stops | |
| /// - version: known good on Xcode 7.1 playgrounds and iOS 9.1 | |
| class ColorGradient | |
| { | |
| // array of specified colors for specified locations along the gradient | |
| let colors:[UIColor] | |
| // array of specified locations (in 0...1) for the specified colors in the gradient | |
| let locations:[CGFloat] | |
| let gradientImage:UIImage | 
  
    
      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
    
  
  
    
  | /// Given `path`, drawn with `width`, returns a new path outlining its edges | |
| func pathOutliningPath(path:UIBezierPath, withWidth width:CGFloat, inSize size:CGSize) -> UIBezierPath | |
| { | |
| UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
| let ctx = UIGraphicsGetCurrentContext() | |
| CGContextSetLineWidth(ctx, width) | |
| CGContextAddPath(ctx, path.CGPath) | |
| CGContextReplacePathWithStrokedPath(ctx) | |
| let extractedCGPath = CGContextCopyPath(ctx) | |
| UIGraphicsEndImageContext() | 
  
    
      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
    
  
  
    
  | let v = UIView() | |
| // use `performSelector` to workaround that the method is private | |
| // use `takeRetainedValue` to get an AnyObject | |
| // use the forced cast because we know it's a string | |
| let s = v.performSelector("recursiveDescription").takeRetainedValue() as! String | |
| // convert the string to a fixed width font, so the quicklook is useful | |
| NSAttributedString(string: s, attributes: [UIFontDescriptorFeatureSettingsAttribute:[UIFontFeatureTypeIdentifierKey:kMonospacedTextSelector]]) | |
  
    
      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
    
  
  
    
  | //: Playground - noun: a place where people can play | |
| import UIKit | |
| /*: | |
| This playground shows a bug in how `NSAttributedString.boundingRectWithSize(_:options:context:)` handles attributed strings containing the LINE SEPARATOR character when the .UsesDeviceMetrics option is not included. | |
| When the `.UsesDeviceMetrics` option is set, the function is supposed to return the bounding rect where the height is what is required to bound the particular glyphs in the string. | 
  
    
      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
    
  
  
    
  | import UIKit | |
| //: # Paragraphs, lines, breaks, and spacing in attributed strings | |
| /*: | |
| The cocoa text system lets you separately adjust line spacing and paragraph spacing. | |
| This playground investigates a few questions concerning these spacing configurations and text layout: | |
| 1. Do empty UILabels collapse to zero height? | 
  
    
      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
    
  
  
    
  | // Swift 1.2 | |
| // synchronous JSON download | |
| import XCPlayground | |
| // my goodness all this complexity is just for an unconditional synchronous | |
| // get in a playground on HTTP or HTTPS and decoding to JSON. sad. | |
| public func waitUntilTrue(@autoclosure pred:()->Bool, secondsUntilTimeout duration:NSTimeInterval = 25) | |
| { | 
  
    
      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
    
  
  
    
  | // works as of Swift 1.2, 2015-08-29 | |
| // https://developer.apple.com/library/ios/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECNSURLSESSION | |
| class NSURLSessionAllowBadCertificateDelegate : NSObject, NSURLSessionDelegate | |
| { | |
| func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) | |
| { | |
| if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust | |
| { | 
  
    
      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
    
  
  
    
  | // in a playground, pause execution wait until the condition pred is true | |
| func waitUntilTrue(@autoclosure pred:()->Bool, secondsUntilTimeout duration:NSTimeInterval = 25) | |
| { | |
| let previousPlayGroundRunStatus = XCPExecutionShouldContinueIndefinitely() | |
| XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true) | |
| let start = NSDate() | |
| while true { | |
| if pred() { | |
| NSLog("condition met.") |