Skip to content

Instantly share code, notes, and snippets.

View ncreated's full-sized avatar
💭
⚡️

Maciek Grzybowski ncreated

💭
⚡️
View GitHub Profile
@ncreated
ncreated / PrintLocalesController.m
Last active February 29, 2024 16:29
List of iOS locales with currency formatting.
//
// PrintLocalesController.m
// NSFormatterTest
//
// Created by Maciek Grzybowski on 02.04.2014.
//
#import "PrintLocalesController.h"
@interface PrintLocalesController ()
@ncreated
ncreated / APIService+Alamofire.swift
Last active August 12, 2018 18:56
A generic approach to parse XML REST API with `Alamofire` and `SWXMLHash`. Still in progress...
//
// APIService+Alamofire.swift
//
// Created by Maciek on 07.10.2015.
// Copyright © 2015 Code Latte. All rights reserved.
//
import SWXMLHash
import Alamofire
// Crash:
let cell = tableView.dequeueReusableCell(withIdentifier: Constants.twoLabelsCellIdentifier) as! TwoLabelsIconCell
// Crash with verbose message:
guard let cell = tableView.dequeueReusableCell(withIdentifier: Constants.twoLabelsCellIdentifier) as? TwoLabelsIconCell else {
fatalEror("Cannot dequeue `TwoLabelsIconCell`")
}
// Crash in DEBUG, recover in Release:
guard let cell = tableView.dequeueReusableCell(withIdentifier: Constants.twoLabelsCellIdentifier) as? TwoLabelsIconCell else {
@ncreated
ncreated / frame-layout.swift
Last active November 29, 2016 10:56
POC of syntax improvement to manual frame layout in Swift.
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
struct Frame {
let x: CGFloat
let y: CGFloat
let width: CGFloat
@ncreated
ncreated / Imperative.swift
Last active February 20, 2017 20:14
Comparison of Imperative vs Reactive ways
// Imperative
protocol EditableMapSourceDelegate: class {
func sourceDidChangeActiveTerritory(_ source: EditableMapSource)
func sourceDidChangeData(_ source: MapDataSource)
}
final class EditableMapSource: MapDataSource {
weak var delegate: EditableMapSourceDelegate?
@ncreated
ncreated / Autocomplete.swift
Last active July 17, 2017 19:57
Medium blogpost snippet
import RxSwift
import RxCocoa
final class Autocomplete {
func autocomplete(text: Observable<String>) -> (result: Driver<AutocompleteResult>,
isBusy: Driver<Bool>) {
return (result: .empty(), isBusy: .empty()) // TODO
}
}
@ncreated
ncreated / AutocompleteProvider.swift
Created July 16, 2017 19:38
Medium blogpost snippet
import RxSwift
protocol AutocompleteProvider {
func autocomplete(text: String) -> Observable<[Prediction]>
}
@ncreated
ncreated / Prediction.swift
Created July 16, 2017 19:44
Medium blogpost snippet
struct Prediction {
let predictedText: String
let matchingRange: Range<String.Index>
}
@ncreated
ncreated / CountryAutocompleteProvider.swift
Created July 16, 2017 20:01
Medium blogpost snippet
import RxSwift
private let countries = ["Afghanistan", "Albania", /* all the countries */ "Zambia", "Zimbabwe"]
final class CountryAutocompleteProvider: AutocompleteProvider {
func autocomplete(text: String) -> Observable<[Prediction]> {
func predictionsFor(prefix: String) -> [Prediction] {
return countries
.flatMap { country in
@ncreated
ncreated / Autocomplete.swift
Last active July 17, 2017 19:57
Medium blogpost snippet
final class Autocomplete {
// MARK: - Properties
private let provider: AutocompleteProvider
// MARK: - Initializers
init(provider: AutocompleteProvider) {
self.provider = provider