Skip to content

Instantly share code, notes, and snippets.

View ihamadfuad's full-sized avatar
🧑‍💻
Coding

Hamad Fuad ihamadfuad

🧑‍💻
Coding
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
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: ihamadfouad@icloud.com
//
// Created At: 24/01/2022
// Last modified: 24/01/2022
//
@ihamadfuad
ihamadfuad / UniversalAlert.swift
Last active January 24, 2022 07:03
SwiftUI: Present Alert From Anywhere Using @Environment
// ºººº----------------------------------------------------------------------ºººº \\
//
// Credit Hamad Fuad.
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// 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)
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 15, 2024 18:34
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational