Skip to content

Instantly share code, notes, and snippets.

Ahmed Hamdy dimohamdy

Block or report user

Report or block dimohamdy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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
View ImageResizeController.swift
import Vapor
import SwiftGD
final class ImageResizeController: RouteCollection {
func boot(router: Router) throws {
let routes = router.grouped("resize")
routes.get(use: index)
}
View Package.swift
.package(url: "https://github.com/twostraws/SwiftGD.git", from: "2.0.0")
You can’t perform that action at this time.