ℹ️ This article is also available on his blog.
Layout and Drawing are two different things:
- Layout defines only the positions and sizes of all views on screen.
- Drawing specifies how each view is rendered (how it looks).
| // | |
| // A Swift property wrapper for adding "indirect" to struct properties. | |
| // Enum supports this out of the box, but for some reason struct doesn't. | |
| // | |
| // This is useful when you want to do something recursive with structs like: | |
| // | |
| // struct Node { | |
| // var next: Node? | |
| // } | |
| // |
| import Darwin | |
| import Foundation | |
| import UIKit | |
| // https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS17.1.sdk/System/Library/PrivateFrameworks/CoreSVG.framework/CoreSVG.tbd | |
| // https://developer.limneos.net/index.php?ios=17.1&framework=UIKitCore.framework&header=UIImage.h | |
| @objc | |
| class CGSVGDocument: NSObject { } |
ℹ️ This article is also available on his blog.
Layout and Drawing are two different things:
The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).
My take-aways are:
You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.
Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse
| // NSCalendar+Swift.swift | |
| // A set of Swift-idiomatic methods for NSCalendar | |
| // | |
| // (c) 2015 Nate Cook, licensed under the MIT license | |
| extension NSCalendar { | |
| /// Returns the hour, minute, second, and nanoseconds of a given date. | |
| func getTimeFromDate(date: NSDate) -> (hour: Int, minute: Int, second: Int, nanosecond: Int) { | |
| var (hour, minute, second, nanosecond) = (0, 0, 0, 0) | |
| getHour(&hour, minute: &minute, second: &second, nanosecond: &nanosecond, fromDate: date) |
| /// Observes a run loop to detect any stalling or blocking that occurs. | |
| /// | |
| /// This class is thread-safe. | |
| @interface GHRunLoopWatchdog : NSObject | |
| /// Initializes the receiver to watch the specified run loop, using a default | |
| /// stalling threshold. | |
| - (id)initWithRunLoop:(CFRunLoopRef)runLoop; | |
| /// Initializes the receiver to detect when the specified run loop blocks for |
| extension NSTimer { | |
| /** | |
| Creates and schedules a one-time `NSTimer` instance. | |
| - Parameters: | |
| - delay: The delay before execution. | |
| - handler: A closure to execute after `delay`. | |
| - Returns: The newly-created `NSTimer` instance. | |
| */ |
| #!/bin/sh | |
| UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal | |
| # make sure the output directory exists | |
| mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" | |
| # Step 1. Build Device and Simulator versions | |
| xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build | |
| xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build |
| #import "UICollectionViewFlowLayoutCenterItem.h" | |
| @implementation UICollectionViewFlowLayoutCenterItem | |
| - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity | |
| { | |
| CGSize collectionViewSize = self.collectionView.bounds.size; | |
| CGFloat proposedContentOffsetCenterX = proposedContentOffset.x + self.collectionView.bounds.size.width * 0.5f; | |
| CGRect proposedRect = self.collectionView.bounds; |
| /** @jsx React.DOM */ | |
| var MyComponent = React.createClass({ | |
| getInitialState: function() { | |
| // set up the initial state. used for "logical" initialization code | |
| return {perMinute: '-', perDay: '-'}; | |
| }, | |
| componentDidMount: function() { | |
| // fired only once, when the component is added to the DOM | |
| // used for initialization code that has "side effects" i.e. i/o, jquery plugins, etc | |
| var socket = io.connect(this.props.url); |