Skip to content

Instantly share code, notes, and snippets.

View iAmrSalman's full-sized avatar

Amr Salman iAmrSalman

View GitHub Profile
@iAmrSalman
iAmrSalman / UIColorExtension.swift
Last active November 9, 2017 07:47
[color from hex] #uicolor #extension
import UIKit
extension UIColor {
func colorFromHexString (_ hex:String, alpha: Float = 1.0) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
@iAmrSalman
iAmrSalman / UIViewControllerExtension.swift
Created November 9, 2017 07:49
[viewController from Storyboard] #uiviewcontroller #swift3 #extension
import UIKit
extension UIViewController {
func viewController(withStoryBoardname storyBoardName : String) -> UIViewController? {
let storyboard = UIStoryboard(name: storyBoardName, bundle: .main)
let controller = storyboard.instantiateInitialViewController()
return controller
}
@iAmrSalman
iAmrSalman / UIColorExtension.swift
Created November 9, 2017 08:21
[color from hex] #uicolor #extension
extension UIColor {
convenience init(red: Int, green: Int, blue: Int, alpha: CGFloat) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: alpha)
}
convenience init(netHex:Int, alpha: CGFloat = 1.0) {
self.init(red:(netHex >> 16) & 0xff, green:(netHex >> 8) & 0xff, blue:netHex & 0xff, alpha: alpha)
@iAmrSalman
iAmrSalman / UIColor+FlatColors.swift
Created November 9, 2017 10:37
[flat colors] #uicolor #extension
extension UIColor {
struct FlatColor {
struct Green {
static let Fern = UIColor(netHex: 0x6ABB72)
static let MountainMeadow = UIColor(netHex: 0x3ABB9D)
static let ChateauGreen = UIColor(netHex: 0x4DA664)
static let PersianGreen = UIColor(netHex: 0x2CA786)
}
struct Blue {
@iAmrSalman
iAmrSalman / loopable.swift
Created December 12, 2017 12:15
[Loopable] #protocol #swift
protocol Loopable {
var allProperties: [String: Any] { get }
}
extension Loopable {
var allProperties: [String: Any] {
var result = [String: Any]()
Mirror(reflecting: self).children.forEach { child in
if let property = child.label {
result[property] = child.value
}
@iAmrSalman
iAmrSalman / refreshControl.swift
Created January 2, 2018 10:34
[Add Pull-to-Refresh] #swift #uitableview
// Configure Refresh Control
refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged)
refreshControl.tintColor = UIColor.Kotobi.red
if #available(iOS 10.0, *) {
self.tableView.refreshControl = refreshControl
} else {
self.tableView.addSubview(refreshControl)
}
@iAmrSalman
iAmrSalman / setupCollectionView.swift
Last active January 16, 2018 08:09
[setup collectionView] #uicollectionview #swift3
private func setupCollectionView() {
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(UINib.init(nibName: "NIB_NAME", bundle: nil), forCellWithReuseIdentifier: "cell")
setupCellSizing()
}
private func setupCellSizing() {
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
@iAmrSalman
iAmrSalman / Sharable.swift
Last active April 7, 2018 19:36
[Sharable] a protocol to handle sharing via UIActivityViewController #swift #protocol
import UIKit
protocol Sharable {
func share(_ str: String, source: UIView?, completionHandler: ((_ completed: Bool) -> Void)?)
}
extension Sharable where Self: UIViewController {
func share(_ str: String, source: UIView? = nil, completionHandler: ((_ completed: Bool) -> Void)? = nil) {
let activityController = UIActivityViewController.init(activityItems: [str], applicationActivities: nil)
activityController.popoverPresentationController?.sourceView = source ?? self.view
@iAmrSalman
iAmrSalman / MacPowerUser.md
Created January 26, 2018 15:13
This is my collection of Apps & Tools for macOS

Mac Power User

This is my collection of Apps & Tools for macOS

Terminal

  • Homebrew: The missing package manager for macOS
  • Homebrew-Cask: extends Homebrew and brings its elegance, simplicity, and speed to the installation and management of GUI macOS applications such as Atom and Google Chrome.
  • Mac-CLI: macOS command line tools for developers
@iAmrSalman
iAmrSalman / Reachability.swift
Created February 12, 2018 09:43
[Reachability.swift] #swift #networkimg
//
// Reachability.swift
//
// Created by Amr Salman on 4/4/17.
//
//
import Foundation
import SystemConfiguration
import UIKit
import SystemConfiguration.CaptiveNetwork