Skip to content

Instantly share code, notes, and snippets.

@jonathan-beebe
jonathan-beebe / vundle_swift_vim_instructions.md
Last active November 30, 2021 16:24
Using Apple’s Swift vim plugin with Vundle

Source of original vim config: https://github.com/apple/swift/tree/master/utils/vim

# use `svn checkout…` to grab just the subfolder from github
svn checkout https://github.com/apple/swift/trunk/utils/vim
# rename to something a bit more specific
mv vim vim-swift
cd vim-swift
rm -rf .svn
# init git
@jonathan-beebe
jonathan-beebe / curried_functions.swift
Last active December 21, 2015 13:27
curried functions in Swift
// Here is a manually curried function.
// maxA takes an int and returns a function, maxB, that takes an int and returns an int.
func maxA(a:Int) -> (Int) -> Int {
func maxB(b:Int) -> Int {
return a > b ? a : b
}
return maxB
}
@jonathan-beebe
jonathan-beebe / AppDelegate.swift
Last active November 1, 2023 19:11
Detect if a Swift iOS app delegate is running unit tests
import UIKit
// Detect if the app is running unit tests.
// Note this only detects unit tests, not UI tests.
func isRunningUnitTests() -> Bool {
let env = NSProcessInfo.processInfo().environment
if let injectBundle = env["XCInjectBundle"] {
return NSString(string: injectBundle).pathExtension == "xctest"
}
return false
@jonathan-beebe
jonathan-beebe / hidden_safari_view_controller.swift
Created November 11, 2015 13:16
Use hidden SFSafariViewController
private func showHiddenSafariViewController(controller:SFSafariViewController) {
controller.view.userInteractionEnabled = false
controller.view.alpha = 0.0
self.addChildViewController(controller)
self.view.addSubview(controller.view)
controller.didMoveToParentViewController(self)
controller.view.frame = CGRectZero
}
private func removeHiddenSafariViewController(controller:SFSafariViewController) {
@jonathan-beebe
jonathan-beebe / Xcode support newer iOS builds
Created October 26, 2015 15:59
Enable Xcode to support installing iOS apps on devices running newer version of iOS
- Go to newer version of Xcode, e.g. Xcode 7, in the Finder
- Right click and show package contents
- Navigate to `Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/`
- Copy the `9.0 (13A340)` folder
- Go to older version of Xcode, e.g. Xcode 6.4, in the Finder
- Right click and show package contents
- Navigate to `Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/`
- Paste the iOS 9 folder
- Restart Xcode
@jonathan-beebe
jonathan-beebe / xcode_async_swift.playground
Created September 4, 2015 00:47
Xcode Swift playgrounds do not normally run async code. You must tell the playground to continue indefinitely.
import XCPlayground
import Foundation
...
XCPSetExecutionShouldContinueIndefinitely(true)
@jonathan-beebe
jonathan-beebe / ocmock_example.m
Created September 2, 2015 12:28
OCMock Examples
#import <OCMock/OCMock.h>
...
// The basic object
id obj = [[MyOjbect alloc] init];
// Create the mock
id objMock = OCMPartialMock(obj);
@jonathan-beebe
jonathan-beebe / .bash_profile+xcode
Last active June 12, 2016 22:39
Helpful bash aliases for Xcode projects
alias xw="open *.xcworkspace"
alias xp="open *.xcodeproj"
function xcode {
# If the pattern matches a workspcace file, try to open it.
if stat -t -- *.xcworkspace >/dev/null 2>&1; then
xw
# Otherwise fall back to opening a project file.
else
xp
@jonathan-beebe
jonathan-beebe / Example_UITextField+TintClearButton.m
Last active March 14, 2018 17:52
Tinting a UITextField’s clear button
#import "UITextField+TintClearButton.h"
@implementation MyCustomTextFieldClass
- (void)layoutSubviews
{
[super layoutSubviews];
[self tintClearImage];
}
@jonathan-beebe
jonathan-beebe / iOS_open_mail_app.m
Created July 21, 2015 20:51
Open the default Apple Mail app on iOS navigating to a non-existent message id.
// Open the mail app on iOS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"message:xxxxxxxx"]];