Skip to content

Instantly share code, notes, and snippets.

View fluidsonic's full-sized avatar

Marc Knaup fluidsonic

View GitHub Profile
@fluidsonic
fluidsonic / sqlite3.sh
Created April 23, 2015 16:03
Make sqlite3 module available in Swift
#!/bin/sh
modulesDirectory=$DERIVED_FILES_DIR/modules
modulesMap=$modulesDirectory/module.modulemap
modulesMapTemp=$modulesDirectory/module.modulemap.tmp
mkdir -p "$modulesDirectory"
cat > "$modulesMapTemp" << MAP
module sqlite3 [system] {
@fluidsonic
fluidsonic / gist:4e81aa2000b7dc62b099
Last active August 29, 2015 14:20
Randomly returns totally wrong values with Swift optimizations (-O) turned on
public func optionalMax <T: Comparable>(elements: T? ...) -> T? {
var maximumElement: T?
for element in elements {
if let element = element {
if let existingMaximumElement = maximumElement {
if element > existingMaximumElement {
maximumElement = element
}
}
{
"name": "Fabric",
"version": "1.3.0",
"summary": "Fabric by Twitter, Inc.",
"homepage": "https://fabric.io",
"authors": "Twitter",
"license": {
"type": "Commercial",
"text": "Fabric: Copyright 2015 Twitter, Inc. All Rights Reserved. Use of this software is subject to the terms and conditions of the Fabric Software and Services Agreement located at https://fabric.io/terms. OSS: http://get.fabric.io/terms/opensource.txt"
},
@fluidsonic
fluidsonic / Escaper.swift
Last active December 22, 2016 13:32
Converting a closure to an @escaping closure in Swift 3
func makeEscaping<Parameters,Result>(_ closure: (Parameters) -> Result) -> (Parameters) -> Result {
func cast<From,To>(_ instance: From) -> To {
return (instance as Any) as! To
}
return cast(closure)
}
// Example
@fluidsonic
fluidsonic / gist:981e0b86661abb30a0ed
Created November 19, 2015 21:58
UIPageControl madness
(lldb) po 0x12fbada50
<UIPageControl: 0x12fbada50; frame = (134.5 46.5; 7 37); autoresize = W; userInteractionEnabled = NO; layer = <WLayer: 0x12fbabe80>>
(lldb) p (NSInteger)[0x12fbada50 numberOfPages]
(NSInteger) $2 = 1
(lldb) p (NSInteger)[0x12fbada50 currentPage]
(NSInteger) $3 = 0
(lldb) p (void)[0x12fbada50 setCurrentPage:1]
@fluidsonic
fluidsonic / gist:3f3c93376d9af3d8ab41
Created December 1, 2015 23:31
iOS View Controller Lifecycle Validation
VIEW CONTROLLER LIFECYCLE BROKEN!
MFMailComposeInternalViewController (indirectly) called super.viewDidAppear() multiple times.
Possible causes:
- MFMailComposeInternalViewController or one of its superclasses called super.viewDidAppear() multiple times
- it was called manually (it should never be called manually)
- the controller containment implementation of MFMailComposeViewController or one if its parents is broken
@fluidsonic
fluidsonic / foo.m
Created December 4, 2015 15:28
UISplitViewController sucks!
(lldb) po 0x7c953600 // UISplitViewController
<UISplitViewController: 0x7c953600>
(lldb) po [0x7c953600 childViewControllers] // UISplitViewController's children
NSArray(
<UIViewController: 0x7be5a6e0>,
<UIViewController: 0x7be9b130>
)
(lldb) po [0x7be5a6e0 parentViewController] // master child's parent
@fluidsonic
fluidsonic / Recursive Struct.swift
Last active December 11, 2015 15:58
Recursive Struct through Indirect Enum
struct Path: CustomStringConvertible {
private var hasParent = HasParent.No
var key: String
init(forKey key: String, inParent parent: Path? = nil) {
self.key = key
self.parent = parent
@fluidsonic
fluidsonic / Podfile.rb
Last active May 12, 2016 11:30
Migrating to CocoaPods 1.0 will be so much fun!
workspace 'OurApp'
xcodeproj 'App'
platform :ios, '8.2'
use_frameworks!
link_with 'App Store', 'Beta', 'Development', 'Testing'
# a lot of pods here
pre_install do |installer|
# workaround for https://github.com/CocoaPods/CocoaPods/issues/3957
@fluidsonic
fluidsonic / FlatOptional.swift
Last active January 30, 2017 20:58
Fully unwraps nested Optionals hidden behind "Any"
protocol _TypeerasedOptional {
var typeerasedSelf: Any? { get }
}
extension Optional: _TypeerasedOptional {
var typeerasedSelf: Any? {
guard let value = self else {