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 / AppDelegate.swift
Last active March 4, 2018 04:44
Storyboard 抜きで、コードオンリーで iOS アプリの UI を作る ref: https://qiita.com/lovee/items/5e8c7752d7e383660543
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// アプリウィンドウを設定します。
self.window = UIWindow(frame: UIScreen.main.bounds)
// ウィンドウをヴィジブルにします。
self.window?.makeKeyAndVisible()
// ウィンドウの rootViewController を viewController に設定します。
@el-hoshino
el-hoshino / file0.swift
Created January 9, 2015 09:43
配列宣言時型推論の意外な落とし穴 ref: http://qiita.com/lovee/items/7e96284f4520b48646a3
let testString = "test"
let testFlag = true
let testInt = 1
let testArray = [testString, testFlag, testInt]
@el-hoshino
el-hoshino / file0.swift
Last active August 29, 2015 14:16
.map を利用して let でランダム数列を作る ref: http://qiita.com/lovee/items/f3515119883f05a8dac5
let randomIntArray = [Int](count: 10, repeatedValue: 0).map { (some: Int) -> Int in
let randomUInt = arc4random_uniform(100) // 0 ..< 100 の乱数を作る
return Int(randomUInt) - 50
}
@el-hoshino
el-hoshino / file0.c
Last active August 29, 2015 14:17
【初心者向け?】map メソッドで既存配列から違う型の配列を作る方法 ref: http://qiita.com/lovee/items/0ee298443e4225f3cb3e
int arrayA[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int arrayB[10];
for (int i = 0; i < 10; i++) {
arrayB[i] = arrayA[i] * arrayA[i];
}
@el-hoshino
el-hoshino / file0.swift
Last active August 29, 2015 14:19
【質問】UIKit のみで OnScreen 描画フィルター掛けることできないかな? ref: http://qiita.com/lovee/items/3e3b6233df9839053521
// Playground - noun: a place where people can play
import UIKit
// オリジナル画像を読み込もう(ファイル名の設定忘れないでね)
let baseImage = UIImage(named: "image.png")!
let baseCIImage = CIImage(image: baseImage)
// Core Image フィルターを #00FFFF の色で設定する
let filterColor = CIColor(red: 0, green: 1, blue: 1)
@el-hoshino
el-hoshino / file0.swift
Last active August 27, 2015 05:55
NSUserDefaults で struct を保存(?)する方法 ref: http://qiita.com/lovee/items/2b39e1c54d6d00adead9
class ViewController: UIViewController {
var settings: UserSettings
init() {
self.settings = UserSettings(a: 0, b: false, c: "NO")
super.init(nibName: nil, bundle: nil)
}
@el-hoshino
el-hoshino / file0.swift
Last active September 4, 2015 10:34
Swift での Int 型 switch case の落とし穴(?) ref: http://qiita.com/lovee/items/31bc2b4e66a93944c9a6
let a = 0
switch a {
case Int.min ..< 0:
print("負数")
case 0:
print("零")
case 1 ... Int.max:
print("正数")
@el-hoshino
el-hoshino / file0.swift
Created October 23, 2015 05:57
UIButton の動作を Callback で設定する方法 ref: http://qiita.com/lovee/items/65b1f10313454fca4a05
import UIKit
class CallbackButton: UIButton {
private var action: (() -> Void)?
init(frame: CGRect, action: (() -> Void)? = nil) {
self.action = action
@el-hoshino
el-hoshino / file0.swift
Last active November 12, 2015 03:34
switch 文で Optional Binding を使いたかった話 ref: http://qiita.com/lovee/items/7bd9aee01d7ccbf72d2b
let dict = [1: 2, 3: 4]
let key = 1
if let value = dict[key] {
print(value)
}
@el-hoshino
el-hoshino / file0.swift
Created November 25, 2015 03:07
UIImage の画素データを Array で取得する方法 ref: http://qiita.com/lovee/items/74c0310a50d1b752ceb8
func getByteArrayFromImage(imageRef: CGImageRef) -> [UInt8] {
let data = CGDataProviderCopyData(CGImageGetDataProvider(imageRef))
let length = CFDataGetLength(data)
var rawData = [UInt8](count: length, repeatedValue: 0)
CFDataGetBytes(data, CFRange(location: 0, length: length), &rawData)
return rawData
}