Skip to content

Instantly share code, notes, and snippets.

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

Aybek Can Kaya aybekckaya

🏠
Working from home
View GitHub Profile
extension UIViewController {
func configureChildViewController(childController: UIViewController, onView: UIView?) {
var holderView = self.view
if let onView = onView {
holderView = onView
}
addChildViewController(childController)
holderView?.addSubview(childController.view)
constrainViewEqual(holderView: holderView!, view: childController.view)
childController.didMove(toParentViewController: self)
extension NSObject {
var className: String {
return String(describing: type(of: self))
}
class var className: String {
return String(describing: self)
}
}
enum NavigationBarType {
case closeOnRight
}
class BaseViewController: UIViewController {
fileprivate static let barButtonSize = CGSize(width: 30, height: 30)
fileprivate enum NavigationBarButtonType {
case closeBtn
extension Int {
static func randomNumber(min:Int , max:Int)->Int {
var minimum = min
var maximum = max
if minimum < 0 { minimum = 0 }
if maximum < 0 { maximum = 0 }
if minimum == maximum { return minimum }
else if minimum > maximum { return randomNumber(min:maximum , max:minimum) }
return minimum + Int(arc4random())%(maximum - minimum)
}
extension String {
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: font], context: nil)
return ceil(boundingBox.height)
}
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
enum AppFont {
case regularFont
case boldFont
case italicBoldFont
case italicFont
func font(size:CGFloat)->UIFont {
switch self {
case .boldFont: return UIFont(name: "Arial-BoldMT", size: size)!
case .italicBoldFont: return UIFont(name: "Arial-BoldItalicMT", size: size)!
@aybekckaya
aybekckaya / UIColor+extensions.swift
Created June 26, 2018 00:00
UIColor extensions
public extension UIColor {
public convenience init(hex: Int, alpha: CGFloat = 1.0) {
let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0
let green = CGFloat((hex & 0xFF00) >> 8) / 255.0
let blue = CGFloat((hex & 0xFF)) / 255.0
self.init(red: red, green: green, blue: blue, alpha: alpha)
}
@aybekckaya
aybekckaya / SampleNetworkingEnum.swift
Created June 25, 2018 23:58
Sample Networking with RxSwift and Alamofire
typealias NetworkResponse = (data:JSON? , error:NetworkError?)
enum NetworkError {
case userNotFound
case cannotGetUserId
case cannotGetServerResponse
case unknownError
func stringify()->String {
switch self {
@aybekckaya
aybekckaya / NibLoadingProtocol.swift
Created June 25, 2018 23:56
easy view loading with {UIView}.identifier
protocol ComponentIdentifier: class {
static var identifier: String { get }
}
extension ComponentIdentifier {
static var identifier: String { return String(describing: self) }
}
extension UIView {
@aybekckaya
aybekckaya / collectionViewCustom.swift
Last active June 27, 2018 01:51
Collection view with blocks
//
// CollectionView.swift
// Trendyol
//
// Created by aybek can kaya on 12/06/2018.
// Copyright © 2018 aybek can kaya. All rights reserved.
//
import UIKit