This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy) | |
// id object: プロパティを持たせたいオブジェクト | |
// void *key: プロパティのアドレス (static で宣言した不変なローカルな静的変数を指定する) | |
// id value: 保持させるのオブジェクト | |
// objc_AssociationPolicy policy: 関連付けの方法 (後述) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let displayLink = CADisplayLink(target: self, selector: Selector("update:")) | |
displayLink.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 1. リストを引数に取って、length に π (=3.1415)を返す関数 | |
pieTime x = fromIntegral (length x) + (pi :: Float) | |
-- 2. 2つの文字列を引数にとって、数値として足し算する関数 | |
addString x y = (read x::Int) + (read y::Int) | |
-- 3. 文字列を逆する関数 | |
reverse' x = [x !! z | z <- [((length x) - 1), ((length x) - 2)..0]] | |
-- 4. 文字列が回文かどうかを判定する関数 isPalindrome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
#Xcode上の不要なファイルを抽出するスクリプト | |
puts "- start class file #{Time.now.strftime("%Y/%m/%d %H:%M:%S")}" | |
class_waste_count = 0 | |
#クラスファイルの一覧を取得 | |
result = `find ~/SampleProject -type f -name "*.h" -exec basename {} \\; | sort` | |
class_filenames = result.split("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reduce<T,R>(list: [T], block: (([R],T) -> R?)) -> [R]? { | |
var acc = [R]() | |
for x in list { | |
if let val = block(acc, x) { | |
acc += [val] | |
} | |
} | |
return acc | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"sort" | |
"time" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Extension<Base> { | |
public let base: Base | |
public init(_ base: Base) { | |
self.base = base | |
} | |
} | |
public struct StaticExtension<Base> { } | |
public protocol ExtensionCompatible { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct Extension<Base> { | |
public let base: Base | |
public init(_ base: Base) { | |
self.base = base | |
} | |
} | |
public protocol ExtensionCompatible { | |
associatedtype Compatible | |
var ex: Extension<Compatible> { get set } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
final class ViewController: UITableViewController { | |
private var names: [String] = (50...99).map { String($0) } | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PlaygroundSupport | |
import UIKit | |
/// Solver for cubic bezier curve with implicit control points at (0, 0) and (1, 1) | |
/// Based on https://github.com/adobe/webkit/blob/master/Source/WebCore/platform/graphics/UnitBezier.h | |
struct UnitBezier { | |
private let a: CGPoint | |
private let b: CGPoint | |
private let c: CGPoint | |
private let epsilon: CGFloat = 0.000001 |
OlderNewer