Skip to content

Instantly share code, notes, and snippets.

View Gatada's full-sized avatar
💭
Working offline on a physical tabletop game

Johan H. W. Basberg Gatada

💭
Working offline on a physical tabletop game
View GitHub Profile
@maxcampolo
maxcampolo / AnimatedSublayer.swift
Last active July 3, 2024 16:46
Animate position of a sublayer when animating a UIView.
public override func layoutSubviews() {
super.layoutSubviews()
// If the view is animating apply the animation to the sublayer
CATransaction.begin()
if let animation = layer.animationForKey("position") {
CATransaction.setAnimationDuration(animation.duration)
CATransaction.setAnimationTimingFunction(animation.timingFunction)
} else {
CATransaction.disableActions()
@StuartMorris0
StuartMorris0 / Swift-find-constraint-by-identifier.swift
Created March 23, 2016 16:29
Get reference to a constraint by filtering through all constraints looking for a specific identifier in Swift
let foregroundTopConstraint = self.contentView.constraints.filter{ $0.identifier == "ForegroundViewTop"}.first
@i07
i07 / catchNonLaunch.swift
Created January 3, 2016 11:42
catch handleNonLaunchSpecificActions exception
import UIKit
extension UIApplication {
func _handleNonLaunchSpecificActions(arg1: AnyObject, forScene arg2: AnyObject, withTransitionContext arg3: AnyObject, completion completionHandler: () -> Void) {
//whatever you want to do in this catch
print("handleNonLaunchSpecificActions catched")
}
}
@nRewik
nRewik / chainingRequestDelegate.swift
Created September 8, 2015 13:20
how request chaining work with NSUrlSessionDelegate
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
class ExampleChainingRequest: NSObject{
private var session: NSURLSession!
@JadenGeller
JadenGeller / Logical XOR.swift
Created March 26, 2015 23:26
Swift Logical XOR
infix operator ^^ { associativity left precedence 120 }
func ^^<T : BooleanType, U : BooleanType>(lhs: T, rhs: U) -> Bool {
return lhs.boolValue != rhs.boolValue
}
// Example
false ^^ false // -> false
false ^^ true // -> true
@ningsuhen
ningsuhen / Regex.swift
Last active April 27, 2019 18:39
Swift extension for Native String class to support Regex match and Regex replace. Credit - http://www.swift-studies.com/blog/2014/6/12/regex-matching-and-template-replacement-operators-in-swift
import Foundation
struct Regex {
var pattern: String {
didSet {
updateRegex()
}
}
var expressionOptions: NSRegularExpressionOptions {
didSet {
@borlaym
borlaym / animals.json
Created December 15, 2014 13:38
Array of animal names
[
"Aardvark",
"Albatross",
"Alligator",
"Alpaca",
"Ant",
"Anteater",
"Antelope",
"Ape",
"Armadillo",
@mattt
mattt / uiappearance-selector.md
Last active June 4, 2024 13:28
A list of methods and properties conforming to `UIAppearance` as of iOS 12 Beta 3

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep UI_APPEARANCE_SELECTOR ./*     | \
  sed 's/NS_AVAILABLE_IOS(.*)//g'     | \
  sed 's/NS_DEPRECATED_IOS(.*)//g'    | \
  sed 's/API_AVAILABLE(.*)//g'        | \
  sed 's/API_UNAVAILABLE(.*)//g'      | \
 sed 's/UI_APPEARANCE_SELECTOR//g' | \
@sekati
sekati / xcode-build-bump.sh
Created July 24, 2012 20:44
Xcode Auto-increment Build & Version Numbers
# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)