Skip to content

Instantly share code, notes, and snippets.

Dave Wood DaveWoodCom

View GitHub Profile
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 Sep 21, 2018
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 whose fingerprint is DE5A 757A 9C17 31A4 5078 D0B4 1001 8549 63B1 C7CA

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.