Skip to content

Instantly share code, notes, and snippets.

View matouka-suzuki's full-sized avatar

matouka-suzuki matouka-suzuki

View GitHub Profile
@matouka-suzuki
matouka-suzuki / markup.swift
Created March 18, 2015 06:13
Swift Playground MarkupFormat
//: Playground - noun: a place where people can play
//: Markup Format
// Heading #
/*:
# Heading1 in Block
@matouka-suzuki
matouka-suzuki / AnimationController.m
Last active August 29, 2015 14:20
AnimationController
// This method can only be a nop if the transition is interactive and not a percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
UIViewController* fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController* toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView* fromView = fromVC.view;
UIView* toView = toVC.view;
UIView* containerView = [transitionContext containerView];
CGRect inframe = [transitionContext initialFrameForViewController:fromVC];
@matouka-suzuki
matouka-suzuki / NS_OPTIONS.swift
Last active October 16, 2015 11:11
NSOptions相当のことをする
// http://natecook.com/blog/2014/07/swift-options-bitmask-generator/
struct UnuseOptions : OptionSetType {
typealias RawValue = UInt
private var value: UInt = 0
init(_ value: UInt) { self.value = value }
init(rawValue value: UInt) { self.value = value }
init(nilLiteral: ()) { self.value = 0 }
static var allZeros: UnuseOptions { return self.init(0) }
static func fromMask(raw: UInt) -> UnuseOptions { return self.init(raw) }
var rawValue: UInt { return self.value }
@matouka-suzuki
matouka-suzuki / RealmMemo.md
Last active December 3, 2015 02:01
Realm 0.96を使った時の注意事項

モデルの定義

class Person: Object {
    dynamic var identifier = ""
    // ネストはOptionalで定義
    dynamic var unit: Unit?
    // 配列はList (Documentではletだが、ObjectMapperを使うためにvar)
    var dogs = List<Dog>()
    
@matouka-suzuki
matouka-suzuki / PlaygroundでCocoaPods利用.md
Created December 16, 2015 10:31
Swift playgroundでCocoaPodsを使う方法
  1. xcprojを作る
  2. podfileを記述
  3. pod install
  4. workspace開く
  5. add > new > playground
  6. Manage SchemeでPods-プロジェクト名にチェックを付ける
  7. "Pods-プロジェクト"をビルド
  8. playgroundでimport
@matouka-suzuki
matouka-suzuki / CSV2Realm.swift
Created December 16, 2015 10:36
CSVファイルをRealmに変換
import UIKit
import RealmSwift
import XCPlayground
class BusStop: Object {
dynamic var identifier = ""
dynamic var name = ""
convenience init(identifier: String, name: String) {
self.init()
@matouka-suzuki
matouka-suzuki / ShowPopoverFromButton.swift
Created December 18, 2015 02:10
UIButtonのイベントでUIPopoverを表示する
func buttonDidPush(button: UIButton) {
let vc = UIViewController()
vc.modalPresentationStyle = .Popover
let presentationController = vc.popoverPresentationController!
presentationController.sourceView = self.view
presentationController.sourceRect = button.superview!.convertRect(button.frame, toView: self.view)
self.presentViewController(vc, animated: true, completion: nil)
}
@matouka-suzuki
matouka-suzuki / HowToGetElementTypeOfArray.swift
Created December 22, 2015 01:58
SwiftのArrayの中身の型を取得する
let objType = array.dynamicType.Element.self
@matouka-suzuki
matouka-suzuki / JSONArrayMapping.swift
Created December 22, 2015 05:27
WebAPIでJSONがObjectではなくArrayを返すときのObjectMapperでのマッピング
typealias ResponseType = [CardList]
// ResponseTypeをうまく使えてないのがアレだが・・
func fromJson(json: AnyObject) -> Result<GetCardList.ResponseType, NSError> {
guard let dictionary = json as? [[String : AnyObject]] else {
return .Failure(Error.errorWithCode(2, failureReason: "[CardList]のマッピングに失敗しました"))
}
var array = [CardList]()
dictionary.forEach {
@matouka-suzuki
matouka-suzuki / changeLocalizationInternally.swift
Created December 29, 2015 08:32
ChangeLocalizationInternallyInIOSApp
import Foundation
import ObjectiveC
private var LangBundleKey = 0
// Thanks for a following post
// http://www.factorialcomplexity.com/blog/2015/01/28/how-to-change-localization-internally-in-your-ios-application.html
extension NSBundle {
private class BundleEx: NSBundle {