• Stars
    star
    100
  • Rank 329,767 (Top 7 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Helpers and extensions for Swift

XLSwiftKit

Build status Platform iOS Carthage compatible CocoaPods compatible License: MIT

By Xmartlabs SRL.

Introduction

XLSwiftKit is a collection of helpers and extensions we use internally. It is a constantly being updated with new snippets. Feel free to use it or to contribute. You can see a list of helper functions and extensions here. Please keep that list updated if you add new functions

Usage

import XLSwiftKit
// your code using XLSwiftKit

Requirements

  • iOS 9.2+
  • Xcode 9.0+
  • Swift 4

Getting involved

  • If you want to contribute please feel free to submit pull requests.
  • If you found a bug or need help please check older issues, FAQ and threads on StackOverflow before submitting an issue..

Before contribute check the CONTRIBUTING file for more info.

If you use XLSwiftKit in your app, We would love to hear about it! Drop us a line on twitter.

Examples

Follow these 3 steps to run Example project: Clone XLSwiftKit repository, open XLSwiftKit workspace and run the Example project.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

To install XLSwiftKit, simply add the following line to your Podfile:

pod 'XLSwiftKit', '~> 3.2.0'

Carthage

Carthage is a simple, decentralized dependency manager for Cocoa.

To install XLSwiftKit, simply add the following line to your Cartfile:

github "xmartlabs/XLSwiftKit" ~> 3.2.0

Implemented functions

This is a list of the helper functions and extensions implemented in this pod.

Extensions

NSData

  • func toJSON() -> AnyObject?: serializes a NSData object to JSON representation

NSDate

  • func isOver18Years() -> Bool: returns if a date is over 18 years ago
  • func monthName() -> String: returns the month of a date in MMMM format
  • func year() -> String: returns the year of a date in yyyy format
  • func day() -> String: returns the day of a date in dd format

UIApplication

  • class func topViewController(base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController) -> UIViewController?: returns the top most view controller in the view hierarchy considering a base rootViewController.
  • static func changeRootViewController(rootViewController: UIViewController, animated: Bool = true, from: UIViewController? = nil, completion: ((Bool) -> Void)? = nil): changes the rootViewController of the applications main window
  • static func changeRootViewControllerAfterDismiss(from: UIViewController? = nil, to: UIViewController, completion: ((Bool) -> Void)? = nil): Same as the previous one but dismisses the current view controller before changing root view controller
  • static func makePhoneCall(phoneNumber: String) -> Bool: Creates a NSURL with the phoneNumber parameter and opens the URL if possible.
  • var bundleIdentifier: String
  • var buildVersion: String
  • var appVersion: String
  • var bundleName: String

UINavigationBar

  • func setTransparent(transparent: Bool): Makes the navigationBar transparent or not
  • func shake(duration: CFTimeInterval = 0.3): Executes a shake animation on a view
  • func spin(duration: CFTimeInterval, rotations: CGFloat, repeatCount: Float): Spins a view around its z axis
  • static public func verticalStackView(views: [UIView], alignLeading: Bool = true, alignTrailing: Bool = true, frame: CGRect? = nil, width: CGFloat = UIScreen.mainScreen().bounds.width) -> UIView: returns a view containing the views passed as parameter as if it was a vertical stack view (putting all views vertically one after the other). Thought to be a iOS 8 alternative to real UIStackViews

UIViewController

  • func showError(title: String, message: String? = nil): shows an UIAlertController alert with error title and message

Double and Int

  • func currencyString() -> String?: Returns a formatted currency String from an Int or Double. Currency formatter used is defined under Constants.Formatters.currencyFormatter

String

  • func isValidAsEmail() -> Bool: Returns if a string is valid as email
  • func isValidAsPhone() -> Bool: Returns if a string is valid as phone number
  • func isNumberString() -> Bool: Returns if a string is composed just of numbers or '-' symbol
  • func findFirstNumberInString() -> String?: Returns the first number in a String if found
  • func renderedHeightWithFont(font: UIFont, width: CGFloat) -> CGFloat: Return the height necessary for a text given a width and font size. Same as heightForString extension on UIFont
  • func getFirstAndLastName() -> (String,String)?: Parses a first and a last name from a String. Takes last whitespace as separator for these values.
  • By conforming the String type to ParametrizedString protocol and specifying a parameter format like "{i}":
    • func parametrize(parameters: CustomStringConvertible...) -> String: Replace "{i}" substring with the i-th element of parameters. For example: "Hey {0}! It's been {1} years!".parametrize("Arnold", 3) gives you "Hey Arnold! It's been 3 years!"
    • parametrize(withDictonary dictonary: [Int: CustomStringConvertible]) -> String: Same behaviour as above but specifying the parameters as a dictonary.

UIImage

  • init(color: UIColor, size: CGSize = CGSize(width: 1, height: 1))
  • init(view: UIView)
  • init(image: UIImage, scaledToSize: CGSize)
  • class func imageWithColor(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage
  • class func imageWithView(view: UIView) -> UIImage
  • class func imageWithImage(image: UIImage, scaledToSize size: CGSize) -> UIImage: Returns a new image scaled to desired size
  • func imageScaledToSize(size: CGSize) -> UIImage: Same as previous
  • func saveToCameraRoll(completion: ((succeded: Bool) -> Void)? = nil): Saves an image to Saved Photos Album

UITableView

  • func setFooterWithSpacing(view: UIView): Adds a footer to a tableView that covers the rest of the screen.
  • func reloadDataAnimated(duration: NSTimeInterval = 0.4, completion: (() -> ())?): Performs a reloadData call using a cross-dissolve transition.

Dictionary

  • mutating func merge(dict: [Key: Value]): Merges two dictionaries of the same Key and Value type

UIColor

  • init(red: Int, green: Int, blue: Int): Creates a color from RGB values between 0 and 255
  • init(netHex:Int): Creates a color from a Hexa string

UIDevice

  • func maxScreenLength() -> CGFloat: Returns the maximum screen length of the current device

The following helpers return if the device is of certain type depending on the devices maxScreenLength

  • func iPhone4() -> Bool
  • func iPhone5() -> Bool
  • func iPhone6() -> Bool
  • func iPhone6Plus() -> Bool

Other helpers:

  • fontSizeForDevice(size: CGFloat, q6: CGFloat = 0.94, q5: CGFloat = 0.86, q4: CGFloat = 0.80) -> CGFloat: Returns the suggested font size for every device (iPhone only).

UIFont

  • func heightForString(string: NSString, width: CGFloat) -> CGFloat: Return the height necessary for a text given a width and font size. Same as renderedHeightWithFont extension on String

Helpers

Constraints

  • func suggestedVerticalConstraint(value: CGFloat, q6: CGFloat = 0.9, q5: CGFloat = 0.77, q4: CGFloat = 0.65) -> CGFloat: Scale a value for a vertical constraint constant depending on the current device. Works for iPhone apps only. All coefficients have reasonable default values for vertical constraints
  • func suggestedHorizontalConstraint(value: CGFloat, q6: CGFloat = 0.9, q5: CGFloat = 0.77, q4: CGFloat = 0.77) -> CGFloat: Scale a value for a horizontal constraint constant depending on the current device. Works for iPhone apps only. All coefficients have reasonable default values for horizontal constraints

Appearances

This is a publis struct with functions inside:

  • static func removeBackImageIndicatorFromNavigationBar(): Removes the navigation bars backIndicator image

GCDHelper

  • static let mainQueue: DispatchQueue: Returns the main queue
  • static let backgroundQueue: DispatchQueue: Returns a background queue
  • static func delay(_ delay: Double, block: @escaping () -> ()): Executes a block after a given delay
  • static func runOnMainThread(_ block: @escaping () -> ()): Executes a block on the main thread
  • static func runOnBackgroundThread(_ block: @escaping () -> ()): Executes a block on the background queue
  • static func synced(_ lock: AnyObject, closure: () -> ()): Locks an object

Box

Box is a Wrapper: e.g. Used to wrap any structs in a class so that they can be used where AnyObject is required

Views

  • RoundedView, RoundedImageView and RoundedButton are subclasses of UIView, UIImageView and UIButton with a rounded appearance.
  • GradientView renders a gradient from an array of colors and a direction specified by the colors and direction properties. It spreads the colors evenly through the space.
  • OwnerView is intended to wrap xib views in order to reuse them in storyboards and also instantiate them in code.
    • Usage
      • Create a subclass of OwnerView
      • Set it as the File's Owner of your xib.
      • Connect your xib's view outlets to your subclass if any.
      • Override func viewForContent() -> UIView? to provide the xib's view.
      • Override func setup() to initialize the view. Your xib's view will be accessible through the contentView property.

Others

  • public func JSONStringify(value: AnyObject, prettyPrinted: Bool = true) -> String: Converts a JSON object to a printable String

Author

Change Log

This can be found in the CHANGELOG.md file.

More Repositories

1

Eureka

Elegant iOS form builder in Swift
Swift
11,705
star
2

XLPagerTabStrip

Android PagerTabStrip for iOS.
Swift
6,880
star
3

XLForm

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
Objective-C
5,790
star
4

XLActionController

Fully customizable and extensible action sheet controller written in Swift
Swift
3,326
star
5

Bender

Easily craft fast Neural Networks on iOS! Use TensorFlow models. Metal under the hood.
Swift
1,780
star
6

PagerTabStripView

🚀 Elegant Pager View fully written in pure SwiftUI.
Swift
692
star
7

Xniffer

A swift network profiler built on top of URLSession.
Swift
501
star
8

XLRemoteImageView

UIImageView that shows a progress indicator while the image is loading from server. It makes use of AFNetworking. It looks like the Instagram loading indicator.
Objective-C
346
star
9

fountain

Android Kotlin paged endpoints made easy
Kotlin
170
star
10

XLData

Elegant and concise way to load and show data sets into table and collection view. It supports AFNetworking, Core Data and memory data stores.
Objective-C
165
star
11

XLSlidingContainer

XLSlidingContainer is a custom container controller that embeds two independent view controllers allowing to easily maximize any of them using gestures.
Swift
149
star
12

android-snapshot-publisher

Gradle plugin to deploy Android Snapshot Versions
Kotlin
145
star
13

Swift-Project-Template

Script to easily create an iOS project base code!
Swift
144
star
14

Swift-Framework-Template

Swift script to easily create Swift frameworks!
Swift
143
star
15

react-native-line

Line SDK wrapper for React Native 🚀
TypeScript
119
star
16

Ecno

Ecno is a task state manager built on top of UserDefaults in pure Swift 4.
Swift
101
star
17

XLMediaZoom

UI controls to view an image or reproduce a video in fullscreen like Instagram does.
Swift
92
star
18

XLMailBoxContainer

Custom container view controller ala MailBox app.
Objective-C
90
star
19

gong

Xmartlabs' Android Base Project Template
Kotlin
89
star
20

cordova-plugin-market

Cordova Plugin that allows you to access native Marketplace app (aka Google Play, App Store) from your app
Java
87
star
21

Opera

Protocol-Oriented Network abstraction layer written in Swift.
Swift
74
star
22

stock

Dart package for Async Data Loading and Caching. Combine local (DB, cache) and network data simply and safely.
Dart
71
star
23

Ahoy

A lightweight swift library to build onboarding experiences.
Swift
52
star
24

bigbang

Android base project used by Xmartlabs team
Kotlin
50
star
25

MetalPerformanceShadersProxy

A proxy for MetalPerformanceShaders which takes to a stub on a simulator and to the real implementation on iOS devices.
Objective-C
45
star
26

Swift-Style-Guide

Swift language style guide & coding conventions followed by Xmartlabs.
44
star
27

RxSimpleNoSQL

Reactive extensions for SimpleNoSQL
Java
37
star
28

docker-jenkins-android

Jenkins docker image for Android development
36
star
29

docker-htpasswd

Docker image to create a htpasswd file
32
star
30

spoter-embeddings

Create embeddings from sign pose videos using Transformers
Python
29
star
31

TypedNavigation

A lightweight library to help you navigate in compose with well typed functions.
Kotlin
23
star
32

XLMapChat

A chat application running on Node.js, using Socket.IO, GMaps, and more...
JavaScript
22
star
33

flutter-template

Xmartlabs' Flutter Base Project
Dart
17
star
34

XLDataLoader

Objective-C
16
star
35

dreamsnap

Real life through the eyes of an artist
CSS
15
star
36

blog

Xmartlabs Blog
CSS
14
star
37

bigbang-template

Android template used by Xmartlabs team
Kotlin
14
star
38

benderthon

Set of utilities to work easier with Bender.
Python
13
star
39

XLiOSKit

Objective-C
13
star
40

MLKitTest

Source code related to a blog post about ML Kit
Swift
12
star
41

react-template-xmartlabs

This is an internal private project - aims to be at some point in the future our React base project
TypeScript
9
star
42

python-template

Python
9
star
43

XmartRecyclerView

A smart, simple and fast RecyclerView library
Java
8
star
44

gpgpu-comparison

8
star
45

jared-landing

Landing page for Jared Bot.
HTML
8
star
46

Fastlane-CI-Files

Fastlane CI files
Ruby
8
star
47

Android-Style-Guide

Style guide for Android by Xmartlabs
7
star
48

fluttips

Flutter trips and tricks
JavaScript
7
star
49

XLMaterialCalendarView

MaterialCalendarView powered with reactive bindings and with the Java 8 Time API!
Java
6
star
50

docker-android

Docker image for Android development.
6
star
51

rnx-cli

TypeScript
5
star
52

gh-top-repos-users

Download the contributors of the top repos.
Python
5
star
53

BuildSlackNotifier

Jenkins plugin to send Android build results through a slack channel using incoming webhooks
Java
4
star
54

javascript-plugin

Source Code of blog Making a JS widget: a full-stack approach
Ruby
4
star
55

xmartchat

Dart
4
star
56

AndroidSwissKnife

Kotlin
3
star
57

projecthub-landing

ProjectHub lets you manage your GitHub Projects on the fly, from your mobile phone.
HTML
3
star
58

gh2s3

Download GitHub Archive data and upload it to an Amazon S3 bucket.
Python
3
star
59

pycon-es-workshop

Python
2
star
60

xl-blog

Gatsby XL's Blogpost
JavaScript
2
star
61

mPOS-SDK-iOS

Objective-C
1
star
62

terraform

HCL
1
star
63

FastlaneDemo

Demo project to show a basic fastlane configuration
Swift
1
star
64

xl-school-automation-web

This is the repository for web automation training for XL
Java
1
star
65

workshop-microservicios

Python
1
star
66

fountain-docs

Fountain documentation
1
star
67

client-side-widget-template

JavaScript templates for a client-side widget
HTML
1
star
68

rn-lightbox

JavaScript
1
star
69

malaria-detector

Jupyter Notebook
1
star
70

SQLiteDSL

1
star
71

terraform-basic-infra

HCL
1
star
72

docker-pcl-cmake

Docker image containing PCL and CMake.
1
star
73

cocoapods-specs

Ruby
1
star