This file contains 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
With my case how I mock the static variable and I hope this can help you, here is my workaround: | |
For example, I have a static `count` value in production code: | |
``` | |
@implementation MyClass | |
static int _count = 0; | |
- (int)viewDidAppearCount { |
This file contains 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
- (void)testCacheSnapshotCombinations { | |
for (int i = 0; i < 32; i++) { | |
@autoreleasepool { | |
//Given: | |
UIImage *snapshotImage = [UIImage new]; | |
id image = OCMClassMock([UIImage class]); | |
OCMStub([image imageForView:OCMOCK_ANY]).andReturn(snapshotImage); | |
if (i & (1 << 0)) { | |
self.sut.bounds = CGRectMake(0, 0, 123, 456); |
This file contains 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
- (void)applicationDidEnterBackground:(UIApplication *)application { | |
@weakify(self); | |
self.backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{ | |
@strongify(self); | |
[application endBackgroundTask:self.backgroundTaskIdentifier]; | |
self.backgroundTaskIdentifier = UIBackgroundTaskInvalid; | |
}]; | |
} | |
- (void)testApplicationDidEnterBackgroundExpirationHandler { |
This file contains 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 <XCTest/XCTest.h> | |
#import "Dispatcher.h" | |
#import <ReactiveObjC/ReactiveObjC.h> | |
@interface Dispatcher () | |
@property(nonatomic, assign) void (*dispatchMethod)(dispatch_queue_t, dispatch_block_t); | |
@property(nonatomic, strong) dispatch_queue_t queue; | |
@end |
This file contains 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
// | |
// A -> B -> C -> D | |
// `keepFirst`: A | |
// `keepLast`: D | |
// | |
enum DebouncerType { | |
case keepFirst | |
case keepLast | |
} |
This file contains 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
class ViewController: UIViewController { | |
var statusBarHidden: Bool = false { | |
didSet { | |
UIView.animate(withDuration: 0.25) { [weak self] in | |
self?.setNeedsStatusBarAppearanceUpdate() | |
} | |
} | |
} | |
override var prefersStatusBarHidden: Bool { |
This file contains 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 | |
extension UIViewController { | |
var segueIdentifiers: [String] { | |
return (self.value(forKey: "storyboardSegueTemplates") as? [AnyObject])?.flatMap({ $0.value(forKey: "identifier") as? String }) ?? [] | |
} | |
} |
This file contains 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
extension Date { | |
var timeAgoSimple: String { | |
let deltaSeconds = fabs(timeIntervalSince(Date())) | |
let deltaMinutes = deltaSeconds / 60.0 | |
if deltaSeconds < 60 { | |
return "\(Int(deltaSeconds))s" | |
} else if deltaMinutes < 60 { | |
return "\(Int(deltaMinutes))m" | |
} else if deltaMinutes < (24 * 60) { |
This file contains 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
// | |
// AssetRecorderView.swift | |
// Snowball | |
// | |
// Created by Le Tai on 7/20/16. | |
// Copyright © 2016 Snowball. All rights reserved. | |
// | |
import UIKit | |
import AVFoundation |
This file contains 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 ImageIO | |
import AVFoundation | |
var cvPixelBuffer: CVPixelBuffer? { | |
var pixelBuffer: CVPixelBuffer? = nil | |
let options: [NSObject: Any] = [ | |
kCVPixelBufferCGImageCompatibilityKey: false, | |
kCVPixelBufferCGBitmapContextCompatibilityKey: false, | |
] | |
let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(size.width), Int(size.height), kCVPixelFormatType_32BGRA, options as CFDictionary, &pixelBuffer) |