Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Indrajit Chakrabarty indyfromoz

🏠
Working from home
Block or report user

Report or block indyfromoz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@indyfromoz
indyfromoz / SelfSizingTableViewCells.swift
Created Jan 3, 2020
Self-sizing UITableView cell - Force update of UI
View SelfSizingTableViewCells.swift
// Via @layoutSubviews in /dev/world2019
func tableView( _ tableView : UITableView, didSelectRowAt indexPath: IndexPath ) {
let cell = tableView.cellForRowAt( indexPath) as! MyCell
// Make some changes that affect the layout. Doing this but nothing else will cause clipped content.
cell.label.fontSize = 100
// We have to force the table view to recalculate the cell size and update the UI
tableView.beginUpdates()
tableView.endUpdates()
}
@indyfromoz
indyfromoz / KeyedDecodingContainer.swift
Created Dec 29, 2019
JSON decoder that handles an absent value or a null value
View KeyedDecodingContainer.swift
extension KeyedDecodingContainer {
func decodeIfPresentAndNotNullString<T>(_ type: T.Type, forKey key: Key) throws -> T? where T: Decodable {
do {
return try decodeIfPresent(type, forKey: key)
} catch {
if let valueAsString = try decodeIfPresent(String.self, forKey: key), valueAsString == "<null>" {
return nil
} else {
throw error
}
View ImageDownloadProtocol.swift
import UIKit
protocol ImageDownloadProtocol {
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void)
}
extension ImageDownloadProtocol {
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void) {
let session = URLSession(configuration: .default)
DispatchQueue.global(qos: .background).async {
@indyfromoz
indyfromoz / build.gradle
Created Oct 22, 2018
Build identifiers
View build.gradle
ext {
// Assumes Git is in your PATH
commitCount = {
return 'git rev-list --count HEAD'.execute().text.trim()
}
gitSha = {
return 'git rev-parse --short HEAD'.execute().text.trim()
}
@indyfromoz
indyfromoz / SolarizedDark.xccolortheme
Created Jul 23, 2017
Solarized Dark Theme for Xcode 8+
View SolarizedDark.xccolortheme
#Remove this line after copying the following to ~/Library/Developer/Xcode/UserData/FontAndColorThemes/SolarizedDark.xccolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.513725 0.580392 0.588235 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Regular - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
@indyfromoz
indyfromoz / cocoapods-install.md
Last active Sep 8, 2017
Installing & updating Cocoapods on a Mac
View cocoapods-install.md
@indyfromoz
indyfromoz / Obsidian.xccolortheme
Created Mar 30, 2017
Obsidian Xcode theme tested with Xcode 8.3
View Obsidian.xccolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 1 1 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SFMono-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 1 1 1</string>
@indyfromoz
indyfromoz / Go_Setup.md
Last active Jun 21, 2018
Go 1.8 setup on a Mac running Sierra 10.12.3+
View Go_Setup.md

Install Go with Homebrew

brew install go --cross-compile-common

Update Bash profile

export GOROOT=/usr/local/opt/go/libexec
View gist:2b2bb235fba798a4543a

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

You can’t perform that action at this time.