Author: Chris Lattner
func queen(atFile file: Int, rank: Int) -> UInt64 { | |
0b00000001_00000001_00000001_00000001_00000001_00000001_00000001_00000001 << (file) | | |
0b00000000_00000000_00000000_00000000_00000000_00000000_00000000_11111111 << (rank * 8) | | |
0b10000000_01000000_00100000_00010000_00001000_00000100_00000010_00000001 >> ((file - rank) * 8) | | |
0b00000001_00000010_00000100_00001000_00010000_00100000_01000000_10000000 >> ((7 - file - rank) * 8) | |
} | |
func occupiedIndices(in board: UInt64) -> some Sequence<(file: Int, rank: Int)> { | |
sequence(state: (board, 0)) { state in | |
let offset = state.0.trailingZeroBitCount |
- (UIImage *)dynamicImage | |
{ | |
UITraitCollection *const baseTraitCollection = /* an existing trait collection */; | |
UITraitCollection *const lightTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]]]; | |
UITraitCollection *const purelyDarkTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]; | |
UITraitCollection *const darkTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, purelyDarkTraitCollection]]; | |
__block UIImage *lightImage; | |
[lightTraitCollection performAsCurrentTraitCollection:^{ | |
lightImage = /* draw image */; |
- Proposal: SE-XXXX
- Authors: Chris Lattner, Joe Groff
Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.
This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.
extension UIImage { | |
convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) { | |
let rect = CGRect(origin: .zero, size: size) | |
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0) | |
color.setFill() | |
UIRectFill(rect) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
guard let cgImage = image?.cgImage else { return nil } |
import UIKit | |
import GLKit | |
extension Float { | |
var radians: Float { | |
return GLKMathDegreesToRadians(self) | |
} | |
} | |
class Matrix4 { |
import UIKit | |
extension UIImage { | |
public func fixedOrientation() -> UIImage { | |
if imageOrientation == UIImageOrientation.up { | |
return self | |
} |
func getURL(ofPhotoWith mPhasset: PHAsset, completionHandler : @escaping ((_ responseURL : URL?) -> Void)) { | |
if mPhasset.mediaType == .image { | |
let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions() | |
options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in | |
return true | |
} | |
mPhasset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in | |
completionHandler(contentEditingInput!.fullSizeImageURL) | |
}) |
import Foundation | |
fileprivate protocol Statelike { | |
var stateMachine: StateMachine { get } | |
func logIn() | |
func logOut() | |
} | |
extension Statelike { | |
func logIn() {} |
Picking the right architecture = Picking the right battles + Managing trade-offs
- Clarify and agree on the scope of the system
- User cases (description of sequences of events that, taken together, lead to a system doing something useful)
- Who is going to use it?
- How are they going to use it?