Swift

  • Synchronized
  • Completion Handlers
  • Declare closure
  • @noescape
  • Memory management
  • Curried function in Swift (Alternated solution)

    func rideTypeFilter(type: RideType, fromRides rides: [Ride]) -> [Ride] {
      return rides.filter { $0.types.contains(type) }
    }
    
    func createRideTypeFilter(type: RideType) -> [Ride] -> [Ride] {
      return { (rides: [Ride]) -> [Ride] in
        return rideTypeFilter(type, fromRides: rides)
      }
    }
    
    let kidRideFilter = createRideTypeFilter(.Kids)
    
    print(kidRideFilter(parkRides))
    
  • Functional Programming in Swift 1

  • Functional Progrmming in Swift 2
  • Swift guide to map filter reduce
  • Map or Reduce with index
  • Using bridging headers with framework targets is unsupported
  • non-modular header inside framework module
  • Capture whole UICollecitonView

      let seconds = 10.0
      let delay = seconds * Double(NSEC_PER_SEC)  // nanoseconds per seconds
      let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
      // TODO: Simulate internel delay
      dispatch_after(dispatchTime, dispatch_get_main_queue(), { [weak self] in
          // Draw1
          let size = self?.dataSource.collectionView.contentSize
          UIGraphicsBeginImageContextWithOptions(size!, (self?.dataSource.collectionView.opaque)!, 0.0)
        self?.dataSource.collectionView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    
          // Draw2
          let heigh = (self?.dataSource.collectionView.contentSize.height)! - (self?.view.frame.height)! + 10
    
          let rect = CGRectMake(0, (self?.view.frame.height)!, CGRectGetWidth((self?.dataSource.collectionView.bounds)!), (self?.dataSource.collectionView.contentSize.height)! - heigh)
          self?.dataSource.collectionView.scrollRectToVisible(rect, animated: false)
          self?.dataSource.collectionView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    
          // Draw3
          let bottom = CGRectMake(0, heigh, CGRectGetWidth((self?.dataSource.collectionView.bounds)!), heigh)
          self?.dataSource.collectionView.scrollRectToVisible(bottom, animated: false)
          self?.dataSource.collectionView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    
          let image = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
    
          UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil);
      })
    
  • Swift pattern matching in detail
  • Global-vs-static-function-swift/
  • Swift Imports
  • solid-design-principle-using-swift

results matching ""

    No results matching ""