Skip to content

Instantly share code, notes, and snippets.

Dave Wood DaveWoodCom

Block or report user

Report or block DaveWoodCom

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
DaveWoodCom / TestProjectTests.swift
Created Jul 4, 2019
Xcode Test to test the performance of using a `for` loop with a `where` clause vs an `if` statement vs a `guard` statement.
View TestProjectTests.swift
// TestProjectTests.swift
// Tests
// Based on a question Nick Lockwood asked on Twitter: .
// And then followed up by GeekAndDad .
// These tests were executed on an iMac 5k, against an iOS project running in the XR Simulator.
// My results are included as comments in each test below. I ran the tests 5 times (which itself runs each test 10 times).
// The average of each 10 runs are listed below, as well as the placing 1st/2nd/3rd for each of the 3 styles.
View Bug.txt
Here's some sample code that works fine in Xcode 10.1, but fails to compile in 10.2 even though it's valid code.
The #if/#else/#endif code seems to be confusing the compiler and thus it is mixing up scope.
Xcode Version 10.2 (10E125) -> Broken
Xcode Version 10.1 (10B61) -> Works correctly
DaveWoodCom / set_swift_version.post_install.ruby
Created Oct 4, 2017
`post_install` hook to set the Swift version of pods (add to the end of your project's podfile)
View set_swift_version.post_install.ruby
post_install do |installer|
print "Setting the default SWIFT_VERSION to 4.0\n"
installer.pods_project.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
installer.pods_project.targets.each do |target|
if ['SomeTarget-iOS', 'SomeTarget-watchOS'].include? "#{target}"
print "Setting #{target}'s SWIFT_VERSION to 3.0\n"
target.build_configurations.each do |config|
DaveWoodCom / String+Email.swift
Last active Jul 27, 2019
Swift method to check for a valid email address (uses Apples data detector instead of a regex)
View String+Email.swift
extension String {
func isValidEmail() -> Bool {
guard !self.lowercaseString.hasPrefix("mailto:") else { return false }
guard let emailDetector = try? NSDataDetector(types: NSTextCheckingType.Link.rawValue) else { return false }
let matches = emailDetector.matchesInString(self, options: NSMatchingOptions.Anchored, range: NSRange(location: 0, length: self.characters.count))
guard matches.count == 1 else { return false }
return matches[0].URL?.scheme == "mailto"
DaveWoodCom /
Last active Jul 23, 2016
Script to fix Xcode 6.x so that it will run on El Capitan
## Copyright (C) 2015 Cerebral Gardens
## Permission is hereby granted, free of charge, to any person obtaining a copy of this
## software and associated documentation files (the "Software"), to deal in the Software
## without restriction, including without limitation the rights to use, copy, modify,
## merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
## permit persons to whom the Software is furnished to do so, subject to the following
## conditions:
DaveWoodCom / XCGTextViewLogDestination
Created Apr 16, 2015
An XCGLogDestination that adds the logs to a UITextView
View XCGTextViewLogDestination
extension XCGLogger {
public class XCGTextViewLogDestination: XCGLogDestinationProtocol, DebugPrintable {
public var owner: XCGLogger
public var identifier: String
public var outputLogLevel: XCGLogger.LogLevel = .Debug
public var showThreadName: Bool = false
public var showFileName: Bool = true
public var showLineNumber: Bool = true

Keybase proof

I hereby claim:

  • I am davewoodcom on github.
  • I am davewood ( on keybase.
  • I have a public key ASDVQq_MleuhYXva8i4Zs2Tt4yIJbtJx15W15Wd_Mx5Yfgo

To claim this, I am signing this object:

DaveWoodCom / gist:ce3a3a6467a7fc7a71a3
Created Aug 5, 2014
if optional != nil is fugly!
View gist:ce3a3a6467a7fc7a71a3
public extension Optional {
public var exists: Bool {
return (self != nil)
public var notExists: Bool {
return (self == nil)
DaveWoodCom / UIViewController+Alerts.h
Created Dec 31, 2012
UIViewController+Alerts Category for presenting a view controller with a transparency above another view controller
View UIViewController+Alerts.h
// UIViewController+Alerts.h
// Created by Dave Wood on 2012-01-17.
// Simplified BSD License
// Copyright (c) 2012, Cerebral Gardens
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
DaveWoodCom / clearCookies.m
Created Sep 19, 2012
Objective-C - clearCookies functions
View clearCookies.m
// By Dave Wood - Released into the Public Domain
+ (void)clearCookies
NSHTTPCookieStorage *httpCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *httpCookie in [httpCookieStorage cookies])
[httpCookieStorage deleteCookie:httpCookie];
[[NSUserDefaults standardUserDefaults] synchronize];
You can’t perform that action at this time.