Skip to content

Instantly share code, notes, and snippets.

View DaveWoodCom's full-sized avatar
🇨🇦

Dave Wood DaveWoodCom

🇨🇦
View GitHub Profile
@DaveWoodCom
DaveWoodCom / fixXcode6OnElCapitan.sh
Last active September 8, 2023 21:02
Script to fix Xcode 6.x so that it will run on El Capitan
#!/bin/bash
## Copyright (C) 2015 Cerebral Gardens http://www.cerebralgardens.com/
##
## 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
DaveWoodCom / set_swift_version.post_install.ruby
Created October 4, 2017 05:18
`post_install` hook to set the Swift version of pods (add to the end of your project's podfile)
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'
end
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
DaveWoodCom / String+Email.swift
Last active February 28, 2021 16:45
Swift method to check for a valid email address (uses Apples data detector instead of a regex)
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
DaveWoodCom / keybase.md
Last active August 10, 2019 06:17
keybase.md

Keybase proof

I hereby claim:

  • I am davewoodcom on github.
  • I am davewood (https://keybase.io/davewood) on keybase.
  • I have a public key ASDVQq_MleuhYXva8i4Zs2Tt4yIJbtJx15W15Wd_Mx5Yfgo

To claim this, I am signing this object:

@DaveWoodCom
DaveWoodCom / TestProjectTests.swift
Created July 4, 2019 20:51
Xcode Test to test the performance of using a `for` loop with a `where` clause vs an `if` statement vs a `guard` statement.
//
// TestProjectTests.swift
// Tests
//
// Based on a question Nick Lockwood asked on Twitter: https://twitter.com/nicklockwood/status/1146508387498303488 .
// And then followed up by GeekAndDad https://twitter.com/GeekAndDad/status/1146630469842116609 .
// 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.
@DaveWoodCom
DaveWoodCom / Bug.txt
Created March 26, 2019 22:03
Radar #?
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
DaveWoodCom / XCGTextViewLogDestination
Created April 16, 2015 07:56
An XCGLogDestination that adds the logs to a UITextView
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
@DaveWoodCom
DaveWoodCom / UIViewController+Alerts.h
Created December 31, 2012 22:26
UIViewController+Alerts Category for presenting a view controller with a transparency above another view controller
//
// 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
DaveWoodCom / clearCookies.m
Created September 19, 2012 09:44
Objective-C - clearCookies functions
// 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];
}
@DaveWoodCom
DaveWoodCom / gist:ce3a3a6467a7fc7a71a3
Created August 5, 2014 09:36
if optional != nil is fugly!
public extension Optional {
public var exists: Bool {
return (self != nil)
}
public var notExists: Bool {
return (self == nil)
}
}