Skip to content

Instantly share code, notes, and snippets.

View onevcat's full-sized avatar
🐭

Wei Wang onevcat

🐭
View GitHub Profile
@onevcat
onevcat / why_not_focusable
Created November 9, 2015 07:21
Ask lldb why a view cannot be focusable.
(lldb) po [(UIView *)0x148db5234 _whyIsThisViewNotFocusable]
ISSUE: This view has userInteractionEnabled set to NO. Views must allow user interaction to be focusable.
ISSUE: This view returns NO from -canBecomeFocused.
let timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: NSBlockOperation {
[weak self] in
// Do something...
}, selector: "main", userInfo: nil, repeats: false)
@onevcat
onevcat / localizedKey.swift
Created October 21, 2015 08:33
Extension
extension UILabel {
@IBInspectable var localizedKey: String? {
set {
if let s = newValue {
text = NSLocalizedString(s, comment:"")
}
}
get {
return text
@onevcat
onevcat / Atomic.swift
Created October 20, 2015 01:23
Atomically performs an arbitrary action using the current value of the variable.
//
// Atomic.swift
// ReactiveCocoa
//
// Created by Justin Spahr-Summers on 2014-06-10.
// Copyright (c) 2014 GitHub. All rights reserved.
//
/// An atomic variable.
internal final class Atomic<Value> {
@onevcat
onevcat / update-version.sh
Last active April 15, 2016 02:18
Update build version by the commit count in git
git=`sh /etc/profile; which git`
appBuild=`"$git" rev-list --all |wc -l`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "${SRCROOT}/${INFOPLIST_FILE}"
echo "Updated ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
@onevcat
onevcat / nstimer_break_retain.swift
Created September 28, 2015 03:34
NSTimer extension which breaks the retain cycle in Swift.
private class Block<T> {
let f : T
init (_ f: T) { self.f = f }
}
extension NSTimer {
static func xxx_scheduledTimerWithTimeInterval(ti: NSTimeInterval, block: ()->(), repeats: Bool) -> NSTimer {
return self.scheduledTimerWithTimeInterval(ti, target:
self, selector: "xxx_blcokInvoke:", userInfo: Block(block), repeats: repeats)
}
@onevcat
onevcat / XCTAssertSwiftError.swift
Created September 24, 2015 09:03
Throw testing support for XCTest
//
// XCTAssertSwiftError.swift
//
// Created by LCS on 6/17/15.
// Released into public domain; use at your own risk.
//
import XCTest
func XCTempAssertThrowsError(message: String = "", file: String = __FILE__, line: UInt = __LINE__, _ block: () throws -> ())
@onevcat
onevcat / debugger.m
Created September 19, 2015 11:13
Check if a debugger attached.
- (BOOL)Debugger{
static BOOL debuggerIsAttached = NO;
static dispatch_once_t debuggerPredicate;
dispatch_once(&debuggerPredicate, ^{
struct kinfo_proc info;
size_t info_size = sizeof(info);
int name[4];
@onevcat
onevcat / ATS.plist
Last active January 12, 2018 12:32
Fuck off ATS
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
@onevcat
onevcat / qsort.swift
Created June 30, 2015 07:00
Quick sort of Swift
//: Playground - noun: a place where people can play
import UIKit
var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5]
func partition(inout v: [Int], left: Int, right: Int) -> Int {
var i = left
for j in (left + 1) ... right {
if v[j] < v[left] {