Skip to content

Instantly share code, notes, and snippets.

objective-c
po [[[UIWindow keyWindow] rootViewController] _printHierarchy]
swift
expr -l objc++ -O -- [[[UIWindow keyWindow] rootViewController] _printHierarchy]
@chriswill0w
chriswill0w / macos-recovery-server.md
Created February 20, 2018 23:51
Fixing "The recovery server could not be contacted" in MacOS High Sierra

I was trying to reinstall High Sierra on an older MacBook Air using internet recovery and I kept on getting an error message when trying to reinstall High Sierra.

The recovery server could not be contacted

It appears that this has to do with the time on the machine not being synchronized, so when the MacBook tries to reach out to the recovery server the certificates do not validate and we get this useless error message.

To fix this.

  1. Open up a Terminal from the utilities menu
  2. Enter the following command
var localized: String {
return NSLocalizedString(self, comment: "")
}
protocol CusotmEquatable {
func isEqual(to rhs: CusotmEquatable) -> Bool
}
extension CusotmEquatable where Self: Equatable {
func isEqual(to rhs: CusotmEquatable) -> Bool {
guard let rhs = rhs as? Self else {
return false
}
return self == rhs
let start = DispatchTime.now()
let end = DispatchTime.now()
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds // Difference in nano seconds (UInt64)
let timeInterval = Double(nanoTime) / 1_000_000_000 // Could overflow for long running tests
LogInfo("Time to generate pdf data: \(timeInterval) seconds")
// to run something in 0.1 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
// your code here
}
extension String {
public var isEmail: Bool {
let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let firstMatch = dataDetector?.firstMatch(in: self, options: .reportCompletion, range: NSRange(location: 0, length: count))
return (firstMatch?.range.location != NSNotFound && firstMatch?.url?.scheme == "mailto")
}
}
@chriswill0w
chriswill0w / discardableThumbnail.swift
Created November 14, 2017 00:27 — forked from benbahrenburg/discardableThumbnail.swift
UIImage that implements NSDiscardableContent
final class discardableThumbnail: NSDiscardableContent {
var thumbnail: UIImage!
var accessCounter: Int = 0
init(image: UIImage) {
thumbnail = image
}
func beginContentAccess() -> Bool {
if !(self.thumbnail != nil) {
private extension ObservableType {
func withPrevious(startWith first: E) -> Observable<(E, E)> {
return scan((first, first)) { ($0.1, $1) }.skip(1)
}
}