Giter Site home page Giter Site logo

swifterswift / swifterswift Goto Github PK

View Code? Open in Web Editor NEW
13.7K 285.0 1.6K 16.12 MB

A handy collection of more than 500 native Swift extensions to boost your productivity.

Home Page: https://swifterswift.com

License: MIT License

Swift 99.05% Ruby 0.83% Objective-C 0.07% Shell 0.05%
swift xcode carthage cocoapods tvos ios macos swifterswift extensions uikit

swifterswift's Introduction

Build Status Platforms Cocoapods Carthage compatible SPM compatible Accio supported codecov docs Swift Xcode MIT Slack Channel

SwifterSwift is a collection of over 500 native Swift extensions, with handy methods, syntactic sugar, and performance improvements for wide range of primitive data types, UIKit and Cocoa classes –over 500 in 1– for iOS, macOS, tvOS, watchOS and Linux.

简体中文

Requirements

  • iOS 12.0+ / tvOS 12.0+ / watchOS 4.0+ / macOS 10.13+ / Ubuntu 14.04+
  • Swift 5.6+

Looking to use SwifterSwift for older versions of Swift

SwifterSwift is Swift v5.0+ compatible starting from v5

  • To use with Swift 3 / Xcode 8.x please ensure you are using v3.1.1.
  • To use with Swift 3.2 / Xcode 9.x please ensure you are using v3.2.0.

Installation

CocoaPods

To integrate SwifterSwift into your Xcode project using CocoaPods, specify it in your Podfile:

- Integrate All extensions (recommended):

pod 'SwifterSwift'

- Integrate SwiftStdlib extensions only:

pod 'SwifterSwift/SwiftStdlib'

- Integrate Foundation extensions only:

pod 'SwifterSwift/Foundation'

- Integrate UIKit extensions only:

pod 'SwifterSwift/UIKit'

- Integrate AppKit extensions only:

pod 'SwifterSwift/AppKit'

- Integrate MapKit extensions only:

pod 'SwifterSwift/MapKit'

- Integrate CoreGraphics extensions only:

pod 'SwifterSwift/CoreGraphics'

- Integrate CoreLocation extensions only:

pod 'SwifterSwift/CoreLocation'

- Integrate CryptoKit extensions only:

pod 'SwifterSwift/CryptoKit'

- Integrate SpriteKit extensions only:

pod 'SwifterSwift/SpriteKit'

- Integrate SceneKit extensions only:

pod 'SwifterSwift/SceneKit'

- Integrate StoreKit extensions only:

pod 'SwifterSwift/StoreKit'

- Integrate Dispatch extensions only:

pod 'SwifterSwift/Dispatch'

- Integrate WebKit extensions only:

pod 'SwifterSwift/WebKit'

- Integrate HealthKit extensions only:

pod 'SwifterSwift/HealthKit'
Carthage

To integrate SwifterSwift into your Xcode project using Carthage, specify it in your Cartfile:

github "SwifterSwift/SwifterSwift" ~> 6.0
Swift Package Manager

You can use The Swift Package Manager to install SwifterSwift by adding the proper description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .package(url: "https://github.com/SwifterSwift/SwifterSwift.git", from: "6.0.0")
    ]
)

Next, add SwifterSwift to your targets dependencies like so:

.target(
    name: "YOUR_TARGET_NAME",
    dependencies: [
        "SwifterSwift",
    ]
),

Then run swift package update.

Note that the Swift Package Manager doesn't support building for iOS/tvOS/macOS/watchOS apps – see Accio in the next section for that.

Accio

Accio is a dependency manager based on SwiftPM which can build frameworks for iOS/macOS/tvOS/watchOS. Therefore the integration steps are exactly the same as described above. Once your Package.swift file is configured, you need to run accio update instead of swift package update though.

Manually

Add the SwifterSwift folder to your Xcode project to use all extensions, or a specific extension.

For your test targets you can also add the XCTest folder.

List of All Extensions

SwiftStdlib Extensions
Foundation Extensions
UIKit Extensions
AppKit Extensions
CoreGraphics Extensions
CoreLocation Extensions
CoreAnimation Extensions
CryptoKit Extensions
MapKit Extensions
SpriteKit Extensions
SceneKit Extensions
StoreKit Extensions
Dispatch Extensions
WebKit Extensions
HealthKit Extensions
XCTest Extensions
Combine Extensions

How cool is this?

SwifterSwift is a library of over 500 properties and methods, designed to extend Swift's functionality and productivity, staying faithful to the original Swift API design guidelines.

Check Examples.playground from the project for some cool examples!

Documentation

Documentation for all extensions, with examples, is available at swifterswift.com/docs

Get involved

We want your feedback. Please refer to contributing guidelines before participating.

Slack Channel: Slack

It is always nice to talk with other people using SwifterSwift and exchange experiences, so come join our Slack channel.

Thanks

Special thanks to:

License

SwifterSwift is released under the MIT license. See LICENSE for more information.

