swift
let inputInt = Int(readline()!)!
let arrayInt = readlin()!.characters.split { $0== " " }.map { Int(String($0))! }
// nice quick and dirty webserver | |
const http = require('http') | |
const port = process.env.PORT || 3000 | |
const server = http.createServer((req, res) => { | |
res.writeHead(200, { 'Content-Type': 'text/plain '}) | |
res.end('Hello world! this is a noob server') | |
}) |
let inputInt = Int(readline()!)!
let arrayInt = readlin()!.characters.split { $0== " " }.map { Int(String($0))! }
import Foundation | |
// async swift playground | |
import PlaygroundSupport | |
// https://min-api.cryptocompare.com/data/all/coinlist | |
let allCoinsPath = "/data/all/coinlist" | |
class CryptoApi { |
// brushing up on url components | |
// | |
class CryptoApi { | |
static let host = "min-api.cryptocompare.com" | |
static let allCoinsPath = "/data/all/coinlist" | |
var allCoinsUrl: URL? = { | |
var urlComponents = URLComponents() | |
urlComponents.scheme = "https" | |
urlComponents.host = CryptoApi.host |
// brushing up on url components | |
// | |
class CryptoApi { | |
static let host = "min-api.cryptocompare.com" | |
static let allCoinsPath = "/data/all/coinlist" | |
var allCoinsUrl: URL? = { | |
var urlComponents = URLComponents() | |
urlComponents.scheme = "https" | |
urlComponents.host = CryptoApi.host |
// https://stackoverflow.com/questions/23806751/strong-reference-to-a-weak-references-inside-blocks | |
__weak typeof(self) weakSelf = self; | |
void (^someBlock)(id) = ^(id data){ | |
if (weakSelf != nil) { | |
// last remaining strong reference released by another thread. | |
// weakSelf is now set to nil. | |
[myArray addObject:weakSelf]; | |
} | |
}); |
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html#//apple_ref/doc/uid/TP40011210-CH8-SW16 | |
@interface XYZBlockKeeper : NSObject | |
@property (copy) void (^block)(void); | |
@end | |
@implementation XYZBlockKeeper | |
- (void)configureBlock { | |
self.block = ^{ | |
[self doSomething]; // capturing a strong reference to self |
protocol RowPresentable { | |
var string: String { get } | |
// it conforms to both protocol + class | |
var rowVC: UIViewController & PanModalPresentable { get } | |
} |
// thanks dude | |
// https://medium.com/@dushyant_db/setting-up-a-container-view-using-interface-builder-and-via-code-7ac1a7f0a0d6 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController else { | |
return | |
} | |
addChildViewController(childVC) |
// thanks dude | |
// https://medium.com/@dushyant_db/setting-up-a-container-view-using-interface-builder-and-via-code-7ac1a7f0a0d6 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController else { | |
return | |
} | |
addChildViewController(childVC) |