All Projects → caiyue1993 → Prefsmate

caiyue1993 / Prefsmate

Licence: mit
🐣 Elegant UITableView generator for Swift.

Programming Languages

swift
15916 projects
swift4
162 projects

Projects that are alternatives of or similar to Prefsmate

React Native Ezplayer
EZPlayer component for react-native apps
Stars: ✭ 47 (-60.83%)
Mutual labels:  uitableview
Adaptivecardui
Snippets of UI, authored in JSON and rendered with SwiftUI
Stars: ✭ 73 (-39.17%)
Mutual labels:  codable
Generic Json Swift
A simple Swift library for working with generic JSON structures
Stars: ✭ 95 (-20.83%)
Mutual labels:  codable
Multipart Kit
🏞 Parses and serializes multipart-encoded data with Codable support.
Stars: ✭ 52 (-56.67%)
Mutual labels:  codable
Datasource
Simplifies the setup of UITableView data sources using type-safe descriptors for cells and sections. Animated diffing built-in.
Stars: ✭ 72 (-40%)
Mutual labels:  uitableview
Tablemanager
An extension of UITableView. The way it should be. 👍
Stars: ✭ 85 (-29.17%)
Mutual labels:  uitableview
Pagingkit
PagingKit provides customizable menu UI. It has more flexible layout and design than the other libraries.
Stars: ✭ 1,030 (+758.33%)
Mutual labels:  uitableview
Rxcodable
RxSwift wrapper for Codable
Stars: ✭ 110 (-8.33%)
Mutual labels:  codable
Ptehorizontaltableview
Horizontal UITableView inspired by EasyTableView.
Stars: ✭ 75 (-37.5%)
Mutual labels:  uitableview
Selectionlist
Simple single-selection or multiple-selection checklist, based on UITableView
Stars: ✭ 93 (-22.5%)
Mutual labels:  uitableview
Swiftprovisioningprofile
Parse iOS mobile provisioning files into Swift models
Stars: ✭ 55 (-54.17%)
Mutual labels:  codable
Core
🌎 Utility package containing tools for byte manipulation, Codable, OS APIs, and debugging.
Stars: ✭ 62 (-48.33%)
Mutual labels:  codable
Codextended
Extensions giving Swift's Codable API type inference super powers 🦸‍♂️🦹‍♀️
Stars: ✭ 1,281 (+967.5%)
Mutual labels:  codable
Mdl11 generics
Example project that was demonstrated on MDL #11 meetup - https://www.youtube.com/watch?v=A4FrEyFBjVA. Medium article - https://medium.com/chili-labs/configuring-multiple-cells-with-generics-in-swift-dcd5e209ba16
Stars: ✭ 50 (-58.33%)
Mutual labels:  uitableview
Sjstatictableview
基于MVVM,用于快速搭建设置页,个人信息页表格等静态表格的框架
Stars: ✭ 101 (-15.83%)
Mutual labels:  uitableview
Carbon
🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Stars: ✭ 1,034 (+761.67%)
Mutual labels:  uitableview
Tcpickerview
Picker view popup with multiply rows selection written in Swift
Stars: ✭ 84 (-30%)
Mutual labels:  uitableview
Skeletonview
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
Stars: ✭ 10,804 (+8903.33%)
Mutual labels:  uitableview
Tdbadgedcell
TDBadgedCell is a table view cell class that adds a badge, similar to the badges in Apple's own apps
Stars: ✭ 1,444 (+1103.33%)
Mutual labels:  uitableview
Basecomponents
BaseComponents aims to provide easily reusable and understandable components to increase productivity with UIKit and Foundation APIs
Stars: ✭ 92 (-23.33%)
Mutual labels:  uitableview

PrefsMate

CI Status Version License Platform

PrefsMate provide an elegant way to generate UITableView using a property list file(plist file, in short). Also, you can configure actions with its support. Thanks to the Codable protocol, it makes the code perfect clean.

Features

  • [x] Data Persistence
  • [x] Switch Accessory
  • [x] Select Action
  • [x] Muilty Sections
  • [x] Section Header / Footer
  • [x] Demo Project
  • [x] World Ready
  • [ ] More Custom Cells

Background

In our app, we usually need a UITableView in PrefsViewController(or perhaps named SettingsViewController, whatever). And the interface may just looks like this:

PrefsViewController

When implementing this kind of stuff, your inner voice must be this: "Writing this UI is fxxking tedious! Is there any help that I can ask for?"

And congrats! You have come to the right place :).

Usage

1. Prepare a plist file containing formatted data

Taking example of the image above, the formatted plist file looks like this:

plist structure

The meaning of each item property is as follows:

Property usage
title the text on the left
detailText the text on the right
hasDisclosure whether the cell has a disclosure accessory view
hasSwitch whether the cell has a switch
switchStatus the status of the switch control
selectActionName the name of select action(optional)
switchActionName the name of switch action(optional)

Don't be afraid of this long file. In fact you just need to do some clickable things. You could even copy and paste our plist source code first just for your convenience.

2. Create the table view and do the parsing job

let tableView = Mate.createPrefsTableView()

You can add the parsing code in viewDidLoad():

 do {
      try Mate.parseWithSource(self, plistUrl: pListUrl) {
        tableView.reloadData()
      }
    } catch {
        // Handle with the error
    }

3. If needed, let your view controller conform to PrefsSupportable protocol

If you have select and switch action to handle, PrefsSupportable protocol already considered for you.

public protocol PrefsSupportable {
    /// Return a bunch of switchableItems, including their behavior in SwitchableItemHandler.
    var switchableItems: [SwitchActionName: SwitchableItemHandler]? { get }
    
    /// Return a bunch of selectableItems, including their behavior in SelectableItemHandler.
    var selectableItems: [SelectActionName: SelectableItemHandler]? { get }
}

Taking the switch of night theme for example:

var switchableItems: [SwitchActionName : SwitchableItemHandler]? {
        return [
            "handleThemeMode": { isOn in
                print("Dark theme mode is \(isOn)")
            }
        ]
}
var selectableItems: [SelectActionName : SelectableItemHandler]? {
        return [
            changeIcon: { 
                print(Handle change icon action here)
            }
           ...
           ...
        ]
}

Then we are done! PrefsMate will do right things for you.

Keep in mind: the "handleThemeMode" String must be the same value of switchActionName in the plist file. Same on selectActionName.

In switch actions, PrefsMate already take care of the data persistence. So you don’t need to store the user preferences yourself.

You could refer to Example project for more detail.

Suggestions

  • Being familiar with plist file structure will help you a lot. Sometimes you can directly edit the plist file through "Open As Source Code".

  • If you have an issue, please don't hesitate. Just let me know :)

Example

To run the example project, clone the repo, and run pod install from the Example directory.

(Cuz this is a new Pod, you may need to pod update first.)

Requirements

  • Swift 5
  • iOS 9 or later

Installation

PrefsMate is available through Swift Package Manager & CocoaPods.

Swift Package Manager

From Xcode 11, you can use Swift Package Manager to add Kingfisher to your project.

  1. Select File > Swift Packages > Add Package Dependency. Enter https://github.com/caiyue1993/PrefsMate.git in the "Choose Package Repository" dialog.
  2. In the next page, specify the version resolving rule as "Up to Next Major" with latest release version
  3. After Xcode checking out the source and resolving the version, you can choose the "PrefsMate" library and add it to your app target.

If you encounter any problem or have a question on adding package to an Xcode project, I suggest the Adding Package Dependencies to Your App guide article from Apple.

CocoaPods

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

pod 'PrefsMate'

Contact

License

PrefsMate is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].