swifterswift's People

Contributors

0mars avatar asura19 avatar basememara avatar be-meyer avatar calebkleveter avatar chalkdust avatar dependabot[bot] avatar freak4pc avatar gurgeous avatar guykogus avatar jayxiang avatar kaphacius avatar leluckyvint avatar lucianopalmeida avatar luoxiu avatar marcocapano avatar maxhaertwig avatar mmdock avatar n0an avatar nathanbacon avatar omaralbeik avatar pawurb avatar pvtmert avatar ratulsharker avatar romanpodymov avatar sd10 avatar shivahuang avatar staffler-xyz avatar stavares843 avatar tapanprakasht avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swifterswift's Issues

Please Split the project.

I think the project should be split into independent projects: CocoaExtensions and DataStructure extension. So the last could be reusable everywhere and not just for iOS. It is different type of expertise to write UIKit extensions and Data Structure ones. It is difficult achieve excellence in both.

open instead of public

error when using this lib with a custom uicontrol.
complaining about Overriding non-open var outside defining module.

UIView isVisible

The property returns true is it's not visible. Is that intended?

Naming of Dequeue Functions in `UITableView` and `UICollectionView`

I found the functions in UITableView and UICollectionView extensions for dequeue cell have the prefix deque like the following:

public func dequeReusableCell<T: UITableViewCell>(withClass name: T.Type, for indexPath: IndexPath) -> T

, not dequeue. Is this a typo or for some reason?

macOS Support

@pawurb Could you please help adding the targets and the initial setup, then I can check all extensions compatibility with macOS.
Thank you in advance!

Is this a mistake?

In DateExtensions, for property 'year', why is the 'second' parameter set to newValue ?
Is this a mistake?

 public var year: Int {
		get {
			return calendar.component(.year, from: self)
		}
		set {
			self = Date(calendar: calendar, timeZone: timeZone, era: era, year: newValue, month: month, day: day, hour: hour, minute: minute, second: newValue, nanosecond: nanosecond)
		}
	}

UIView fadeIn fadeOut

Seems like fadeIn is setting the alpha to 0 and fadeOut is setting the alpha to 1. Is that correct?

DateExtensions.swift:215:27: Type 'Locale!' has no member 'posix'

public var iso8601String: String {
		// https://github.com/justinmakaila/NSDate-ISO-8601/blob/master/NSDateISO8601.swift
		let dateFormatter = DateFormatter()
		dateFormatter.locale = .posix
		dateFormatter.timeZone = TimeZone(abbreviation: "GMT")
		dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
		
		return dateFormatter.string(from: self).appending("Z")
}

DateExtensions.swift:215:27: Type 'Locale!' has no member 'posix'

Swift 4 Support

Swift 4

Xcode 9 beta with Swift 4 was announced yesterday 🎉, whats new
All Swift 4 work will be done in the swift-4 branch and will be released as soon as Swift 4 is available officially

tvOS support

It would be nice if you could update the podspec to allow usage of this in a tvOS project as well.

Thanks,

pieter

About the "Coding Style"

As I know, In Objective-C, Extension functions often write with a fix prefix. like "sd_xxx". I think swift extension should be do it as the same to forbidden conflict to other's extension?

UISegmentedControlExtensions return array of optional values

public var segmentTitles: [String?]

public var segmentImages: [UIImage?]

The implementation currently returns an empty array in the case where no titles exist.
I think it would be better to either:

a) Return an optional Array
b) Return an Array of non-optional elements

This would also eliminate double optional values from using .first property on the array

let doubleOptional = UISegmentedControl().segmentTitles.first

I would also like to remove the use of the while loops from the implementation of these properties.

I think its "swiftier" to use a for in range loop
so we don't have to keep track of and increment our own index.

Currently with while loop

public var segmentTitles: [String?] {
		get {
			var titles: [String?] = []
			var i = 0
			while i < numberOfSegments {
				titles.append(titleForSegment(at: i))
				i += 1
			}
			return titles
		}
		set {
			removeAllSegments()
			for (index, title) in newValue.enumerated() {
				insertSegment(withTitle: title, at: index, animated: false)
			}
		}
	}

With for in range loop:

public var segmentTitles: [String?] {
		get {
			var titles: [String?] = []
			for i in 0..<numberOfSegments {
				titles.append(titleForSegment(at: i))
			}
			return titles
		}
		set {
			removeAllSegments()
			for (index, title) in newValue.enumerated() {
				insertSegment(withTitle: title, at: index, animated: false)
			}
		}
	}

If anyone has some thoughts on this let me know. I'd like to make any changes under the same commit for testing of this class.

Problem with SPM

Hi, i can't install with SPM...

using .Package(url: "https://github.com/SwifterSwift/SwifterSwift.git", versions: Version(1,4,0)..<Version(2, .max, .max)) i got this error:

