Skip to content

Instantly share code, notes, and snippets.

Struct MovieData: Codable {
let data: Movies
}
Struct Movies: Codable {
let movies: [Movie]
}
Struct Movie: Codable {
let id: Int
{
"data": {
"movies": [ { "id": 1, "title": "title", "image_url":"loremipsum"} ]
}
}
@suprie
suprie / Chaining.swift
Created May 3, 2018 05:11
Create a method that chained each other. There is a name for this. But i forgot
//: Playground - noun: a place where people can play
import UIKit
class Test {
var username: String?
var password: String?
var onSuccess: (() -> (Void))? = nil
var onFailure: (() -> (Void))? = nil
struct Invoice {
private var invoiceId = 0
private var date = Date()
private var items = [Item]()
private var name = ""
private var paid = false
private var paymentData: Date?
func paid() {
paid = true
protocol ViewModelDelegate {
func dataLoaded();
}
class ViewModel {
private var objects: [Object]?
var delegate: ViewModelDelegate?
func getObjects() {
// .. do something fancy in background here
protocol ViewModelDelegate {
func dataLoaded();
}
class ViewModel {
var objects: [Object]?
var delegate: ViewModelDelegate?
func getObjects() {
// .. do something fancy in background here
@suprie
suprie / ViewController.swift
Created February 18, 2017 06:12
Slightly better
class ProductDataAdapter {
private var database: FMDatabase?
init() {
var paths: [Any] = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
var docsPath: String = paths[0]
var path: String = URL(fileURLWithPath: docsPath).appendingPathComponent("abc.sqlite").absoluteString
database = FMDatabase(path: path)
}
@suprie
suprie / ViewController.swift
Last active February 18, 2017 06:04
Bad Smelled VC
// Converted with Swiftify v1.0.6242 - https://objectivec2swift.com/
class ViewController {
override func viewDidAppear(_ animated: Bool) {
var paths: [Any] = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
var docsPath: String = paths[0]
var path: String = URL(fileURLWithPath: docsPath).appendingPathComponent("abc.sqlite").absoluteString
database = FMDatabase(path: path)
database.open()
@suprie
suprie / ViewController.swift
Last active May 6, 2020 19:51
Null Object Pattern in Swift
//
// ViewController.swift
// NullObject
//
// Created by Suprie on 1/18/16.
// Copyright © 2016 Suprie. All rights reserved.
//
import UIKit