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 Foundation | |
import PlaygroundSupport | |
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil) | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
// Refer to the example: https://grokswift.com/simple-rest-with-swift/ | |
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todo/1" | |
guard let url = URL(string: todoEndpoint) else { | |
print("Error: cannot create URL") |
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
#!/bin/bash | |
# git pre-commit hook that runs an clang-format stylecheck. | |
# Features: | |
# - abort commit when commit does not comply with the style guidelines | |
# - create a patch of the proposed style changes | |
# modifications for clang-format by [email protected] | |
# This file is part of a set of unofficial pre-commit hooks available | |
# at github. |
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
#!/usr/bin/swift | |
// | |
// SelfPrinter.swift | |
// SelfPrinter | |
// | |
// Created by Lin Cheng Lung on 2018/6/25. | |
// Copyright © 2018 Lin Cheng Lung. All rights reserved. | |
// | |
import Foundation |
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
public class DramaInfo: NSObject, Codable { | |
@objc public let currentEpisode: Int | |
@objc public let episodeID: String | |
@objc public let name: String | |
@objc public let viewCount: Int | |
@objc public let totalEpisode: Int | |
enum CodingKeys: String, CodingKey { | |
case currentEpisode = "currentEps" | |
case episodeID = "id" |
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 Foundation | |
class FrameTimeintervalCollector { | |
private(set) lazy var displayLink: CADisplayLink = { //< 1. | |
let displayLink = CADisplayLink(target: self, selector: #selector(tick(displayLink:))) | |
displayLink.add(to: .main, forMode: .default) | |
return displayLink | |
}() | |
private(set) var frameTickTimeSet = Set<FrameTickTime>() //< 2. | |
private var lastTimestamp: TimeInterval = 0 |
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 Foundation | |
import XCTest | |
import QuartzCore | |
// 1. | |
@available(iOS 11.2.0, *) | |
class SlowFrameMetric: NSObject, XCTMetric { | |
private static let slowFrameThresholdInMiliSecond = 0.017 | |
private let frameTimeintervalCollector = FrameTimeintervalCollector() | |
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
// 1. | |
@available(iOS 13.0, *) | |
func testMeasureSPFCascadeScrollingAsAnXtraUser() { | |
// 2. | |
measure(metrics: [SlowFrameMetric()]) { | |
app.launch() | |
// interact with the app, like scrolling or swiping | |
app.terminate() |
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
// 1. | |
@available(iOS 13.0, *) | |
func testMeasureSPFCascadeScrollingAsAnXtraUser() { | |
let options = XCTMeasureOptions() | |
options.invocationOptions = [.manuallyStart, .manuallyStop] //< 2. | |
// 3. | |
measure(metrics: [SlowFrameMetric()], options: options) { | |
app.launch() |
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
/** | |
* @protocol XCTMetric | |
* Defines a protocol which may be used with the -measureWithMetrics* methods on XCTestCase. | |
* | |
* @discussion | |
* Classes conforming to XCTMetric must also adopt NSCopying, as a unique metric instance is copied for each iteration. | |
*/ | |
public protocol XCTMetric : NSCopying, NSObjectProtocol { | |
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
struct AStruct { | |
let letRefValue = "foo" | |
var varRefValue = "bar" | |
let letDataValue = 0 | |
var varDataValue = 0 | |
func changeLetRefValue() { | |
letRefValue = "hello" //< Cannot assign to property: 'letRefValue' is a 'let' constant | |
} |