Skip to content

Instantly share code, notes, and snippets.

View m1entus's full-sized avatar

Michał Zaborowski m1entus

View GitHub Profile
@wakinchan
wakinchan / generate-target-dependencies.sh
Last active February 29, 2024 13:14
Generate Target Dependencies for Package.swift
#!/usr/bin/env sh
# usage: sh ./generate-target-dependencies.sh | dot -Tsvg -o target-graph.svg
packages=`swift package describe --type json`
targets=`echo $packages | jq '.targets'`
target_names=`echo $targets | jq -r '.[] | .name'`
body=""
template=`cat <<EOF
digraph DependenciesGraph {
@krzyzanowskim
krzyzanowskim / AsyncWaiter.swift
Last active June 25, 2022 12:25
Synchronously (well) wait for async Task value update https://twitter.com/krzyzanowskim/status/1523233140914876416
/// Wait for async operation to return value and call callback with the value
/// This class is intended to workaround/simplify async/await + actors isolation
/// https://twitter.com/krzyzanowskim/status/1523233140914876416
private class AsyncWaiter<T> {
var didReceiveValue: Bool = false
let value: (T) -> Void
let operation: () async throws -> T
init(_ value: @escaping (T) -> Void, operation: @escaping () async throws -> T) {
self.value = value
#!/bin/sh
#
# Disable Siri Suggestions on Simulators and SwiftUI Previews to
# avoid Spotlight heating up your MacBook by keeping 4 cores busy
# at 100%.
#
# See https://developer.apple.com/forums/thread/683277
#
import Combine
import Foundation
@available(iOS 13.0, macOS 10.15, tvOS 13, watchOS 6, *)
public struct ObjectDidChangePublisher<ObjectWillChangePublisher: Publisher>: Publisher {
private let upstream: ObjectWillChangePublisher
public typealias Output = ObjectWillChangePublisher.Output
public typealias Failure = ObjectWillChangePublisher.Failure
fileprivate init(upstream: ObjectWillChangePublisher) {
import SwiftUI
import UIKit
struct ContentView: View {
var body: some View {
NoSepratorList {
Text("Message 1")
Text("Message 1")
Text("Message 1")
Text("Message 1")
@wotjd
wotjd / debug_preview.swift
Created May 14, 2020 04:26
resolve sizeThatFits not working on Xcode Preview using UIView
import SwiftUI
// https://medium.com/@lyeskinnikitaalexandrovich/mastering-xcode-previews-with-snapkit-uikit-aa82a146059a
enum DebugPreviewLayout {
case fitWidth(CGFloat)
case fitHeight(CGFloat)
case `default`
}
final class DebugPreviewLayoutView: UIView {
@groue
groue / CancelBag.swift
Last active April 5, 2024 19:12
CancelBag
import Combine
import Foundation
/// A thread-safe store for cancellables which addresses usability pain points
/// with stock Combine apis.
///
/// ## Thread-safe storage of cancellables
///
/// let cancelBag = CancelBag()
/// cancellable.store(in: cancelBag)
@TheMetalCode
TheMetalCode / A_Way_To_Mostly_Automate_FastlaneSession_Update.md
Last active June 17, 2022 19:21
Mostly Automated Way to Update FASTLANE_SESSION

fastlane/fastlane#13833

This script may be useful to you if you use fastlane for iOS CI builds and your Apple developer portal account uses 2-factor authentication. There is reason to suppose that Apple may not be persisting these sessions for as long as they used to, and hence you might find yourself needing to update FASTLANE_SESSION for your CI projects more often than usual.

This script is a way to mostly automate the process of updating FASTLANE_SESSION if you use CircleCI as your CI provider. It expects to find your Apple username in env as FASTLANE_USER, your Apple password as FASTLANE_PASSWORD, and your CircleCI API token as CIRCLE_API_TOKEN. It then executes fastlane spaceauth and waits for you to put in your 2FA code. From there, it parses out the session data and then uses the CircleCI API to populate the specified projects with the newly updated FASTLANE_SESSION. You'll

@shaps80
shaps80 / Scheduling-AppDelegate.swift
Last active February 16, 2022 03:14
NSNotification Scheduling Service in Swift. (the only required file is `SchedulingService.swift`)
//
// AppDelegate.swift
// Scheduling
//
// Created by Shaps Benkau on 19/02/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
//
import UIKit
@Marcocanc
Marcocanc / Equatable+CheckIfEqualTo.swift
Created January 27, 2018 12:24
Easily compare two objects by using KeyPath
extension Equatable {
func checkIfEqualTo<T: Equatable>(_ other: Self, byComparing paths: KeyPath<Self,T>...) -> Bool {
for keyPath in paths {
guard self[keyPath: keyPath] == other[keyPath: keyPath] else {
return false
}
}
return true
}
}