Skip to content

Instantly share code, notes, and snippets.

View dimohamdy's full-sized avatar
🏠
Working from home

Dimo Hamdy dimohamdy

🏠
Working from home
View GitHub Profile
@dimohamdy
dimohamdy / CoordinatorExtended.swift
Created November 13, 2019 08:35 — forked from bocato/CoordinatorExtended.swift
An extended implementation of the Coordinator pattern.
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 {}
import UIKit
class BookCollectionViewCell: UICollectionViewCell {
var book: Book!
func configureCellWith(_ book: Book) {
self.book = book
}
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)
}
weak var sourceVC: UIViewController!
//make it weak to avoid retain cycle
func registerFor3DTouch(viewController: UIViewController?) {
if let viewController = viewController {
sourceVC = viewController
}
}
class IqraaliCollectionViewCell: UICollectionViewCell {
var book: BookEntity!
}
extension BookCollectionViewCell: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
return AboutBookViewControllerWith(book)
}
import Foundation
extension String {
func fileName() -> String {
return URL(fileURLWithPath: self).deletingPathExtension().lastPathComponent
}
func fileExtension() -> String {
return URL(fileURLWithPath: self).pathExtension
}
import Vapor
/// Register your application's routes here.
public func routes(_ router: Router) throws {
let imageResizeController = ImageResizeController()
try router.register(collection: imageResizeController)
}
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
import Vapor
import SwiftGD
final class ImageResizeController: RouteCollection {
func boot(router: Router) throws {
let routes = router.grouped("resize")
routes.get(use: index)
}
.package(url: "https://github.com/twostraws/SwiftGD.git", from: "2.0.0")