Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Ahmed Hamdy dimohamdy

🏠
Working from home
View GitHub Profile
View Date+Ago.swift
extension Date {
var timeAgo: String {
get {
let relativeDateFormatter = RelativeDateTimeFormatter()
//change these to get different formats
relativeDateFormatter.dateTimeStyle = .named
relativeDateFormatter.unitsStyle = .full
//you can know your loacal identifier here https://gist.github.com/jacobbubu/1836273
relativeDateFormatter.locale = Locale(identifier: "ar_EG")
let relativeDate = relativeDateFormatter.localizedString(for: self, relativeTo: Date())
View Optional+isNilOrEmpty.swift
import Foundation
extension Optional where Wrapped: Collection {
public var isNilOrEmpty: Bool {
switch self {
case .none:
return true
case .some(let collection):
return collection.isEmpty
}
@dimohamdy
dimohamdy / CoordinatorExtended.swift
Created Nov 13, 2019 — forked from bocato/CoordinatorExtended.swift
An extended implementation of the Coordinator pattern.
View CoordinatorExtended.swift
import UIKit
/// An enum that defines an output to be passed on from
/// a child to it's parents over the responders Chain
public protocol CoordinatorOutput {}
/// An enum that defines an input to be passed on from
/// the parent to it's childs
public protocol CoordinatorInput {}
View BookCollectionViewCell.swift
import UIKit
class BookCollectionViewCell: UICollectionViewCell {
var book: Book!
func configureCellWith(_ book: Book) {
self.book = book
}
View BookCollectionViewCell.swift
weak var viewControllerPreviewing: UIViewControllerPreviewing!
override func awakeFromNib() {
super.awakeFromNib()
if self.traitCollection.forceTouchCapability == .available {
if viewControllerPreviewing != nil {
sourceVC.unregisterForPreviewing(withContext: viewControllerPreviewing)
}
viewControllerPreviewing = sourceVC.registerForPreviewing(with: self, sourceView: self)
}
View BookCollectionViewCell.swift
weak var sourceVC: UIViewController!
//make it weak to avoid retain cycle
func registerFor3DTouch(viewController: UIViewController?) {
if let viewController = viewController {
sourceVC = viewController
}
}
View BookCollectionViewCell.swift
class IqraaliCollectionViewCell: UICollectionViewCell {
var book: BookEntity!
}
extension BookCollectionViewCell: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
return AboutBookViewControllerWith(book)
}
View String+Extension.swift
import Foundation
extension String {
func fileName() -> String {
return URL(fileURLWithPath: self).deletingPathExtension().lastPathComponent
}
func fileExtension() -> String {
return URL(fileURLWithPath: self).pathExtension
}
View routes.swift
import Vapor
/// Register your application's routes here.
public func routes(_ router: Router) throws {
let imageResizeController = ImageResizeController()
try router.register(collection: imageResizeController)
}
View FilesHelper.swift
struct FilesHelper {
//get image path in Public folder
static func getImagePath(fileName:String) -> URL{
let directory = DirectoryConfig.detect()
let workingDirectory = directory.workDir
let workingDirectoryPath = URL(fileURLWithPath:workingDirectory)
let destination = workingDirectoryPath.appendingPathComponent("Public/\(fileName)")
return destination
You can’t perform that action at this time.