Skip to content

Instantly share code, notes, and snippets.

View ihamadfuad's full-sized avatar
🧑‍💻
Swifting with UI and server

Hamad Fuad ihamadfuad

🧑‍💻
Swifting with UI and server
View GitHub Profile
//
// ContentView.swift
// Emitter
//
// Created by localuser on 18.04.23.
//
import SwiftUI
import Combine
import Algorithms
@shayanbo
shayanbo / AsyncImage.swift
Last active July 6, 2023 09:42
Enhanced AsyncImage Sample
import SwiftUI
import CommonCrypto
struct AsyncImage<Content> : View where Content: View {
enum Error : Swift.Error {
case invalidData
}
private let url: URL
@MihaelIsaev
MihaelIsaev / AwesomeWSPing.swift
Created July 4, 2022 21:23
AwesomeWS automatic ping implementation
class YourCustomWS: ClassicObserver, LifecycleHandler {
var pingTask: RepeatedTask?
var waitForPongAttempts: [WaiterForPongAttempt] = []
public required init (app: Application, key: String, path: String, exchangeMode: ExchangeMode) {
super.init(app: app, key: key, path: path, exchangeMode: exchangeMode)
pingTask = app.eventLoop.scheduleRepeatedTask(initialDelay: .seconds(5), delay: .seconds(5)) { [weak self] task in
guard let self = self else { return }
self.waitForPongAttempts.enumerated().forEach { i, object in
if object.attempt >= 2 {
extension Notification.Name {
static let taskAddedNotification = Notification.Name("TaskAddedNotification")
}
struct ListenToNotificationChanges: View {
@State private var newTask: String?
var body: some View {
VStack {
@ihamadfuad
ihamadfuad / SheetViewPresenter.swift
Created January 24, 2022 07:02
SwiftUI: Present Sheet From Anywhere Using @Environment
// ºººº----------------------------------------------------------------------ºººº \\
//
// Credit Hamad Fuad.
//
// Author: Hamad Fuad
// Email: [email protected]
//
// Created At: 24/01/2022
// Last modified: 24/01/2022
//
@ihamadfuad
ihamadfuad / UniversalAlert.swift
Last active December 2, 2024 02:28
SwiftUI: Present Alert From Anywhere Using @Environment
// ºººº----------------------------------------------------------------------ºººº \\
//
// Credit Hamad Fuad.
//
// Author: Hamad Fuad
// Email: [email protected]
//
// Created At: 24/01/2022
// Last modified: 24/01/2022
//
@insidegui
insidegui / ScrollViewOffsetModifier.swift
Created July 20, 2021 20:28
A SwiftUI ViewModifier that can be used to read a ScrollView's offset and store it into a @State property of the view
struct ScrollViewOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGPoint = .zero
static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {
value = nextValue()
print("value = \(value)")
}
typealias Value = CGPoint
@inket
inket / PreviewScreenshot.swift
Last active July 28, 2024 23:57
How to take screenshots of SwiftUI previews
#if DEBUG
import SwiftUI
private let screenshotDirectory = "/Users/inket/Desktop/"
struct PreviewScreenshot: ViewModifier {
struct LocatorView: UIViewRepresentable {
let tag: Int
func makeUIView(context: Context) -> UIView {
//
// CodableExtensionExample.swift
//
// Created by Pramod Kumar on 05/15/20.
// Copyright © 2020 Swift Commmunity. All rights reserved.
//
import UIKit
let json = """
@quocnb
quocnb / UserNotificationsExample.swift
Last active March 16, 2022 12:28
UserNotifications iOS 10 Example
import UserNotifications
// 1. Request Permission
func requestAuthorization() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (granted, error) in
if granted {
// Success
} else {
// Error
print(error?.localizedDescription)