{"id":21373637,"url":"https://github.com/Xiaoye220/EmptyDataSet-Swift","last_synced_at":"2025-07-13T08:30:33.384Z","repository":{"id":22384217,"uuid":"96985351","full_name":"Xiaoye220/EmptyDataSet-Swift","owner":"Xiaoye220","description":"🎄 DZNEmptyDataSet implement with Swift.A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display. DZNEmptyDataSet with Swift.","archived":false,"fork":false,"pushed_at":"2022-05-24T15:23:10.000Z","size":2751,"stargazers_count":706,"open_issues_count":20,"forks_count":102,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-07-10T19:23:26.249Z","etag":null,"topics":["dznemptydataset","emptydataset-swift","swift","uicollectionview","uitableview"],"latest_commit_sha":null,"homepage":"","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/Xiaoye220.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-12T08:43:19.000Z","updated_at":"2025-07-10T07:29:13.000Z","dependencies_parsed_at":"2022-07-20T07:02:11.739Z","dependency_job_id":null,"html_url":"https://github.com/Xiaoye220/EmptyDataSet-Swift","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/Xiaoye220/EmptyDataSet-Swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xiaoye220%2FEmptyDataSet-Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xiaoye220%2FEmptyDataSet-Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xiaoye220%2FEmptyDataSet-Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xiaoye220%2FEmptyDataSet-Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xiaoye220","download_url":"https://codeload.github.com/Xiaoye220/EmptyDataSet-Swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xiaoye220%2FEmptyDataSet-Swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264836186,"owners_count":23670818,"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":["dznemptydataset","emptydataset-swift","swift","uicollectionview","uitableview"],"created_at":"2024-11-22T08:29:26.029Z","updated_at":"2025-07-13T08:30:32.896Z","avatar_url":"https://github.com/Xiaoye220.png","language":"Swift","funding_links":[],"categories":["iOS"],"sub_categories":["EmptyDataSet"],"readme":"# EmptyDataSet-Swift\n![pod](https://img.shields.io/badge/pod-5.0.0-brightgreen.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n![iOS](https://img.shields.io/badge/iOS-8.0-green.svg)\n![lisence](https://img.shields.io/badge/license-MIT-orange.svg)\n![swift](https://img.shields.io/badge/swift-5.0-red.svg)\n\nA drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display.  [DZNEmptyDataSet](https://github.com/dzenbot/DZNEmptyDataSet/blob/master/README.md) with Swift.\n\n## ScreenShot\n\n![Screenshots_row1](Example/ScreenShot/Screenshots_row1.png)\n\n![Screenshots_row2](Example/ScreenShot/Screenshots_row2.png)\n\n## Installation\n\n### CocoaPods\n```\npod 'EmptyDataSet-Swift', '~\u003e 5.0.0'\n```\n\n### Carthage\n\n```\ngithub \"Xiaoye220/EmptyDataSet-Swift\" \"4.2.0\"\n```\n\n## Usage\n### Basic \nSame as [DZNEmptyDataSet](https://github.com/dzenbot/DZNEmptyDataSet/blob/master/README.md)\n\n```swift\nimport EmptyDataSet_Swift\n\nclass OriginalUsageViewController: UITableViewController, EmptyDataSetSource, EmptyDataSetDelegate {\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \n        tableView.emptyDataSetSource = self\n        tableView.emptyDataSetDelegate = self\n    }\n}\n```\n#### EmptyDataSetDelegate\n```swift\npublic protocol EmptyDataSetDelegate: class {\n\n    /// Asks the delegate to know if the empty dataset should fade in when displayed. Default is true.\n    func emptyDataSetShouldFadeIn(_ scrollView: UIScrollView) -\u003e Bool\n    \n    /// Asks the delegate to know if the empty dataset should still be displayed when the amount of items is more than 0. Default is false.\n    func emptyDataSetShouldBeForcedToDisplay(_ scrollView: UIScrollView) -\u003e Bool\n\n    /// Asks the delegate to know if the empty dataset should be rendered and displayed. Default is true.\n    func emptyDataSetShouldDisplay(_ scrollView: UIScrollView) -\u003e Bool\n\n    /// Asks the delegate for touch permission. Default is true.\n    func emptyDataSetShouldAllowTouch(_ scrollView: UIScrollView) -\u003e Bool\n\n    /// Asks the delegate for scroll permission. Default is false.\n    func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -\u003e Bool\n\n    /// Asks the delegate for image view animation permission. Default is false.\n    /// Make sure to return a valid CAAnimation object from imageAnimationForEmptyDataSet:\n    func emptyDataSetShouldAnimateImageView(_ scrollView: UIScrollView) -\u003e Bool\n\n    /// Tells the delegate that the empty dataset view was tapped.\n    /// Use this method either to resignFirstResponder of a textfield or searchBar.\n    func emptyDataSet(_ scrollView: UIScrollView, didTapView view: UIView)\n\n    /// Tells the delegate that the action button was tapped.\n    func emptyDataSet(_ scrollView: UIScrollView, didTapButton button: UIButton)\n\n    /// Tells the delegate that the empty data set will appear.\n    func emptyDataSetWillAppear(_ scrollView: UIScrollView)\n\n    /// Tells the delegate that the empty data set did appear.\n    func emptyDataSetDidAppear(_ scrollView: UIScrollView)\n\n    /// Tells the delegate that the empty data set will disappear.\n    func emptyDataSetWillDisappear(_ scrollView: UIScrollView)\n\n    /// Tells the delegate that the empty data set did disappear.\n    func emptyDataSetDidDisappear(_ scrollView: UIScrollView)\n}\n```\n\n#### EmptyDataSetSource\n```swift\npublic protocol EmptyDataSetSource: class {\n\n    /// Asks the data source for the title of the dataset.\n    /// The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string.\n    func title(forEmptyDataSet scrollView: UIScrollView) -\u003e NSAttributedString?\n    \n    /// Asks the data source for the description of the dataset.\n    /// The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string.\n    func description(forEmptyDataSet scrollView: UIScrollView) -\u003e NSAttributedString?\n    \n    /// Asks the data source for the image of the dataset.\n    func image(forEmptyDataSet scrollView: UIScrollView) -\u003e UIImage?\n    \n    /// Asks the data source for a tint color of the image dataset. Default is nil.\n    func imagetintColor(forEmptyDataSet scrollView: UIScrollView) -\u003e UIColor?\n\n    /// Asks the data source for the image animation of the dataset.\n    func imageAnimation(forEmptyDataSet scrollView: UIScrollView) -\u003e CAAnimation?\n    \n    /// Asks the data source for the title to be used for the specified button state.\n    /// The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string.\n    func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -\u003e NSAttributedString?\n    \n    /// Asks the data source for the image to be used for the specified button state.\n    /// This method will override buttonTitleForEmptyDataSet:forState: and present the image only without any text.\n    func buttonImage(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -\u003e UIImage?\n    \n    /// Asks the data source for a background image to be used for the specified button state.\n    /// There is no default style for this call.\n    func buttonBackgroundImage(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -\u003e UIImage?\n\n    /// Asks the data source for the background color of the dataset. Default is clear color.\n    func backgroundColor(forEmptyDataSet scrollView: UIScrollView) -\u003e UIColor?\n\n    /// Asks the data source for a custom view to be displayed instead of the default views such as labels, imageview and button. Default is nil.\n    /// Use this method to show an activity view indicator for loading feedback, or for complete custom empty data set.\n    /// Returning a custom view will ignore -offsetForEmptyDataSet and -spaceHeightForEmptyDataSet configurations.\n    func customView(forEmptyDataSet scrollView: UIScrollView) -\u003e UIView?\n\n    /// Asks the data source for a offset for vertical alignment of the content. Default is 0.\n    func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -\u003e CGFloat\n\n    /// Asks the data source for a vertical space between elements. Default is 11 pts.\n    func spaceHeight(forEmptyDataSet scrollView: UIScrollView) -\u003e CGFloat\n}\n```\n\n### Extensions\nUsage without conform to datasource and/or delegate.Tableview just calls the following method.\n\n```swift\npublic func emptyDataSetView(_ closure: @escaping (EmptyDataSetView) -\u003e Void)\n```\n\nExample:\n\n```swift\ntableView.emptyDataSetView { view in\n    view.titleLabelString(titleString)\n        .detailLabelString(detailString)\n        .image(image)\n        .imageAnimation(imageAnimation)\n        .buttonTitle(buttonTitle, for: .normal)\n        .buttonTitle(buttonTitle, for: .highlighted)\n        .buttonBackgroundImage(buttonBackgroundImage, for: .normal)\n        .buttonBackgroundImage(buttonBackgroundImage, for: .highlighted)\n        .dataSetBackgroundColor(backgroundColor)\n        .verticalOffset(verticalOffset)\n        .verticalSpace(spaceHeight)\n        .shouldDisplay(true, view: tableView)\n        .shouldFadeIn(true)\n        .isTouchAllowed(true)\n        .isScrollAllowed(true)\n        .isImageViewAnimateAllowed(isLoading)\n        .didTapDataButton {\n            // Do something\n        }\n        .didTapContentView {\n            // Do something\n        }\n}\n\n```\n\n### About CustomView\nSet customView by using EmptyDataSetSource, other setting will be invalid.Set customView by using Extensions, other autolayout will be invalid.\n\nRule for displaying CustomView\n1. CustomView will Display in the center of tableView\n2. The verticalOffset of customView can be setted by ```func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -\u003e CGFloat```\n3. The width and height is equel to the frame of customView.But if the customView is UILabel and it's frame is CGRect.zero,it's width and height will be autolayout by it's content.\n\n**Example:**\n\n#### Rule 1\n```swift\nfunc customView(forEmptyDataSet scrollView: UIScrollView) -\u003e UIView? {\n    let view = CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))\n    return view\n}\n```\n```swift\ntableView.emptyDataSetView { [weak self] view in\n    view.customView(CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150)))\n}\n```\nabove code will show as follows\n\n![CustomScreenShot_1](Example/ScreenShot/CustomViewScreenShot_1.png)\n\n#### Rule 2\n\n```swift\nfunc customView(forEmptyDataSet scrollView: UIScrollView) -\u003e UIView? {\n    let view = CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))\n    return view\n}\nfunc verticalOffset(forEmptyDataSet scrollView: UIScrollView) -\u003e CGFloat {\n    return 200\n}\n```\n```swift\ntableView.emptyDataSetView { [weak self] view in\n    view.customView(CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150)))\n        .verticalOffset(200)\n}\n```\n\nabove code will show as follows\n\n![CustomScreenShot_2](Example/ScreenShot/CustomViewScreenShot_2.png)\n\n#### Rule 3\n\n```swift\nfunc customView(forEmptyDataSet scrollView: UIScrollView) -\u003e UIView? {\n    let label = UILabel()\n    label.text = \"CustomView\"\n    label.backgroundColor = UIColor.red\n    return label\n}\n```\n\nabove code will show as follows\n\n![CustomScreenShot_3](Example/ScreenShot/CustomViewScreenShot_3.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXiaoye220%2FEmptyDataSet-Swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FXiaoye220%2FEmptyDataSet-Swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXiaoye220%2FEmptyDataSet-Swift/lists"}