Skip to content

Instantly share code, notes, and snippets.

@soffes
soffes / BaseTextStorage.swift
Last active July 1, 2023 10:14
Fast, concrete text storage intended to be subclassed.
import UIKit
/// Fast, concrete text storage intended to be subclassed.
class BaseTextStorage: NSTextStorage {
// MARK: - Properties
private let storage = NSMutableAttributedString()
// MARK: - NSTextStorage
import UIKit
extension UIEdgeInsets {
init(_ value: CGFloat) {
top = value
left = value
right = value
bottom = value
}
@ronshapiro
ronshapiro / iOS_Android_Vocab_Cheat_Sheet.md
Last active February 1, 2023 07:54
iOS <> Android Vocab Cheat Sheet

iOS <> Android Vocab Cheat Sheet

A couple months ago while at Venmo, @chrismaddern and I discussed the lack of a bidirectional dictionary/vocab list of parallel terms in Android and iOS. It's important to know what your teammates are refering when they talk about code, even if you're not engaged with it every day. This is a beginning attempt to finally break down that knowledge gap. The goal is to allow developers of one framework to understand the basics of the other and should someone want to make the switch, this can be a resource in helping learn the new framework.

If there's a topic that you think would be interesting to discuss, tweet at me and we'll get include it in this list. I'll be updating this post with links to all future posts.

Disclaimer: I'm an Android developer and have done minimal iOS/Objective-C programming. If there is anything incorrect, reach out and I'll fix it as soon as possible. I'm assuming iOS developer are

WWDC 2014 Brain Lanier

Optionals

  • Cleaner alternative to using sentinels (NULL, NSNotFound, etc.) to represent invalid values
  • optionals are initialized to nil by default
    • var optionalNumber: Int?
  • nil is a sentinel value that works with any type
  • value is wrapped in optional by setter
    • optionalNumber = 6
@ayanonagon
ayanonagon / FunctionApplication.playground
Created June 4, 2014 01:30
Function application using Swift
func fp<A, B, C>(fn:((A, B) -> C), arg:A) -> (B -> C) {
func apply(b:B) -> C {
return fn(arg, b)
}
return apply
}
func add(x: Int, y: Int) -> Int {
return x + y
}
@bunnyhero
bunnyhero / ReusableCellExample.m
Last active February 19, 2022 02:04
Example of Reactive Cocoa binding for a reusable cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:REUSABLE_CELL_ID];
UILabel *label = (UILabel *)[cell viewWithTag:VIEW_TAG];
Model *someModel = [self getModelFromIndexPath:indexPath];
// `takeUntil:` makes the RACObserve() signal complete (and thus breaks the subscription)
// when the cell is recycled.