Skip to content

Instantly share code, notes, and snippets.

View ken0nek's full-sized avatar

Ken Tominaga ken0nek

  • San Francisco, CA
View GitHub Profile
@ken0nek
ken0nek / file0.swift
Last active September 28, 2016 06:26
【Swift】Int型の数字から[Int]型の配列を生成する。数字を桁ごとに分ける。 ref: http://qiita.com/ken0nek/items/825289a7f3ea1d840337
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]
// 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]
// 画像から特徴を抽出する
-(IBAction)postToTwitter{
// ServiceTypeをTwitterに設定
NSString *serviceType = SLServiceTypeTwitter;
// Twitterが利用可能かチェック
if ([SLComposeViewController isAvailableForServiceType:serviceType]) {
// SLComposeViewControllerを初期化・生成
SLComposeViewController *twitterPostVC = [[SLComposeViewController alloc] init];
// カメラを起動する
-(IBAction)launchCamera{
// 画像の取得先をカメラに設定
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
// カメラが使用可能かどうか判定する
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
// UIImagePickerControllerを初期化・生成
// フォトライブラリを開く
-(IBAction)openLibrary{
// 画像の取得先をフォトライブラリに設定
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// フォトライブラリを使用可能かどうか判定する
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
// UIImagePickerControllerを初期化・生成