Skip to content

Instantly share code, notes, and snippets.

View ivanbruel's full-sized avatar

Ivan Bruel ivanbruel

View GitHub Profile
extension String {
init?(utf16chars:[UInt16]) {
var str = ""
var generator = utf16chars.generate()
var utf16 : UTF16 = UTF16()
var done = false
while !done {
let result = utf16.decode(&generator)
switch result {
//: Playground - noun: a place where people can play
import UIKit
struct Domino {
let left: Int
let right: Int
init(string: String) {
let split = string.componentsSeparatedByString("-")
import UIKit
struct Domino {
let left: Int
let right: Int
init(string: String) {
let split = string.componentsSeparatedByString("-")
left = split.first.flatMap { Int($0) } ?? 0
right = split.last.flatMap { Int($0) } ?? 0
@ivanbruel
ivanbruel / Observable+Result.swift
Created May 3, 2016 13:20
RxSwift extension to handle Result signals with doOn methods
import Foundation
import RxSwift
import Result
extension ObservableType where E: ResultType {
func doOnSuccess(onSuccess: (E.Value throws -> Void))
-> Observable<E> {
return self.doOnNext { (value) in
guard let successValue = value.value else {
//
// DressDetailsAddToBagViewModel.swift
// ChicByChoice
//
// Created by Francisco Gonçalves on 19/02/16.
// Copyright © 2016 Chic by Choice. All rights reserved.
//
import Foundation
import RxSwift
@ivanbruel
ivanbruel / DressDetailsAddToBagViewModel.swift
Last active April 19, 2016 16:08
DressDetailsAddToBagViewModel
//
// DressDetailsAddToBagViewModel.swift
// ChicByChoice
//
// Created by Ivan Bruel on 18/04/16.
// Copyright © 2016 Chic by Choice. All rights reserved.
//
import Foundation
import RxSwift
class AnimalTableViewCell: UITableViewCell {
private var imageView: UIImageView
private var nameLabel: UILabel
private var hungryIconView: HungryIconView
private let disposeBag = DisposeBag()
var viewModel: AnimalViewModel {
didSet {
class AnimalViewModel {
let name: String
let image: UIImage
private let _hungry: Variable<Bool>
var hungry: Observable<Bool> {
return _hungry.asObservable()
}
init(animal: Animal) {
@ivanbruel
ivanbruel / AnimalViewController.swift
Created March 11, 2016 11:13
AnimalViewController.swift
class AnimalViewController: UIViewController {
// Model Object
var animal: Animal
// View Object
var imageView: UIImageView
override func viewDidLoad() {
// Maps Model into a View
@ivanbruel
ivanbruel / Animal.swift
Created March 11, 2016 11:10
Animal.swift
class Animal {
var name: String
var age: Int
var image: UIImage
init(name: String, age: Int, image: UIImage) {
self.name = name
self.age = age
self.image = image
}