Skip to content

Instantly share code, notes, and snippets.

View amrangry's full-sized avatar
🎯
Focusing

Amr Elghadban amrangry

🎯
Focusing
View GitHub Profile
@amrangry
amrangry / UserDefaultsManager.swift
Last active February 5, 2024 17:19
UserDefaultsManager is a manager and wrapper class for UserDefaults
//
// UserDefaultsManager.swift
// Www.ADKATech.com
//
// Created by AmrAngry on 7/30/19.
// Modifyed by AmrAngry on 5/5/20.
// Copyright © 2019 Www.ADKATech.com. All rights reserved.
// Generic use original mestion by (FB)محمود زكى and hamada147(Github)
import Foundation
@RichAppz
RichAppz / UICollectionView+Extension.swift
Last active December 7, 2020 11:15
UICollectionView+Extension
import Foundation
import UIKit
public extension UICollectionView {
/**
Register nibs faster by passing the type - if for some reason the `identifier` is different then it can be passed
- Parameter type: UICollectionView.Type
- Parameter identifier: String?
*/
@m25lazi
m25lazi / ReadEnvironmentVariable.swift
Created January 7, 2020 15:18
Snippet for reading environment variables.
var shouldLogTextAnalyzer = false
if ProcessInfo.processInfo.environment["text_analyzer_log"] == "verbose" {
shouldLogTextAnalyzer = true
}
if shouldLogTextAnalyzer {
/// Actual logger code
}
import Foundation
import UIKit
struct ViewStyle<T> {
let style: (T) -> Void
}
let filled = ViewStyle<UIButton> {
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .red
@bpolania
bpolania / DataExtensions.swift
Last active January 25, 2024 07:10
Swift Extensions for Data, Int, UInt8, UInt16, and UInt32 types
// MIT License
// Copyright (c) 2018 Boris Polania
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@nathanfjohnson
nathanfjohnson / String+HTML.swift
Last active November 23, 2021 15:09 — forked from mwaterfall/StringExtensionHTML.swift
Decoding HTML Entities in Swift 4
// Swift 4
// Check out the history for contributions and acknowledgements.
extension String {
/// Returns a new string made by replacing all HTML character entity references with the corresponding character.
///
/// - Returns: decoded string
func decodingHTMLEntities() -> String {
var result = String()
var position = startIndex
@budidino
budidino / string-truncate.swift
Last active April 3, 2024 20:11 — forked from vicc/string-truncate.swift
String truncate extension for Swift 4
extension String {
/*
Truncates the string to the specified length number of characters and appends an optional trailing string if longer.
- Parameter length: Desired maximum lengths of a string
- Parameter trailing: A 'String' that will be appended after the truncation.
- Returns: 'String' object.
*/
func trunc(length: Int, trailing: String = "…") -> String {
return (self.count > length) ? self.prefix(length) + trailing : self
//: A UIKit based Playground to present user interface
import UIKit
import PlaygroundSupport
protocol Traceable {
var cornerRadius: CGFloat { get set }
var borderColor: UIColor? { get set }
var borderWidth: CGFloat { get set }
@amrangry
amrangry / DataTask.swift
Created March 20, 2017 08:29
this file is aiming to use URLSession to make a web service api call using swift 3
//
// DataTask.swift
//
//
// Created by Amr AlGhadban on 2/15/17.
// Copyright © 2017 Amr AlGhadban. All rights reserved.
//
import Foundation
@edmund-h
edmund-h / generateRandomDate.swift
Last active August 13, 2021 17:47
A function to create a random date in Swift 3
// credit to @eirnym, adapted this from their OBJC code: https://gist.github.com/eirnym/c9526a045556e4d8464b41a367843e3c
// generates a random date and time in the past, limited by daysBack (a number of days before today)
// also generates a random time to go with that date.
// original request: http://stackoverflow.com/questions/10092468/how-do-you-generate-a-random-date-in-objective-c
func generateRandomDate(daysBack: Int)-> Date?{
let day = arc4random_uniform(UInt32(daysBack))+1