{"id":15037472,"url":"https://github.com/xmartlabs/xlswiftkit","last_synced_at":"2025-04-09T23:24:21.341Z","repository":{"id":56464876,"uuid":"51607133","full_name":"xmartlabs/XLSwiftKit","owner":"xmartlabs","description":"Helpers and extensions for Swift","archived":false,"fork":false,"pushed_at":"2020-11-05T20:40:04.000Z","size":146,"stargazers_count":101,"open_issues_count":2,"forks_count":22,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-09T01:51:28.784Z","etag":null,"topics":["helpers","swift3"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xmartlabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-12T18:17:41.000Z","updated_at":"2024-06-04T01:09:51.000Z","dependencies_parsed_at":"2022-08-15T19:11:03.449Z","dependency_job_id":null,"html_url":"https://github.com/xmartlabs/XLSwiftKit","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FXLSwiftKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FXLSwiftKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FXLSwiftKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmartlabs%2FXLSwiftKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xmartlabs","download_url":"https://codeload.github.com/xmartlabs/XLSwiftKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248127170,"owners_count":21052199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helpers","swift3"],"created_at":"2024-09-24T20:34:42.989Z","updated_at":"2025-04-09T23:24:20.502Z","avatar_url":"https://github.com/xmartlabs.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XLSwiftKit\n\n\u003cp align=\"left\"\u003e\n\u003ca href=\"https://travis-ci.org/xmartlabs/XLSwiftKit\"\u003e\u003cimg src=\"https://travis-ci.org/xmartlabs/XLSwiftKit.svg?branch=master\" alt=\"Build status\" /\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/platform-iOS-blue.svg?style=flat\" alt=\"Platform iOS\" /\u003e\n\u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\" alt=\"Carthage compatible\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://cocoapods.org/pods/XLSwiftKit\"\u003e\u003cimg src=\"https://img.shields.io/cocoapods/v/XLSwiftKit.svg\" alt=\"CocoaPods compatible\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://raw.githubusercontent.com/xmartlabs/XLSwiftKit/master/LICENSE\"\u003e\u003cimg src=\"http://img.shields.io/badge/license-MIT-blue.svg?style=flat\" alt=\"License: MIT\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nBy [Xmartlabs SRL](http://xmartlabs.com).\n\n## Introduction\n\nXLSwiftKit 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.\nYou can see a list of helper functions and extensions [here](#implemented-functions). Please keep that list updated if you add new functions\n\n## Usage\n\n```swift\nimport XLSwiftKit\n// your code using XLSwiftKit\n```\n\n## Requirements\n\n* iOS 9.2+\n* Xcode 9.0+\n* Swift 4\n\n## Getting involved\n\n* If you **want to contribute** please feel free to **submit pull requests**.\n* If you **found a bug** or **need help** please **check older issues, [FAQ](#faq) and threads on [StackOverflow](http://stackoverflow.com/questions/tagged/XLSwiftKit) before submitting an issue.**.\n\nBefore contribute check the [CONTRIBUTING](https://github.com/xmartlabs/XLSwiftKit/blob/master/CONTRIBUTING.md) file for more info.\n\nIf you use **XLSwiftKit** in your app, We would love to hear about it! Drop us a line on [twitter](https://twitter.com/xmartlabs).\n\n## Examples\n\nFollow these 3 steps to run Example project: Clone XLSwiftKit repository, open XLSwiftKit workspace and run the *Example* project.\n\n## Installation\n\n#### CocoaPods\n\n[CocoaPods](https://cocoapods.org/) is a dependency manager for Cocoa projects.\n\nTo install XLSwiftKit, simply add the following line to your Podfile:\n\n```ruby\npod 'XLSwiftKit', '~\u003e 3.2.0'\n```\n\n#### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a simple, decentralized dependency manager for Cocoa.\n\nTo install XLSwiftKit, simply add the following line to your Cartfile:\n\n```ogdl\ngithub \"xmartlabs/XLSwiftKit\" ~\u003e 3.2.0\n```\n\n## Implemented functions\n\nThis is a list of the helper functions and extensions implemented in this pod.\n\n### Extensions\n\n#### NSData\n\n* `func toJSON() -\u003e AnyObject?`: serializes a NSData object to JSON representation\n\n#### NSDate\n\n* `func isOver18Years() -\u003e Bool`: returns if a date is over 18 years ago\n* `func monthName() -\u003e String`: returns the month of a date in `MMMM` format\n* `func year() -\u003e String`: returns the year of a date in `yyyy` format\n* `func day() -\u003e String`: returns the day of a date in `dd` format\n\n#### UIApplication\n\n* `class func topViewController(base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController) -\u003e UIViewController?`: returns the top most view controller in the view hierarchy considering a base rootViewController.\n* `static func changeRootViewController(rootViewController: UIViewController, animated: Bool = true, from: UIViewController? = nil, completion: ((Bool) -\u003e Void)? = nil)`: changes the rootViewController of the applications main window\n* `static func changeRootViewControllerAfterDismiss(from: UIViewController? = nil, to: UIViewController, completion: ((Bool) -\u003e Void)? = nil)`: Same as the previous one but dismisses the current view controller before changing root view controller\n* `static func makePhoneCall(phoneNumber: String) -\u003e Bool`: Creates a NSURL with the phoneNumber parameter and opens the URL if possible.\n* `var bundleIdentifier: String`\n* `var buildVersion: String`\n* `var appVersion: String`\n* `var bundleName: String`\n\n#### UINavigationBar\n\n* `func setTransparent(transparent: Bool)`: Makes the navigationBar transparent or not\n* `func shake(duration: CFTimeInterval = 0.3)`: Executes a shake animation on a view\n* `func spin(duration: CFTimeInterval, rotations: CGFloat, repeatCount: Float)`: Spins a view around its z axis\n* `static public func verticalStackView(views: [UIView], alignLeading: Bool = true, alignTrailing: Bool = true, frame: CGRect? = nil, width: CGFloat = UIScreen.mainScreen().bounds.width) -\u003e 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\n\n#### UIViewController\n\n* `func showError(title: String, message: String? = nil)`: shows an UIAlertController alert with error title and message\n\n#### Double and Int\n\n* `func currencyString() -\u003e String?`: Returns a formatted currency String from an Int or Double. Currency formatter used is defined under `Constants.Formatters.currencyFormatter`\n\n#### String\n\n* `func isValidAsEmail() -\u003e Bool`: Returns if a string is valid as email\n* `func isValidAsPhone() -\u003e Bool`: Returns if a string is valid as phone number\n* `func isNumberString() -\u003e Bool`: Returns if a string is composed just of numbers or '-' symbol\n* `func findFirstNumberInString() -\u003e String?`: Returns the first number in a String if found\n* `func renderedHeightWithFont(font: UIFont, width: CGFloat) -\u003e CGFloat`: Return the height necessary for a text given a width and font size. Same as `heightForString` extension on UIFont\n* `func getFirstAndLastName() -\u003e (String,String)?`: Parses a first and a last name from a String. Takes last whitespace as separator for these values.\n* By conforming the `String` type to `ParametrizedString` protocol and specifying a parameter format like `\"{i}\"`:\n\t* `func parametrize(parameters: CustomStringConvertible...) -\u003e 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!\"`\n\t* `parametrize(withDictonary dictonary: [Int: CustomStringConvertible]) -\u003e String`: Same behaviour as above but specifying the parameters as a dictonary.\n\n#### UIImage\n\n* `init(color: UIColor, size: CGSize = CGSize(width: 1, height: 1))`\n* `init(view: UIView)`\n* `init(image: UIImage, scaledToSize: CGSize)`\n* `class func imageWithColor(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -\u003e UIImage`\n* `class func imageWithView(view: UIView) -\u003e UIImage`\n* `class func imageWithImage(image: UIImage, scaledToSize size: CGSize) -\u003e UIImage`: Returns a new image scaled to desired size\n* `func imageScaledToSize(size: CGSize) -\u003e UIImage`: Same as previous\n* `func saveToCameraRoll(completion: ((succeded: Bool) -\u003e Void)? = nil)`: Saves an image to Saved Photos Album\n\n\n#### UITableView\n\n* `func setFooterWithSpacing(view: UIView)`: Adds a footer to a tableView that covers the rest of the screen.\n* `func reloadDataAnimated(duration: NSTimeInterval = 0.4, completion: (() -\u003e ())?)`: Performs a `reloadData` call using a cross-dissolve transition.\n\n#### Dictionary\n\n* `mutating func merge(dict: [Key: Value])`: Merges two dictionaries of the same Key and Value type\n\n#### UIColor\n\n* `init(red: Int, green: Int, blue: Int)`: Creates a color from RGB values between 0 and 255\n* `init(netHex:Int)`: Creates a color from a Hexa string\n\n#### UIDevice\n\n* `func maxScreenLength() -\u003e CGFloat`: Returns the maximum screen length of the current device\n\nThe following helpers return if the device is of certain type depending on the devices `maxScreenLength`\n* `func iPhone4() -\u003e Bool`\n* `func iPhone5() -\u003e Bool`\n* `func iPhone6() -\u003e Bool`\n* `func iPhone6Plus() -\u003e Bool`\n\nOther helpers:\n* `fontSizeForDevice(size: CGFloat, q6: CGFloat = 0.94, q5: CGFloat = 0.86, q4: CGFloat = 0.80) -\u003e CGFloat`: Returns the suggested font size for every device (iPhone only).\n\n#### UIFont\n\n* `func heightForString(string: NSString, width: CGFloat) -\u003e CGFloat`: Return the height necessary for a text given a width and font size. Same as `renderedHeightWithFont` extension on String\n\n\n### Helpers\n\n#### Constraints\n\n* `func suggestedVerticalConstraint(value: CGFloat, q6: CGFloat = 0.9, q5: CGFloat = 0.77, q4: CGFloat = 0.65) -\u003e 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\n* `func suggestedHorizontalConstraint(value: CGFloat, q6: CGFloat = 0.9, q5: CGFloat = 0.77, q4: CGFloat = 0.77) -\u003e 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\n\n#### Appearances\n\nThis is a publis struct with functions inside:\n* `static func removeBackImageIndicatorFromNavigationBar()`: Removes the navigation bars backIndicator image\n\n#### GCDHelper\n\n* `static let mainQueue: DispatchQueue`: Returns the main queue\n* `static let backgroundQueue: DispatchQueue`: Returns a background queue\n* `static func delay(_ delay: Double, block: @escaping () -\u003e ())`: Executes a block after a given delay\n* `static func runOnMainThread(_ block: @escaping () -\u003e ())`: Executes a block on the main thread\n* `static func runOnBackgroundThread(_ block: @escaping () -\u003e ())`: Executes a block on the background queue\n* `static func synced(_ lock: AnyObject, closure: () -\u003e ())`: Locks an object\n\n#### Box\n\nBox is a Wrapper: e.g. Used to wrap any structs in a class so that they can be used where AnyObject is required\n\n#### Views\n\n* `RoundedView`, `RoundedImageView` and `RoundedButton` are subclasses of `UIView`, `UIImageView` and `UIButton` with a rounded appearance.\n* `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.\n* `OwnerView` is intended to wrap xib views in order to reuse them in storyboards and also instantiate them in code.\n\t* Usage\n\t\t* Create a subclass of `OwnerView`\n\t\t* Set it as the File's Owner of your xib.\n\t\t* Connect your xib's view outlets to your subclass if any.\n\t\t* Override `func viewForContent() -\u003e UIView?` to provide the xib's view.\n\t\t* Override `func setup()` to initialize the view. Your xib's view will be accessible through the `contentView` property.\n\n#### Others\n\n* `public func JSONStringify(value: AnyObject, prettyPrinted: Bool = true) -\u003e String`: Converts a JSON object to a printable String\n\n\n## Author\n\n* [Xmartlabs SRL](https://github.com/xmartlabs) ([@xmartlabs](https://twitter.com/xmartlabs))\n\n# Change Log\n\nThis can be found in the [CHANGELOG.md](CHANGELOG.md) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmartlabs%2Fxlswiftkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxmartlabs%2Fxlswiftkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmartlabs%2Fxlswiftkit/lists"}