App architecture
- https://www.raywenderlich.com/709-ios-unit-testing-and-ui-testing-tutorial
- https://medium.com/flawless-app-stories/applying-unit-tests-to-mvvm-with-swift-ba5a79df8a18
- https://www.swiftbysundell.com/posts/reducing-flakiness-in-swift-tests
- https://medium.com/cocoaacademymag/unit-testing-uiview-with-nimble-snapshot-651a7c5a5e93
- https://medium.com/cocoaacademymag/unit-testing-parsing-a-json-response-b694a1b669ff
- https://medium.com/cocoaacademymag/unit-testing-uitableview-2387f3a42b4f
- http://adamborek.com/rxtests-rxactionsheet/
struct Todo: Decodable {
let userId: Int
let id: Int
let title: String
let completed: Bool
}
func getToDoItems(completionHandler: @escaping ([Todo]) -> Void) {
Resources
- https://fluffy.es/closure-overview/
- https://grokswift.com/completion-handler-faqs/
- http://alisoftware.github.io/swift/closures/2016/07/25/closure-capture-1/
- https://www.andrewcbancroft.com/2017/04/26/what-in-the-world-is-an-escaping-closure-in-swift/
- https://medium.com/@stremsdoerfer/understanding-memory-leaks-in-closures-48207214cba
- https://blog.bobthedeveloper.io/swift-capture-list-in-closures-e28282c71b95
import Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
var value: Int = 2 | |
let concurrentQueue = DispatchQueue(label: "queue", attributes: .concurrent) | |
concurrentQueue.async(flags: .barrier) { |
final class LoopedVideoPlayerView: UIView { | |
fileprivate var videoURL: URL? | |
fileprivate var queuePlayer: AVQueuePlayer? | |
fileprivate var playerLayer: AVPlayerLayer? | |
fileprivate var playbackLooper: AVPlayerLooper? | |
func prepareVideo(_ videoURL: URL) { | |
let playerItem = AVPlayerItem(url: videoURL) |
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
import CoreData | |
let context = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) | |
class Book: NSManagedObject { | |
var title: String? | |
var author: Author? | |
var date: Date? | |
} |
public func CVPixelBufferGetPixelFormatName(pixelBuffer: CVPixelBuffer) -> String { | |
let p = CVPixelBufferGetPixelFormatType(pixelBuffer) | |
switch p { | |
case kCVPixelFormatType_1Monochrome: return "kCVPixelFormatType_1Monochrome" | |
case kCVPixelFormatType_2Indexed: return "kCVPixelFormatType_2Indexed" | |
case kCVPixelFormatType_4Indexed: return "kCVPixelFormatType_4Indexed" | |
case kCVPixelFormatType_8Indexed: return "kCVPixelFormatType_8Indexed" | |
case kCVPixelFormatType_1IndexedGray_WhiteIsZero: return "kCVPixelFormatType_1IndexedGray_WhiteIsZero" | |
case kCVPixelFormatType_2IndexedGray_WhiteIsZero: return "kCVPixelFormatType_2IndexedGray_WhiteIsZero" | |
case kCVPixelFormatType_4IndexedGray_WhiteIsZero: return "kCVPixelFormatType_4IndexedGray_WhiteIsZero" |
import UIKit | |
import ImageIO | |
import MobileCoreServices | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
func report_memory() -> UInt64 { | |
var taskInfo = mach_task_basic_info() | |
var count = mach_msg_type_number_t(MemoryLayout<mach_task_basic_info>.size)/4 |