Swiftpack.co -  VadimPavlov/Swifty as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
VadimPavlov/Swifty
Awesome Swift helpers
.package(url: "https://github.com/VadimPavlov/Swifty.git", from: "swift4.0")

Swifty

Obj-C Wrappers

Settings protocol

⚠️ Since Swift 5.1 use property wrapper @UserDefault ⚠️ Simple string-enum wrapper around UserDefaults:

enum UserSettingsKeys: String, CaseIterable, SettingKey {

    case language
    case tutorialShowed

    static var clearKeys: [UserSettingsKeys] {
        return allCases // keys to remove on logout for example
    }
}

class UserSettings: Settings<UserSettingsKeys> {}

To read and write:

    let showed: Bool = settings[.tutorialShowed] ?? false
    ...
    settings[.tutorialShowed] = true

    settings[.language] = .dutch // where Language is RawRepresentable

Only supported types can be stored (check SettingValue). Also any Codable object:

    settings.set(user, key: .currentUser) // by default encoded as .plist
    
    let currentUser: User? = settings.object(.currentUser)

CoreData Primitives

⚠️ Since Swift 5.1 can be improved with @propertyWrapper ⚠️ Similar string-enum wrapper for primitives in CoreData:

   class FavoriteItem: NSManagedObject, Primitives {
       enum PrimitiveKey: String {
           case rating
           case type
       }
       
       // optionals
       var rating: Int16? {
           set { self[.rating] = newValue }
           get { return self[.rating] }
       }
       
       // RawRepresentable
       var type: FavoriteType? {
           set { self[.type] = newValue }
           get { return self[.type] }
       }
   }

Table & Collection Controllers

Boilerplate code for DataSource of TableView & CollectionView can be simplied to:

    // where MyCell is a prototype in Storyboard 
    let controller = TableController<String, MyCell>(tableView: self.tableView) { cell, item in
        cell.textLabel?.text = item
    }
    
    // DataProvider is ExpressibleByArrayLiteral
    controller.update(provider: ["one", "two", "three"]) // aka reload data

Flexibility of DataProvider:

    // single section with 3 rows
    let provider = DataProvider([1, 2, 3]) 
    
    // multiple section with optional titles
    let section1 = Section(title: "First", objects: [0,1,2]) // 3 rows
    let section2 = Section(title: "Second", objects: [3,4])  // 2 rows
    let provider = DataProvider(sections: [section1, section2])
    
    // NSFetchedResultsController and even PHFetchResult is supported
    let provider = DataProvider(frc: frc)

CoreData support:

    // by default FRCTableController will listen to changes in context and do batch updates
    ...
    let frc = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
    let controller = FRCTableController<CoreDataEntity, EntityCell>(tableView: self.tableView, frc: frc) { cell, entity in
        cell.update(with: entity)
    }

MVVM

ViewController

ViewModel

StateController

Reactive

Observable

⚠️ Since Swift 5.1 use Combine's Publisher ⚠️

Future

⚠️ Since Swift 5.1 use Combine's Future ⚠️

Permissions

GitHub

link
Stars: 3
Last commit: Yesterday

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API