Skip to content

Instantly share code, notes, and snippets.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
/// 1. Capture the scene
guard let windowScene = (scene as? UIWindowScene) else { return }
/// 2. Create a new UIWindow using the windowScene constructor which takes in a window scene.
let window = UIWindow(windowScene: windowScene)
/// 3. Create a view hierarchy programmatically
let viewController = ArticleListViewController()
@munho
munho / URLSession tutorial .md
Created November 29, 2023 07:11 — forked from hertz315/URLSession tutorial .md
URLSession API 호출 정리
@munho
munho / Simple-browser-WKWebView-UIKit.md
Created November 2, 2023 08:07 — forked from quangDecember/Simple-browser-WKWebView-UIKit.md
Creating Simple Web Browser with WKWebView & UINavigationController

WKWebView was first introduced on iOS 8. With Apple finally release a deadline for all apps to migrate away from UIWebView, this series and this post is here to help you explore the features of WKWebView. In this blog post you will create a simple web browser with some basic features such as displaying content, back and forward.

Setup Previews for your project

One of the most interesting things coming out with Xcode 11 is SwiftUI's PreviewProvider, which provides a way to preview the UI during development instantly on multiple devices, multiple settings at the same time.

To preview UIViewController and UIView, you need to download previewing code from NSHipster

Since we are making this browser with a navigation bar, our main UIViewController needs to be embedded inside a UINavigationController. Therefore the previewing code would be like this:

@munho
munho / shell-setup.ps1
Created August 16, 2023 03:54 — forked from mikepruett3/shell-setup.ps1
Packages to install via scoop, winget, choco, and other tools...
<#
.SYNOPSIS
Script to Initialize my custom powershell setup.
.DESCRIPTION
Script uses scoop
.NOTES
**NOTE** Will configure the Execution Policy for the "CurrentUser" to Unrestricted.
Author: Mike Pruett
Date: October 18th, 2018
@munho
munho / collectIt.kt
Created June 2, 2022 01:24 — forked from mahdiPourkazemi/gist:5b30e934e1bb48d0636a4f9d5aa6b222
remove bracket hell for using flow
fun <T> StateFlow<T>.collectIt(lifecycleOwner: LifecycleOwner, function: (T) -> Unit) {
// Create a new coroutine in the lifecycleScope
lifecycleOwner.lifecycleScope.launch {
// repeatOnLifecycle launches the block in a new coroutine every time the
// lifecycle is in the STARTED state (or above) and cancels it when it's STOPPED.
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED){
collect {
// Trigger the flow and start listening for values.
// This happens when lifecycle is STARTED and stops
// collecting when the lifecycle is STOPPED
@munho
munho / characteristic.js
Created March 14, 2022 05:29 — forked from jhays/characteristic.js
A sample BLE peripheral service and characteristic for use with Node.js and bleno.
/* characteristic.js
* A simple custom BLE peripheral characteristic for use with Node.js and bleno.
* This characteristic supports read, write, and notify properties.
* Julian Hays - 10/14/19
*/
var util = require('util');
var bleno = require('bleno-mac'); //or 'bleno-mac' if you are using that
var BlenoCharacteristic = bleno.Characteristic;
@munho
munho / RxSwiftExample.swift
Created February 23, 2022 06:03 — forked from saiday/RxSwiftExample.swift
RxSwift callback chaining
func fetchUserId() -> Observable<String> {
return create{ (observer) -> Disposable in
Client.fetchUserId() { [unowned self]
(userId: String?, err: ErrorType?) -> Void in
if let _ = err{
observer.on(Event.Error(err!))
} else {
observer.on(Event.Next(userId))
observer.on(Event.Completed)
}
this += repository.getImages(params)
.compose(applySingleAsync())
.subscribe { result ->
result.fold(
onSuccess = { },
onFailure = { }
)
}
internal class ImagesRepositoryImpl(private val source: ImageDataSource) : ImagesRepository {
override fun getImages(params: Map<String, String>): Single<Result<ImagesResponse>> {
return source.getImages(params)
.map { Result.success(it) }
.compose(applyRetryPolicy(TIMEOUT, maxRetries = 5, interval = 2, unit = TimeUnit.SECONDS) { Single.just(Result.failure(it)) })
}
}
internal typealias RETRY_PREDICATE = (Throwable) -> Boolean
internal const val MAX_RETRIES = 3L
internal const val DEFAULT_INTERVAL = 1L
internal val TIMEOUT: RETRY_PREDICATE = { it is SocketTimeoutException }
internal val NETWORK: RETRY_PREDICATE = { it is IOException }
internal val SERVICE_UNAVAILABLE: RETRY_PREDICATE = { it is HttpException && it.code() == 503 }
internal fun <T> applyRetryPolicy(