Skip to content

Instantly share code, notes, and snippets.

@jlehikoinen
jlehikoinen / setup.sh
Last active March 4, 2021 13:12
Swift syntax highlighting for Vim
# Swift syntax highlighting for Vim
# Source: http://wingsquare.com/blog/swift-script-syntax-highlighting-and-indentation-for-vim-text-editor/
echo "--- Installing and configuring Pathogen.."
mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
echo "execute pathogen#infect()
syntax on
@christianklotz
christianklotz / ios-default-fontsize-table.swift
Created February 2, 2016 16:42
List of default font sizes for dynamic type
let defaultFontSizeTable = [
UIFontTextStyleHeadline: [
UIContentSizeCategoryAccessibilityExtraExtraExtraLarge: 26,
UIContentSizeCategoryAccessibilityExtraExtraLarge: 25,
UIContentSizeCategoryAccessibilityExtraLarge: 24,
UIContentSizeCategoryAccessibilityLarge: 24,
UIContentSizeCategoryAccessibilityMedium: 23,
UIContentSizeCategoryExtraExtraExtraLarge: 23,
UIContentSizeCategoryExtraExtraLarge: 22,
UIContentSizeCategoryExtraLarge: 21,
@trevorwang
trevorwang / NSDateFormatter cheat sheet
Created January 26, 2016 08:58 — forked from romaonthego/NSDateFormatter cheat sheet
Date Formats for NSDateFormatter
a: AM/PM
A: 0~86399999 (Millisecond of Day)
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
@ericdke
ericdke / extractURLS.swift
Created January 21, 2016 18:38
SWIFT: Extract URLS from String
extension String {
func extractURLs() -> [NSURL] {
var urls : [NSURL] = []
do {
let detector = try NSDataDetector(types: NSTextCheckingType.Link.rawValue)
detector.enumerateMatchesInString(self,
options: [],
range: NSMakeRange(0, text.characters.count),
usingBlock: { (result, _, _) in
if let match = result, url = match.URL {
@mcmurrym
mcmurrym / MirrorDebugDecscription.swift
Last active December 24, 2019 05:59
A default protocol implementation for CustomDebugStringConvertible that uses Mirror for introspection
public extension CustomDebugStringConvertible {
var debugDescription: String {
return debugDescription()
}
func debugDescription(_ indentationLevel: Int = 0, includeType: Bool = true) -> String {
let indentString = (0..<indentationLevel).reduce("") { tabs, _ in tabs + "\t" }
var s: String
@zgchurch
zgchurch / BridgingHeader.h
Created June 26, 2014 17:32
Using SQLite3 from Swift
// 1. Create this file in your Xcode project
// 2. Go to "Build Settings" and find "Objective-C Bridging Header." Use the search bar to find it quickly.
// 3. Double-click and type "BridgingHeader.c"
// If you get "Could not import Objective-C Header," try "my-project-name/BridgingHeader.h"
// 4. Go to "Build Phases," "Link Binary With Libraries," and add libsqlite3.0.dylib
#include <sqlite3.h>
@snikch
snikch / gist:3661188
Created September 6, 2012 23:16
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}