Maintained by Morgan Berger.


  • By
  • morganberger


CI Status Version License Platform


A colourful library of Swift extensions & custom stuffs!


  1. Extensions
  2. Models


To run the example project, clone the repo, and run pod install from the Example directory first.

Note that the example project is currently a work in progress. I only use to test the stuff I code so it might be a little messy for now.


  • iOS 9.3+
  • Xcode 9.4+
  • Swift 4.0+


BadasSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BadasSwift'



  • Bundle:

    Provides rapid access to app version & build numbers.

    public var versionNumber: String? { get }
    public var buildVersionNumber: String? { get }


    print("Version number: \(Bundle.main.versionNumber)")

    Output -> "Version number: 1.0"

  • CharacterSet:

    static let urlAllowed: CharacterSet

    The urlAllowed variable is a CharacterSet union between:

    • .urlFragmentAllowed
    • .urlHostAllowed
    • .urlPasswordAllowed
    • .urlQueryAllowed
    • .urlUserAllowed

    It allows quick conversion from any string to a formatted acceptable url string.


    var urlStr = " there, have a good day."
    urlStr = urlStr.addingPercentEncoding(withAllowedCharacters: .urlAllowed)!

    Output -> ",%20have%20a%20good%20day."

  • CLLocationManager:

    public static var isAuthorized: Bool { get }

    Returns true if user authorized location always or whenInUse

  • Date:

    Returns a date string with asked format.

    public func formatedString(_ format: String) -> String


    print("Today's date is: \(Date().formatedString("EEEE, MMM d, yyyy"))")

    Output -> "Today's date is Monday, Oct 11, 2018"

  • NSLayoutConstraint:

    Provides some sweet real-time animation methods for NSLayoutConstraint.

    public func animateConstraintTo(_ value: CGFloat, for view: UIView, duration: Double)
    public func animateConstraintTo(_ value: CGFloat, for view: UIView, duration: Double, completion: @escaping () -> Void)
    public func setMultiplier(multiplier: CGFloat) -> NSLayoutConstraint
  • String:

    Got a string full of HTML tags? Change it to a attributed string with the methods below.

    public var html2AttributedString: NSAttributedString? { get }
    public var html2String: String { get }


    let htmlStr = "<h1>Very Big Title</h1>"
    let attributedStr = htmlStr.html2AttributedString()

    Or you could smoothly hash any string to MD5 if you feel like it!

    public func MD5Hex() -> String
    public func MD5base64() -> String
  • UIButton:

    func alignTextHorizontal(spacing: CGFloat = default)
  • UIImage:

    Convert image to black & white (grayscale).

    public func convertToGrayScale() -> UIImage

    Check is two images are identicals.

    public func isEqualTo(_ image: UIImage) -> Bool

    Scale any image to the provided CGSize.

    func scaleImage(scaleToSize: CGSize) -> UIImage
  • UIImageView:

    Fetches any web image from its url and applies it to the image view. Fast & async!

    public func setImageWithUrlString(_ urlStr: String, completion: @escaping (_ img: UIImage?) -> Void)


    anyImageView.setImageWithUrlString("") { (img) in
        //the completion block send back the UIImage object that has been fetched.
  • UIView:

    Get the root view in view hierarchy.

    public var rootView: UIView { get }

    Animate any view alpha to 1.0f. Can be called with or without completion block.

    public func showWithDuration(_ duration: Double)
    public func showWithDuration(_ duration: Double, completion: @escaping () -> Void)

    Animate any view alpha to 0.0f. Can be called with or without completion block.

    public func hideWithDuration(_ duration: Double)
    public func hideWithDuration(_ duration: Double, completion: @escaping () -> Void)

    Put 1px width border to any view with the wanted color. Mostly use for debugging purposes.

    public func putBorders(color: UIColor)

    Adds a vertical gradient layer with wanted colors to any view.

    public func putGradient(_ colors: CGColor...)

    Basically turn a view to an UIImage.

    public func takeSnapshot() -> UIImage?
  • UIViewController:

    public func setStatusBarColor(_ color: UIColor)

    Easily change the status bar color from any view controller!


    override func viewDidLoad() {
  • URL:

    public static func verifyUrl(string: String?) -> Bool

    Return true if url is correct/reachable. Else false.


  • SnappingCollectionViewLayout:

    This class is a child of UICollectionViewFlowLayout. It provides simple snapping for collection view cells.


    let snapLayout:SnappingCollectionViewLayout = SnappingCollectionViewLayout()
    snapLayout.scrollDirection = .horizontal
    // Optional, you can ajust inset to better match your cells size.
    snapLayout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 20)
    anyCollectionView.collectionViewLayout = snapLayout



  • VoteView:

    Very simple Objective-C coded view created to make some users rate some stuff. Could be anything.

    You can easily subclass this IBDesignable view and make it your own.
    It implements a few delegates:

    - (UIImage*)setSelectedImgName;
    - (UIImage*)setUnselectedImgName;
    - (int)setImageNumber;

    Those three are called during the draw(_ rect:CGRect) method. It depends of the developper's preferences to set the UIImages and images number directly in the Storyboard or to call those delegates to set them. They're like a lot of things in life: optional.

    - (void)voteDidChange:(int)voteResult;

    This one is called everytime a user taps an image within the view. Whenever the vote changes.

  • AwesomePageControl:

    A custom segmented control coded to be similar to the one used in the new version of the Chrome mobile app.

    Look how beautiful it is!

    You can use it as is but at this day it's a work in progress so you'll probably have a BAD TIME trying to add more segments to it.
    -> IBDesignable version coming very soon.

    Anyway, it has only one delegate method, which is:

    @objc optional func didTapControlAtIndex(_ index:Int) -> Void

    called everytime a new 'segment' is selected.


morganberger, [email protected]


BadasSwift is available under the MIT license. See the LICENSE file for more info.