Skip to content

Instantly share code, notes, and snippets.

View MMnasrabadi's full-sized avatar
🤠
i am happy

Mohammad Mohammadi Nasrabadi MMnasrabadi

🤠
i am happy
View GitHub Profile
@MMnasrabadi
MMnasrabadi / EntryPoint.swift
Created July 8, 2024 06:25 — forked from IanKeen/EntryPoint.swift
Example main.swift
import Foundation
import SwiftUI
let isUITesting = /* your UI test detection here */
@main
struct EntryPoint {
static func main() {
if isUITesting {
UITestApp.main()
Registered Name: https://zhile.io
License Key: 48891cf209c6d32bf4
@MMnasrabadi
MMnasrabadi / DocumentPicker.swift
Created December 16, 2020 15:39 — forked from aheze/DocumentPicker.swift
UIDocumentPickerViewController example in Swift 5. Bug fixed version of this article: https://medium.com/flawless-app-stories/a-swifty-way-to-pick-documents-59cad1988a8a
//
// DocumentPicker.swift
import UIKit
import MobileCoreServices
protocol DocumentDelegate: class {
func didPickDocument(document: Document?)
}
@MMnasrabadi
MMnasrabadi / gist:c35337677c2d368dab967eeab685ff75
Created September 12, 2020 17:31 — forked from ebraminio/gist:5292017
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir
// Check Iranian National Code Validity - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، روبی، جاوااسکریپت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو، سوئیفت، کاتلین، گرووی، راست، هسکل، ارلنگ، الکسیر
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست http://www.fardanews.com/fa/news/127747
// بعضی از پیاده‌سازی‌ها سریع نیستند، می‌توانید نسخهٔ خود را بر پایهٔ
// نسخهٔ سی یا گو ایجاد کنید که بهترین سرعت را داشته باشد
/**
@MMnasrabadi
MMnasrabadi / UserDefaults+Codable+propertyWrapper.swift
Created August 26, 2020 12:59 — forked from quangDecember/UserDefaults+Codable+propertyWrapper.swift
property wrappers for saving to UserDefaults, generics or Codable
import Foundation
@propertyWrapper
struct UserDefault<T> {
let key: String
let defaultValue: T
init(_ key: String, defaultValue: T) {
self.key = key
func using<T: AnyObject>(object: T, execute: (T) throws -> Void) rethrows -> T {
try execute(object)
return object
}
import UIKit
// Then in some configureView() function of an UIViewController or whatnot…
let label1 = using(UILabel()) {
@MMnasrabadi
MMnasrabadi / CopyLabel.swift
Created June 20, 2020 11:42 — forked from AliSoftware/CopyLabel.swift
An UILabel subclass which allows you to show the "copy" MenuController item to copy its content to the pasteboard
import UIKit
class CopyLabel : UILabel {
// MARK: Setup
override init(frame: CGRect) {
super.init(frame: frame)
configureMenu()
}
@MMnasrabadi
MMnasrabadi / Bindings.swift
Created June 20, 2020 11:39 — forked from AliSoftware/Bindings.swift
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
enum Demo {
case simple
case oneValue(Int)
case twoValues(String, Double)
case threeValues(one: Int, two: Float, [Int])
}
//: # Direct exposition in the enum
//: ## Sourcery Template
// Xcode 11b1
@propertyDelegate
struct Clamped<Value: Comparable> {
private var storage: Value
private var clamp: (Value) -> Value
init(min: Value, max: Value, initialValue: Value) {
let clampingFunction = { ($0...$0).clamped(to: min...max).lowerBound }
self.storage = clampingFunction(initialValue)