Cloning https://github.com/SwifterSwift/SwifterSwift.git
error: The dependency graph could not be satisfied. The package (https://github.com/SwifterSwift/SwifterS
wift.git) with version tag in range (1.4.0..<2.9223372036854775807.9223372036854775807) is not found. Fou
nd tags ([1.0.2])

and with .Package(url: "https://github.com/SwifterSwift/SwifterSwift.git", majorVersion: 1, minor: 6) i got something similar

Poll: Add ss prefix to all extensions

While adding the SS prefix to all extensions will make them less readable, it could bring more compatibility with 3rd party libraries

Example:

[1, 2, 3].ssRandomItem
// or
[1, 2, 3].ss.randomItem

instead of:

[1, 2, 3].randomItem

Help please

Then use - let someString = String(" 123 ").trimmed
have error - Value of type "String?" has no member 'trimmed'

Why?

// and many others!

instead of // and many others! i would like to see a full doc of all functions and extensions

and mandatory for new pull requests

Inconsistent naming...

Given the code:

public var nearestHourQuarter: Date {

...
public var nearestHalfHour: Date {

Shouldn't the first function be named "nearestQuarterHour", to match nearestHalfHour? Truthfully, when I was reading the code, I thought the function was named incorrectly even before I got to the second function. It just seems like it would be better to be consistent.

Increase test coverage

Currently test coverage is quite low, with a bunch of extension files not being tested at all.
coverage

Though there is no way to display a fancy coverage status badge in the readme it would still be nice to increase it. I don't have time to look into it right now but I would leave issue hanging around for others to see.

If someone feels like earning some cheap OS karma and get started on collaborating here it would be the simplest way to do it.

Add Subspecs support

Use Cocoapods Subspecs to divide the project into smaller sub projects so users can install everything or only what they need.

Suggested Subspecs

  • SwifterSwift/Foundation
  • SwifterSwift/UIKit
  • SwifterSwift/Cocoa

Drop method is missing

The following method is missing:

drop(while condition: (Element) -> Bool)

Drop elements of Array while condition is true.

type: Mutating Method.
parameters:
condition: condition to evaluate each element against.
availability: iOS 8+ tvOS 9+ watchOS 3+ macOS 10.10+.

Please update, thank you.

Unable to find SwifterSwift

pod search SwifterSwift
[!] Unable to find a pod with name, author, summary, or description matching SwifterSwift

MD file error

I found something wrong in the document.
NSAttributedString extensions link to nothing
UIAlertController extensions link to NSAttributedString extensions

UIView rotate(toAngle

This method will reset all other transformations applied to the view. UIView rotate(byAngle behaves differently

Swift PM support

Since Swift 3 introduce Package Manager, any plans to support?

Typo in Wiki

There's a typo on the UINavigationItem Extensions page. The word navigation in the description column is misspelled.

Int.randomBetween(min:max) is changed to Int.random(between:max)

In the latest version Xcode is complaining about Int not having a static function called randomBetween. After looking at the source code I found that it is changed from Int.randomBetween(min: 5, max: 25) to Int.random(between: 5, max: 25). This change is not yet documented in your documentation.

I would also like to suggest tweaking the syntax to the following for nicer readability:

public static func random(between min: Int, and max: Int) -> Int {
	return random(inRange: min...max)
}

This would result in usage as Int.random(between: 5, and: 25)

Swift Source Compatibility

Hello @omaralbeik . I have been away for a while but could not find time for contributing recently. Just found out that Apple is including OS projects into its Swift source compatibility testing. Maybe you would be interested in joining it? Unfortunately in the nearest future I will not have time to look into it.

https://swift.org/source-compatibility/

Looking for new contributors!

Help Wanted

Hey, everyone! SwifterSwift is looking for new contributors!

You can contribute to the project in a variety of ways:

  • Improve documentation 🙏
  • Add more extensions 👍
  • Add missing unit tests 😅
  • Fixing or reporting bugs 😱

If you're new to Open Source or Swift the SwifterSwift community is a great place to get involved.
No contribution is too small.

If you have any questions or need help getting started -- feel free to let me know!

Is codecov report correct?

I was looking into codecov report to check how well the code is tested. But I found some disparity between codecov report and Xcode coverage report. For example look at the case of UISliderExtensions.
This is the codecov report for UISliderExtension where completion handler is not covered by test.
image
But when I run the same test in Xcode it is giving the following result where test coverage is 100%
image

Did anybody know why this disparity happens? Is it a bug with Codecov? Is there anything to do with xcpretty in travis file? Because following link says broken codecov with xcpretty.
codecov/example-swift

Array: item(at: ) error if index is same as items

[1, 2, 3, 4, 5].item(at: 2) -> 3
[1.2, 2.3, 4.5, 3.4, 4.5].item(at: 3) -> 3.4
["h", "e", "l", "l", "o"].item(at: 10) -> nil

//bug
["h"].item(at: 1) -> error, should be nil
["h", "e"].item(at: 2) -> error, should be nil

xcode: 8.3
swift: 3.1
swifterswift: 1.6.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.