Skip to content

Instantly share code, notes, and snippets.

View el-hoshino's full-sized avatar
🏠
Working from home

Elvis Shi el-hoshino

🏠
Working from home
View GitHub Profile
@el-hoshino
el-hoshino / file0.swift
Last active November 27, 2015 07:06
「要素が範囲に含まれる」という演算子を作ってみた ref: http://qiita.com/lovee/items/32ceca1effbeceb959d6
let a = 1
0 ..< 10 ~= a // true
@el-hoshino
el-hoshino / TestModel
Last active August 29, 2017 02:44
ガチで Swift でプログラム組んで1年経っての心得 ref: http://qiita.com/lovee/items/555a5b76097347aa2367
import UIKit
protocol TestModelDelegate {
func display(something: NSObject)
}
class TestModel: NSObject {
var displayedString: String
var delegate: TestModelDelegate?
@el-hoshino
el-hoshino / file0.swift
Last active December 24, 2015 05:44
十六進数の文字列から実際の数値を取得する ref: http://qiita.com/lovee/items/eac017d1dcaf52541d3d
let hexString = "FF"
var hex:UInt32 = 0x0
let scanner:NSScanner = NSScanner(string: hexString)
scanner.scanHexInt(&hex)
print(hex) //255
@el-hoshino
el-hoshino / file0.swift
Created February 10, 2016 06:24
配列の一部範囲を取り出して新しい配列を生成する方法のパフォーマンス比較 ref: http://qiita.com/lovee/items/155a662146445ca4a79c
let array = [Int](0 ..< 10000)
let number = array[1000] // number = 1000
import Foundation
let candidates = ["ガルパン", "は", "いい", "ぞ"]
var createdPhrase = [String](count: candidates.count, repeatedValue: "")
for i in 0 ..< Int.max {
if createdPhrase != candidates {
let randomNumber = Int(arc4random_uniform(UInt32(candidates.count)))
let nextWord = candidates[randomNumber]
print(nextWord)
@el-hoshino
el-hoshino / after
Created March 24, 2016 08:35
【TIPS】protocol の対応は extension で! ref: http://qiita.com/lovee/items/2b96b9db0fbe7fccfbc1
class Person {
var car: Car?
func goForADrive() {
self.car?.drive()
}
func buyGasoline() {
@el-hoshino
el-hoshino / file0.swift
Last active March 30, 2016 13:58
Range<Int> に distance 作って Int に指定範囲で乱数を作成させる extension ref: http://qiita.com/lovee/items/942de12e9edb5ad01f48
//普通に distanceTo を使うからこの方法やめる
//extension Range where Element: IntegerType {
extension Range {
//普通に distanceTo を使うからこの方法やめる
//var distance: Element {
// return self.endIndex - self.startIndex
//}
var distance: Element.Distance {
@el-hoshino
el-hoshino / file1.txt
Last active April 4, 2016 06:23
ソースコードで想いを届ける(Swift コマンドライン編) ref: http://qiita.com/lovee/items/a225e27610a663035cd8
% swift iLoveYou.swift 春彦母
私は春彦母のことが好きです
@el-hoshino
el-hoshino / ChildViewController
Last active April 21, 2016 13:18
遅延生成で生成時に色々設定を入れる方法 ref: http://qiita.com/lovee/items/0bf551b5ef65ad00cccc
import UIKit
class ChildViewController: UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
print("Child controller inited")
}
required init?(coder aDecoder: NSCoder) {
@el-hoshino
el-hoshino / GCD.swift
Created April 29, 2016 12:56
dispatch いちいち書くの面倒だったら…自分で改良すればいいじゃない! ref: http://qiita.com/lovee/items/facfe77f6eab16651f08
import Foundation
struct GCD {
enum Thread {
case Main
case Static(queue: dispatch_queue_t)
case Dynamic(name: String, attribute: QueueAttribute)