Skip to content

Instantly share code, notes, and snippets.

@ole
ole / UIAlertController+TextField.swift
Last active September 13, 2022 14:20
A UIAlertController with a text field and the ability to perform validation on the text the user has entered while the alert is on screen. The OK button is only enabled when the entered text passes validation. More info: https://oleb.net/2018/uialertcontroller-textfield/
import UIKit
/// A validation rule for text input.
public enum TextValidationRule {
/// Any input is valid, including an empty string.
case noRestriction
/// The input must not be empty.
case nonEmpty
/// The enitre input must match a regular expression. A matching substring is not enough.
case regularExpression(NSRegularExpression)
@timshadel
timshadel / version.sh
Last active August 18, 2017 16:28
iOS automatic version script
#!/bin/sh
###
# Version: $Major.$Minor.$Commit
#
# How it works:
# 1. To roll minor number, tag each App Store release with a message.
# 2. To roll major number, create an additional tag on the last App Store
# release (e.g. "2.17.9") with new major number (e.g. "3").
# 3. `Release` builds require a clean working directory.

To start using Carthage with a new project:

  1. List your dependencies in a Cartfile. Refer to the Carthage documentation for details.
  2. Run carthage bootstrap --no-build --use-submodules
  3. Create a new workspace.
  4. Drag your existing App project into the workspace.
  5. Drag framework dependency projects from ./Carthage/Checkouts into the workspace.
  6. Go to the General tab of your target properties.
  7. Add framework dependencies to Linked Frameworks and Libraries. They will show up as Workspace frameworks.
  8. Add the same frameworks to Embedded Binaries.
  9. Note, the previous step will probably create duplicates in Linked Frameworks and Libraries. Delete the duplicates.
//: Playground - noun: a place where people can play
import UIKit
enum JSONError : ErrorType {
case NoValueForKey(String)
case TypeMismatch
}
public class JSONObject {
@laynemoseley
laynemoseley / gist:5fb41ca89eed62fb1ea1
Created April 15, 2015 13:06
Property List Serialization
// NSArray and NSDictionary have methods to write to files using the .plist format
// If your array/dictionary only contains NSNumber, NSDate, NSData or NSString objects, this works like a charm!
NSArray *strings = @[@"stringOne", @"stringTwo"];
NSString *filePath = @"/Path/To/Documents/data.plist";
BOOL successfullyWroteFile = [strings writeToFile:filePath atomically:YES];
// For error handling, you can check the successfullWroteFile variable
@bwhiteley
bwhiteley / MyWKInterfaceController.swift
Last active August 29, 2015 14:12
Ensure UI updates to WatchKit Interface Controller only happen while the controller is active.
/*
"WatchKit ignores attempts to set values of interface objects
while your interface is inactive.... Modifications can be made
only during initialization of your interface controller and
between calls to willActivate and [didDeactivate]."
*/
class MyWKInterfaceController: WKInterfaceController {
private var isActive:Bool = true
@jkhowland
jkhowland / Stack.h
Last active March 31, 2020 13:43
Simple Core Data - Stack.m
//
// Stack.m
//
// Created by Joshua Howland on 6/12/14.
// Copyright (c) 2014 DevMountain. All rights reserved.
//
#import <Foundation/Foundation.h>
@import CoreData;
@airdrummingfool
airdrummingfool / update_build_number.sh
Last active October 27, 2020 16:43
Update current Xcode target's build number with the number of commits on a specified branch. http://tgoode.com/2014/06/05/sensible-way-increment-bundle-version-cfbundleversion-xcode/
#!/bin/bash
# update_build_number.sh
# Usage: `update_build_number.sh [branch]`
# Run this script after the 'Copy Bundle Resources' build phase
# Ref: http://tgoode.com/2014/06/05/sensible-way-increment-bundle-version-cfbundleversion-xcode/
branch=${1:-'master'}
buildNumber=$(expr $(git rev-list $branch --count) - $(git rev-list HEAD..$branch --count))
echo "Updating build number to $buildNumber using branch '$branch'."