Skip to content

Instantly share code, notes, and snippets.

@janodev
janodev / idioms.swift
Last active June 29, 2018 16:17
initialising idioms
import UIKit
// this one doesn’t require a helper function
var label: UILabel = {
$0.backgroundColor = .blue
$0.text = "This is a playground"
$0.textColor = .white
$0.textAlignment = .center
return $0
@algal
algal / SwiftLineReader.swift
Last active February 8, 2023 16:14
Read a file one line at a time in Swift
import Darwin
/**
Returns a lazy sequence that returns a String for every line of `file`.
Example 1:
// print all lines from a file
let file = fopen(NSBundle.mainBundle().pathForResource("Cartfile", ofType: nil)!,"r")
for line in lineGenerator(file) { print(line,separator: "", terminator: "") }
fclose(file)
//
// Created by Eric Firestone on 3/22/16.
// Copyright © 2016 Square, Inc. All rights reserved.
// Released under the Apache v2 License.
//
// Adapted from https://gist.github.com/blakemerryman/76312e1cbf8aec248167
import Foundation