Skip to content

Instantly share code, notes, and snippets.

View 53ningen's full-sized avatar
🐰
Is the Order a Rabbit?

gomi_ningen 53ningen

🐰
Is the Order a Rabbit?
View GitHub Profile
/// DEFINE protocol A, class AImpl
protocol A { func getA() -> String }
private class AImpl: A{ func getA() -> String { return "a" } }
protocol AComponent {
static var a: A { get }
static func createA() -> A
}
/// DEFINE AComponent, DefaultAComponent

Dependency Injection in Swift 2

今日話す内容

中〜大規模 Swift 開発における依存オブジェクト解決の方法を考える

  1. DI (Dependency Injection) とは?
  • DIの基本的な話:知っている人が多かったら省略予定
  1. コンテナ (Swinject) を用いた DI
  • Swinject の DI コンテナを用いた 動的DIの話
  1. Swiftにおける静的 DI
@53ningen
53ningen / play_with_protocol.swift
Last active March 15, 2016 16:06
Playgroundで動きます (Xcode7.2)
public protocol A {
func getA() -> String
}
private class AImpl: A {
private func getA() -> String {
return "a"
}
}

RxSwiftライブラリの作り方 Observer/Observable編

 RxSwiftライブラリの作り方をご紹介します。一つの記事ですべてを説明するのは非常に厳しいので、まず ObserverObservable といった基本的なコンポーネントとその周辺について、ひとつずつ作っていく流れで説明します。

注意事項

  • この記事の内容を理解しなくても RxSwift は十分使えるライブラリです
  • まだ Rx 系のライブラリを使ったことがない方は、まずライブラリを使ってみてください
  • ただ、記事の内容的には Rx 系ライブラリの利用経験がなくても分かるように書いたつもりです
  • 以下の実装は RxSwift のものであり、他言語の Rx ライブラリとは実装が異なる場合があります

対象コード

public enum Event<E> {
    case Next(E)
    case Error(ErrorType)
    case Completed
}

public class Subject {
@53ningen
53ningen / Hoge
Last active April 10, 2016 09:53
; ModuleID = 'Hoge'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9"
%Vs5Int32 = type <{ i32 }>
%Sp = type <{ i8* }>
%swift.type = type { i64 }
%swift.type_pattern = type opaque
%swift.protocol_conformance = type { i32, i32, i32, i32 }
%swift.protocol = type { i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i32, i32 }
enum Hoge {
case Next
case Error
}
func piyo(arg: Hoge?) -> Bool {
return arg != nil
}
func foo(arg: Bool) -> Bool {
import Swift
import Foundation
let observable = BehaviorSubject(value: "cocoa")
let observer = AnyObserver<String> {
switch $0 {
case .Next(let str): NSLog(str)
default: break
}
}
### nil check for boolean
```
% cat ./NilCheckForBoolean.swift
import Foundation
func target() {
for _ in 1...100000 {
let e: Bool? = true
if e == nil { }
; your code goes here
(define (square x) (* x x))
(define (sum-of-square x y) (+ (square x) (square y)))
(define (q13 x y z) (cond
((and (>= y x) (>= z x)) (sum-of-square y z))
((and (>= x y) (>= z y)) (sum-of-square x z))
(else (sum-of-square x y))
))