Skip to content

Instantly share code, notes, and snippets.

View mkchoi212's full-sized avatar
🎯
Focusing

Mike JS. Choi mkchoi212

🎯
Focusing
View GitHub Profile
@mkchoi212
mkchoi212 / func_var_escape.swift
Last active December 28, 2017 19:59
Examples for escaping, no-escaping closures in Swift
struct Resource {
let parse : (String) -> (String)
}
// parseFunc is escaping createResource's scope by being stored off to
// randResource's parse variable
func createResource(parseFunc: @escaping (String) -> (String)) -> Resource{
let randResource = Resource(parse: parseFunc)
return randResource
}
@mkchoi212
mkchoi212 / optional_escape.swift
Last active December 28, 2017 19:58
Optional closures are escaping by default
struct RandData {
let parse: (String) -> (String)
}
// Note: There is no @escaping and no compiler warnings occur when parseFunc
// escapes the scope by being stored off to RandData struct.
//
// parseFunc can not be used as nonescaping since optional closures
// are also automatically escaping
func parseString(input: String, parseFunc: ((String) -> (String))?) {
// IMPLEMENTATION
enum LookupError: ErrorType {
case InvalidName
case NullData
}
enum UserResult {
case Success(String)
case Error(LookupError)
}
@mkchoi212
mkchoi212 / generic_result_enum.swift
Created February 5, 2017 13:24
Simple generic version of result enums
enum Result<T> {
case Success(T)
case Error(ErrorType)
}
// Example function signitures
func findUserAddress(name: String) -> Result<String>
func findUserAge(name: String) -> Result<Int>
@mkchoi212
mkchoi212 / beginner-issues.md
Last active July 11, 2018 04:04
VLC-iOS Beginner Issues
So you just ran
git clone https://github.com/videolan/vlc-ios.git
after deciding that you want to contribute to VLC-iOS. First thing is first; '''welcome to the community 🎉.'''<br>
To get you settled in, here are couple of issues beginners tend to run into when first trying to build and run the app.
= Running VLC-iOS =
== Podfile ==
@mkchoi212
mkchoi212 / testhelper.go
Created May 28, 2018 19:33
Go Test Helpers
package testhelper
import (
"fmt"
"path/filepath"
"reflect"
"runtime"
"testing"
)
@mkchoi212
mkchoi212 / UISwitchBackgroundViewBugDemo.swift
Last active June 19, 2018 02:53
UISwitch BackgroundView Bug Demo Playground File
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIStackView()
view.alignment = .center
view.distribution = .equalCentering
view.axis = .horizontal
view.backgroundColor = .black
@mkchoi212
mkchoi212 / VLCMediaNetworkingTest.swift
Created July 6, 2018 10:11
This is the ideal testing code to test VLCMedia::parse
func testLength() {
let tests: [(path: String, expected: VLCTime)] = [
("https://youtube.com/some_video_here", VLCTime(int: 12345)),
]
for (path, expected) in tests {
let media = VLCMedia(url: URL(string: path)!)
let expection = self.expectation(description: "mediaDidFinishParsing called")
let delegate = MockMediaDelegate(parseExpectation: expection)
media.delegate = delegate
@mkchoi212
mkchoi212 / VLCMediaPlayerTest.swift
Last active July 16, 2018 14:36
UI API called on a background thread problem while testing VLCMediaPlayer
class MockMediaPlayerDelegate: NSObject, VLCMediaPlayerDelegate {
let stateExpectation: XCTestExpectation?
init(stateExpectation: XCTestExpectation) {
self.stateExpectation = stateExpectation
}
func mediaPlayerStateChanged(_ aNotification: Notification!) {
guard let mediaPlayer = aNotification.object as? VLCMediaPlayer else {