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 Cocoa | |
import CoreImage | |
import CoreImage.CIFilterBuiltins | |
let nextButtonImage = NSImage(named: "next button")! | |
let startGameButtonImage = NSImage(named: "start game button")! | |
computeImageDifference(inputImage: nextButtonImage, inputImage2: startGameButtonImage) | |
// MARK: - |
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 | |
class MyViewController: UIViewController { | |
var name: String = "" { | |
didSet { | |
print("name = \(name)") | |
testLabel.text = name // 2 | |
} | |
} |
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
// Put this in a UITableViewCell or UICollectionViewCell subclass. | |
// Returns nil if point is not within the specified subviews. | |
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { | |
let subviews = [imageView, titleLabel, detailLabel, downloadButton] | |
for view in subviews { | |
if view.convert(view.bounds, to: self).contains(point) { | |
return super.hitTest(point, with: event) | |
} | |
} | |
return nil |
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
let layout = UICollectionViewCompositionalLayout(sectionProvider: { | |
(sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in | |
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: .estimated(30)) | |
let item = NSCollectionLayoutItem(layoutSize: itemSize) | |
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: .estimated(30)) |
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
let layout = UICollectionViewCompositionalLayout(sectionProvider: { | |
(sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in | |
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: .fractionalHeight(1.0)) | |
let item = NSCollectionLayoutItem(layoutSize: itemSize) | |
// (1) setting widthDimension to half of collectionView size | |
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.5), | |
heightDimension: .absolute(50)) |
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 APIClient { | |
// 1 - Error enum | |
enum APIClientError: Error { | |
case dataTaskFailed(Error) | |
case noHTTPURLResponse | |
case badHTTPStatusCode(HTTPURLResponse) | |
case noData |
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 UIKit | |
// From an example view hierarchy... | |
// 1 -> 2 -> 3 -> 4 -> 5 | |
// | | |
// ---> 6 | |
// Find the least common ancestor of 2 views. | |
// Input |
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
find /Applications -name "*.app" -user old-user -maxdepth 1 | tr \\n \\0 | xargs -0 sudo chown -R $USER |
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 | |
// Allows defining CodingKey from String | |
struct DynamicCodingKey: CodingKey { | |
var intValue: Int? | |
var stringValue: String | |
init?(intValue: Int) { | |
assertionFailure("Not implemented") | |
return nil |
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 | |
public extension Array { | |
// Iterate through all elements in pair tuples | |
// e.g. [1, 2, 3, 4].allPairs = [(1, 2), (2, 3), (3, 4)] | |
var allPairs: [(Element, Element)] { | |
var array: [(Element, Element)] = [] | |
for i in 0..<self.count - 1 { | |
array.append((self[i], self[i+1])) | |
} |
NewerOlder