Skip to content

Instantly share code, notes, and snippets.

View regularberry's full-sized avatar

Sean Berry regularberry

View GitHub Profile
class MutableClass {
var val: Int?
init(val: Int = 0) {
self.val = val
}
func update(newVal: Int) {
val = nil
val = newVal
dict["first"] = .some(nil)
if let val = dict["first"] {
print(val)
}
// prints ‘nil’
@regularberry
regularberry / nil.swift
Last active April 28, 2018 21:53
Not the right nil
var dict: [String: Any?] = ["first": nil, "second": 2]
if let val = dict["first"] {
print(val)
}
// Output: nil
dict["first"] = nil
if let val = dict["first"] {
print(val)
override fun onBindViewHolder(holder: ViewHolder,
position: Int,
payloads: MutableList<Any>) {
if (!payloads.isEmpty()) {
// Because these updates can be batched,
// there can be multiple payloads for a single bind
when (payloads[0]) {
Payload.FAVORITE_CHANGE -> {
// Change only the "favorite" icon,
// leave background image alone: