Skip to content

Instantly share code, notes, and snippets.

View soxjke's full-sized avatar

Petro Korienev soxjke

View GitHub Profile
@soxjke
soxjke / Podfile.rb
Last active October 26, 2017 10:19
Podfile for weather app
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
inhibit_all_warnings!
def common_pods
pod 'Redux-ReactiveSwift', '~> 0.1.1' # Our Redux library
pod 'ReactiveCocoa', '~> 7.0.0-alpha1' # ReactiveCocoa has necessary UI bindings
pod 'ObjectMapper', '3.0.0' # ObjectMapper is for fast from/to JSON transformations
end
import UIKit
class WeatherView: UIView {
private struct Const {
static let cellIdentifier = "WeatherFeatureCell"
}
@IBOutlet private weak var tableView: UITableView!
static func fromNib() -> WeatherView {
guard let view = Bundle.main.loadNibNamed("WeatherView", owner: nil)?.first as? WeatherView else {
import UIKit
import SnapKit
class ViewController: UIViewController {
@IBOutlet private weak var containerView: UIView!
@IBOutlet private weak var segmentedControl: UISegmentedControl!
@IBOutlet private weak var leftBarButtonItem: UIBarButtonItem!
@IBOutlet private weak var rightBarButtonItem: UIBarButtonItem!
private lazy var currentWeatherView: WeatherView = WeatherView.fromNib()
override func viewDidLoad() {
enum WeatherValue<Value> {
case single(value: Value)
case minmax(min: Value, max: Value)
}
struct WeatherFeature<T> {
let unit: String
let value: WeatherValue<T>
}
{
"Date": "2017-10-26T07:00:00+01:00",
"EpochDate": 1508997600,
"Sun": {
"Rise": "2017-10-26T08:21:00+01:00",
"EpochRise": 1509002460,
"Set": "2017-10-26T19:23:00+01:00",
"EpochSet": 1509042180
},
"Moon": {
@soxjke
soxjke / WeatherSpec.swift
Last active October 26, 2017 15:01
WeatherSpec - Step1
import Foundation
import Quick
import Nimble
@testable import Simple_Weather_App
class WeatherSpec: QuickSpec {
override func spec() {
let weatherJSON: [String: Any] = try! JSONSerialization.jsonObject(with: try! Data.init(contentsOf: Bundle.test.url(forResource: "Weather", withExtension: "json")!)) as! [String: Any]
describe("parsing") {
it("should parse weather") {
@soxjke
soxjke / Weather.swift
Created October 26, 2017 15:45
Weather - ImmutableMappable
extension Weather: ImmutableMappable {
init(map: Map) throws {
effectiveDate = try map.value("EpochDate", using: DateTransform())
temperature = try map.value("Temperature")
realFeel = try map.value("RealFeelTemperature")
day = try map.value("Day")
night = try map.value("Night")
}
func mapping(map: Map) {
}
@soxjke
soxjke / WeatherSpec.swift
Created October 28, 2017 08:31
WeatherSpec - Step2
class WeatherSpec: QuickSpec {
override func spec() {
let weatherJSON: [String: Any] = try! JSONSerialization.jsonObject(with: try! Data.init(contentsOf: Bundle.test.url(forResource: "Weather", withExtension: "json")!)) as! [String: Any]
describe("parsing") {
let weather = try? Weather(JSON: weatherJSON)
it("should parse weather") {
expect(weather).notTo(beNil())
}
it("should parse precipitation probability") {
expect(weather!.day.precipitationProbability).to(equal(12))
import Foundation
import ObjectMapper
struct Geoposition {
let localizedName: String
let englishName: String
let localizedRegion: String
let englishRegion: String
let country: String
let key: String
{
"Version": 1,
"Key": "274357",
"Type": "City",
"Rank": 75,
"LocalizedName": "Sao Vicente",
"EnglishName": "Sao Vicente",
"PrimaryPostalCode": "",
"Region": {
"ID": "EUR",