Swiftpack.co - Package - illescasDaniel/Foundation2

Foundation2

Swift versionlicenseVersion

A great collection of extensions, protocols and classes that improves Swift and extend the Foundation module 😉.

Content

  • Operators:

    • Power operator: **

      print(5 ** 2) // 25
      
    • String similarity operator: =~

      // Will return true if the two strings are 85% similar or above.
      print("Daniel Illescas" =~ "Daniel ilescas")
      
    • Apply operator: =>

      let daniel = Human() => { its in
        its.name = "Daniel"
        its.age = 10
      }
      
    • Operators to trim strings: <>, <|>

      let name = "John "
      print(name<>) // "John"
      var name = " Daniel "
      name<|> // name = "Daniel"
      
    • Default value operators: .., ..|. Works with String, Numeric, Dictionary, Initiable...

      let paths: [String]? = nil
      print(paths..) // []
      let value: Float? = nil
      print(value..) // value = 0
      
    • String replacement ternary operator: ~~> ( ==> ).

      // Result: "Message: Hi!"
      print("Message: <placeholder>" ~~> ("<placeholder>" ==> "Hi!"))
      
  • Protocols:

    • AutoProtocols: AutoEquatable, AutoCustomDebugStringConvertible,AutoCustomStringConvertible, AutoComparable.

    • Initiable/CustomInitiable: protocol Initiable { init() }. Making a type conform to this protocol allows it to create an instance in generic functions where <T: Initiable>.

    • Arithmetic protocols: that allows you to perform some extra operations with generic types (useful when using Numeric types). ModulusArithmetic.

  • Extensions:

    • UIAlertController: addAction(title:, style:, handler:).

    • UIColor: extensions for DisplayP3, RBG, Hex values, return RGB components...

    • UIImage: contentsOf(url:),  manageContentsOf(_ url:, completionHandler:, errorHandler:), isLandscape, isPortrait, resizedImage(to targetSize:), averageColor, resizedWith(width:), resizedWith(height:).

    • UIColor: lighter(by percentage:), darker(by percentage:), isLight, isDark, inGrayScale.

    • Collection: subscript (safe index: Index), sum.

    • String:

      • subscript(index: Int), var deletingPathExtension: String, var localized: String.
      • clear(), isNumeric, levenshteinDistanceScoreTo(string:, ...).
    • UIView: mapEverySubview(block:).

    • AVAudioPlayer: convenience init?(file:, type:, volume:), setVolumeLevel(to:, duration:) .

    • AVFoundation.AVMetadataObject: name, allBarcodes, twoDBarcodes, is1DBarcode.

    • UIApplication: openURL(from url:, completionHandler:), openSettings(), versionNumber, buildNumber, versionAndBuildNumber.

    • UIDevice: modelName, hasNotchOrExtraInsets.

    • BinaryInteger: isEven, isOdd, isPrime.

    • FloatingPoint: π, τ, tau.

    • RawRepresentable: rawLocalized.

    • CaseIterable (Swift 4.2 or >): all (allCases mapped to its RawValue).

    • CIContext: easy properties to use a metal context or a OpenGL context.

    • Mirror: deepChildren(of originalValue:).

    • Extensions for Swift 4.1 or lower: shuffle(), shuffled, Array.hashValue, CaseIterableEnum, Collection.randomElement .

  • Classes:

    • CachedImages: an easy class to manage online images in Swift.

    • File: manage files easier with this struct.

    • PreferencesManager: a simple way to manage local values in your iOS apps.

    • HapticFeedback: create simple haptic feedback patters easily.

    • ToastAlert: a basic toast-like alert, similar to what to find in Android.

    • Reachability: easily know if the device is connnected to a network or not.

    • CSVWriter: a CSV writer made in Swift.

    • IAPViewController: a viewController which lets you easily control your purchases.

    • TrueRandom: very useful type which handles millions of random numbers.

    • SwiftMutex: PthreadMutex, Semaphore, NSLock.sync.

Installation

  • Swift package manager:

    Add Foundation2 in your Package.swift dependencies.

    Like this (take a look at the Sample folder):

    import PackageDescription
    
    let package = Package(
        name: "Sample",
        dependencies: [
            .package(url: "https://github.com/illescasDaniel/Foundation2.git", from: "1.5.0"),
        ],
        targets: [
            .target(
                name: "Sample",
                dependencies: [
                    "Foundation2"
                ]),
        ]
    )
    
  • Normal project:

    • Save your currect project as a workspace (on the same directory of your project). Close your project window.
    • Clone this github repo git clone https://github.com/illescasDaniel/Foundation2.git.
    • Go to the Foundation2 folder, delete the Sample folder and run swift package generate-xcodeprojto generate an xcode project.
    • Open your workspace and drag the generated Foundation2.xcodeproj project to the same level as yours in Xcode.
    • In your project go to Linked Frameworks and Libraries and add Foundation2.framework.
    • In your workspace: Foundation2 project > Build Settings > Base SDK > Choose latest iOS or latest macOS.
    • In the Info tab for iOS choose iOS Deployment Target: 8.0, for a macOS project choose 10.10.

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 1

Releases

1.2.2 - Jul 13, 2018

1.2.1 - Jul 13, 2018

1.2.0 - Jul 13, 2018

1.1.0 - Jul 13, 2018

1.0.4 - Jul 12, 2018