Skip to content

Instantly share code, notes, and snippets.

Josh Marasigan josh-marasigan

Block or report user

Report or block josh-marasigan

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
View ViewController.swift
// `.` indicates code left out.
// Please refer to the sample app for reference
// https://github.com/josh-marasigan/ObserverDesignExample
class ViewController: UIViewController {
.
.
.
// MARK: - Button Configuration
private func configChangeBackgroundButtonUI() {
.
View TitleAndTextView.swift
// `.` indicates code left out.
// Please refer to the sample app for reference
// https://github.com/josh-marasigan/ObserverDesignExample
// Somewhere in the TitleAndTextView.swift file
class TitleAndTextView: UIView {
.
.
.
// MARK: - Class Properties. Fun fact: emojis are just stirng literals
View ObserverKeys.swift
struct ObserverKeys {
static let teal = "observer-example.teal"
static let pink = "observer-example.magenta"
}
@josh-marasigan
josh-marasigan / SwiftMapExercise.swift
Last active Apr 28, 2018
Varying Swift syntax for map function
View SwiftMapExercise.swift
// Most verbose: No compiler assumptions are made, the closure to map
// receives a transforming function explicitly casted as (val: Int) -> Int
// Transforms an array of Int and multiplies each value by 10
arrValues.map({ (val: Int) -> Int in
return val * 10
})
// Compiler assumes return type for closure, no need to explicitly indicate
arrValues.map({ (val: Int) in
return val * 10
View DelegateRuntimeExample.swift
let josh = Son()
let joshsMom = Mom(son: josh)
joshsMom.tellJoshWhatToDo()
---
"Washing Dishes"
"Cleaning Room"
"Walking Nala"
View Son.swift
class Son: MomDelegate {
func washDishes() {
print("Washing Dishes")
}
func cleanRoom() {
print("Cleaning Room")
}
View DelegateProtocolExample.swift
protocol MomDelegate {
func washDishes()
func cleanRoom()
func walkNala()
}
View Mom.swift
class Mom {
var _son: Son
init(son: Son) {
self._son = son
}
func tellJoshWhatToDo() {
self._son.washDishes()
self._son.cleanRoom()
View GuardLet.swift
// Within a function
var box: String? = "Something"
guard let boxContents = box else { return }
print(boxContents)
---
"Something"
View IfLets.swift
// Ran in the same codeblock
var box1: String?
if let boxContents = box1 {
print(boxContents)
}
---
Nothing Prints
var box2: String? = "Something"
if let boxContents = box2 {
You can’t perform that action at this time.