Skip to content

Instantly share code, notes, and snippets.

extension Task where Failure == Error {
// Start a new Task with a timeout. If the timeout expires before the operation is
// completed then the task is cancelled and an error is thrown.
init(priority: TaskPriority? = nil, timeout: TimeInterval, operation: @escaping @Sendable () async throws -> Success) {
self = Task(priority: priority) {
try await withThrowingTaskGroup(of: Success.self) { group -> Success in
group.addTask(operation: operation)
group.addTask {
try await _Concurrency.Task.sleep(nanoseconds: UInt64(timeout * 1_000_000_000))
@hungeric
hungeric / NavigationSplitViewExample.swift
Created July 18, 2023 05:30 — forked from Dimillian/NavigationSplitViewExample.swift
An example on how to use the new NavigationSplitView on iPad with global navigation
import SwiftUI
enum HomeDestination: String, CaseIterable, Hashable {
case hot, best, trending, new, top, rising
}
enum SubredditDestination: String, CaseIterable, Hashable {
case news, diablo, pics, wtf, games, movies
}
enum UserDestination: String, CaseIterable, Hashable {
@hungeric
hungeric / gist:c04e606cc7ef2333993f30413eb846f0
Created March 16, 2023 03:17 — forked from tomohisa/gist:2897676
Add and Remove ChildViewController
// add child view
UIViewController* controller = [self.storyboard instantiateViewControllerWithIdentifier:@"test"];
[self addChildViewController:controller];
controller.view.frame = CGRectMake(0, 44, 320, 320);
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
// remove child view
UIViewController *vc = [self.childViewControllers lastObject];
[vc.view removeFromSuperview];
@hungeric
hungeric / TaskConcurrencyManifesto.md
Created April 18, 2022 16:10 — forked from lattner/TaskConcurrencyManifesto.md
Swift Concurrency Manifesto
@hungeric
hungeric / SimpleRepositoryPatternIn.swift
Created April 5, 2020 21:30 — forked from omayib/SimpleRepositoryPatternIn.swift
Introducing repository pattern with swift.
//: Playground - noun: a place where people can play
import UIKit
class Todo{
var tempId: UUID?
var id : Int
var title: String
var isCompleted: Bool
@hungeric
hungeric / gist:154b3f34e954db9eec0b488aedcef8dd
Created February 13, 2020 07:44 — forked from gimenete/gist:53704124583b5df3b407
Animated rootViewController transition
// put this in your AppDelegate
- (void)changeRootViewController:(UIViewController*)viewController {
if (!self.window.rootViewController) {
self.window.rootViewController = viewController;
return;
}
UIView *snapShot = [self.window snapshotViewAfterScreenUpdates:YES];
[viewController.view addSubview:snapShot];
self.window.rootViewController = viewController;
@hungeric
hungeric / gist:a557ac29e855b4f96454be8d0756ee41
Created February 13, 2020 07:44 — forked from gimenete/gist:53704124583b5df3b407
Animated rootViewController transition
// put this in your AppDelegate
- (void)changeRootViewController:(UIViewController*)viewController {
if (!self.window.rootViewController) {
self.window.rootViewController = viewController;
return;
}
UIView *snapShot = [self.window snapshotViewAfterScreenUpdates:YES];
[viewController.view addSubview:snapShot];
self.window.rootViewController = viewController;
@hungeric
hungeric / .gitignore
Created June 12, 2019 07:20 — forked from smebberson/.gitignore
Express simple authentication example
node_modules
*.swp
@hungeric
hungeric / curl.md
Created October 17, 2018 04:21 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@hungeric
hungeric / udid-faq.md
Created August 14, 2018 01:20 — forked from hujunfeng/udid-faq.md
UDID, identifierForVendor and advertisingIdentifier FAQ

What's the difference between UUID, GUID and UDID?

  • UUID (Universally Unique Identifier): A sequence of 128 bits that can guarantee uniqueness across space and time, defined by [RFC 4122][rfc4122].

  • GUID (Globally Unique Identifier): Microsoft's implementation of the UUID specification; often used interchangeably with UUID.

  • UDID _(Unique Device Identifier)): A sequence of 40 hexadecimal characters that uniquely identify an iOS device (the device's Social Security Number, if you will). This value can be retrieved through iTunes, or found using UIDevice -uniqueIdentifier. Derived from hardware details like MAC address.

Is UDID deprecated?