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
// フォトライブラリを開く | |
-(IBAction)openLibrary{ | |
// 画像の取得先をフォトライブラリに設定 | |
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary; | |
// フォトライブラリを使用可能かどうか判定する | |
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) { | |
// UIImagePickerControllerを初期化・生成 |
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
// カメラを起動する | |
-(IBAction)launchCamera{ | |
// 画像の取得先をカメラに設定 | |
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; | |
// カメラが使用可能かどうか判定する | |
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) { | |
// UIImagePickerControllerを初期化・生成 |
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
-(IBAction)postToTwitter{ | |
// ServiceTypeをTwitterに設定 | |
NSString *serviceType = SLServiceTypeTwitter; | |
// Twitterが利用可能かチェック | |
if ([SLComposeViewController isAvailableForServiceType:serviceType]) { | |
// SLComposeViewControllerを初期化・生成 | |
SLComposeViewController *twitterPostVC = [[SLComposeViewController alloc] init]; |
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
// storyboardに置いたimageViewからCIImageを生成する | |
let image = CIImage(CGImage: self.sampleImageView.image?.CGImage) | |
// 顔認識なのでTypeをCIDetectorTypeFaceに指定する | |
let detector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyHigh]) | |
// 取得するパラメーターを指定する | |
let options = [CIDetectorSmile : true, CIDetectorEyeBlink : true] | |
// 画像から特徴を抽出する |
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
extension Double : ForwardIndexType { | |
public func successor() -> Double { | |
return self + 1.0 | |
} | |
} | |
infix operator ∫ { associativity left precedence 120 } | |
func ∫ (left: Range<Double>, right: (Double -> Double)) -> Double { | |
let dx = (left.endIndex - left.startIndex) / 1000 | |
let r = left.startIndex.stride(to: left.endIndex, by: dx) |
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
// | |
// RootViewController.swift | |
// iOS9Sampler | |
// | |
// Created by Shuichi Tsutsumi on 2015/06/10. | |
// Copyright © 2015 Shuichi Tsutsumi. All rights reserved. | |
// | |
import UIKit |
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
var result: [(hasSmile: Bool, leftEyeClosed: Bool, rightEyeClosed: Bool)] = [] | |
for feature in features as! [CIFaceFeature] { | |
result.append((feature.hasSmile, feature.leftEyeClosed, feature.rightEyeClosed)) | |
} | |
if result.count >= 1 { | |
if result[0].hasSmile { | |
self.playerAttack() |
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, 2, 3, 4] -> ["0:1", "1:2", "2:3", "3:4"] |
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 num = 1234 | |
let numList = "\(num)".characters.flatMap { Int("\($0)") } | |
// let numList = String(num).characters.flatMap { Int(String($0)) } | |
print(numList) | |
// [1, 2, 3, 4] |
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 romanStrs = ["M", "D", "C", "L", "X", "V", "I"] | |
let romanNums = [1000, 500, 100, 50, 10, 5, 1] | |
let romanToNum = zip(romanStrs, romanNums).reduce([String: Int]()) { (dic, t) in | |
var dic = dic | |
dic[t.1] = t.0 | |
return dic | |
} |
OlderNewer