Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #17 from nekonora/feature/#16-SPM-Support
Browse files Browse the repository at this point in the history
SPM Support
  • Loading branch information
nekonora committed Sep 7, 2019
2 parents c770f19 + 54f1779 commit 322d8bb
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 83 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Example/Pods/TaggerKit.xctestplan

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 13 additions & 27 deletions Example/TaggerKit/ViewController.swift
Expand Up @@ -17,8 +17,8 @@ class ViewController: UIViewController {
@IBOutlet var testContainer : UIView!

// We want the whole experience, let's create two TKCollectionViews
let productTags = TKCollectionView()
let allTags = TKCollectionView()
var productTags: TKCollectionView!
var allTags: TKCollectionView!

// MARK: - Lifecycle Methods
override func viewDidLoad() {
Expand All @@ -30,47 +30,35 @@ class ViewController: UIViewController {
// testCollection.customSpacing = 20.0 // Spacing between cells
// testCollection.customBackgroundColor = UIColor.red // Background of cells

// These are the tags already added by the user, give an aray of strings to the collection
productTags.tags = ["Tech", "Design", "Writing", "Social Media"]
productTags = TKCollectionView(tags: [
"Tech", "Design", "Writing", "Social Media"
],
action: .removeTag,
receiver: nil)

// These are intended to be all the tags the user has added in the app, which are going to be filtered
allTags.tags = ["Cars", "Skateboard", "Freetime", "Humor", "Travel", "Music", "Places", "Journalism", "Music", "Sports"]

/*
We set this collection's action to .removeTag,
becasue these are supposed to be the tags the user has already added
*/
productTags.action = .removeTag
allTags = TKCollectionView(tags: [
"Cars", "Skateboard", "Freetime", "Humor", "Travel", "Music", "Places", "Journalism", "Sports"
],
action: .addTag,
receiver: productTags)

// Set the current controller as the delegate of both collections
productTags.delegate = self
allTags.delegate = self

// "testCollection" takes the tags sent by "searchCollection"
allTags.receiver = productTags

// The tags in "searchCollection" are going to be added, so we set the action to addTag
allTags.action = .addTag

// Set the sender and receiver of the TextField
addTagsTextField.sender = allTags
addTagsTextField.receiver = productTags

add(productTags, toView: testContainer)
add(allTags, toView: searchContainer)
}

}

// MARK: - Extension to TKCollectionViewDelegate

extension ViewController: TKCollectionViewDelegate {

/*
These methods come from UIViewController now conforming to TKCollectionViewDelegate,
You use these to do whatever you want when a tag is added or removed (e.g. save to file, etc)
*/


func tagIsBeingAdded(name: String?) {
// Example: save testCollection.tags to UserDefault
print("added \(name!)")
Expand All @@ -79,6 +67,4 @@ extension ViewController: TKCollectionViewDelegate {
func tagIsBeingRemoved(name: String?) {
print("removed \(name!)")
}

}

16 changes: 16 additions & 0 deletions Package.swift
@@ -0,0 +1,16 @@
// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "TaggerKit",
platforms: [.iOS(.v11)],
products: [
.library(name: "TaggerKit", targets: ["TaggerKit"])
],
targets: [
.target(
name: "TaggerKit",
path: "TaggerKit"
)
]
)
14 changes: 11 additions & 3 deletions README.md
Expand Up @@ -18,6 +18,11 @@ TaggerKit is writtern is compatible with Swift 4.2/5 and runs on iOS 11+.

## Changelog

### 0.6.1
• Added support for Swift Package Manager;
• Fixed a bug that was causing a tag view to not send tags to another one by tapping the button;
• Added a convenience init method to create a tag view more quickly;

### 0.6
`tagIsBeingAdded` and `tagIsBeingRemoved` methods are not accessible by override from UIViewControllers. This is because UIViewController is not a delegate of TKViewController anymore. If you want to use these methods you can still make your controller conform to the TKCollectionViewDelegate protocol;
• Custom properties `customTagBorderWidth` and `customTagBorderColor` can now be set;
Expand All @@ -27,19 +32,22 @@ TaggerKit is writtern is compatible with Swift 4.2/5 and runs on iOS 11+.

## Installation

TaggerKit is available through [CocoaPods](https://cocoapods.org). To install the latest version (updated for Swift 5)
, just add the following line to your Podfile:
TaggerKit is available through [CocoaPods](https://cocoapods.org), Carthage or SPM.

To install the latest version, just add the following line to your Podfile:

```ruby
pod 'TaggerKit'
```

Or in your Cartfile:
In your Cartfile:

```ruby
github "nekonora/TaggerKit" ~> 0.6.0
```

Or add this repo as a swift package inside of Xcode 11.

## Setup

### Static tags
Expand Down
2 changes: 1 addition & 1 deletion TaggerKit.podspec
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'TaggerKit'
s.version = '0.6.0'
s.version = '0.6.1'
s.summary = 'TaggerKit is a straightforward library that helps you implement tags in your iOS project.'

# This description is used to generate tags and improve search results.
Expand Down
Empty file removed TaggerKit/Assets/.gitkeep
Empty file.
26 changes: 0 additions & 26 deletions TaggerKit/Classes/Source/CollectionView/TKCollectionView+.swift
Expand Up @@ -22,32 +22,6 @@ extension TKCollectionView: UICollectionViewDataSource {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TKCell", for: indexPath) as? TKTagCell else { return UICollectionViewCell() }
return cell
}

public func addNewTag(named tag: String) {
guard let receiver = receiver, !tag.isEmpty, receiver.tags.contains(tag) else { return }

receiver.tags.insert(tag, at: 0)

let indexPath = IndexPath(item: 0, section: 0)

receiver.tagsCollectionView.performBatchUpdates({
receiver.tagsCollectionView.insertItems(at: [indexPath])
}, completion: nil)
}

public func removeOldTag(named tag: String) {
guard tags.contains(tag) else { return }

if let index = tags.firstIndex(of: tag) {
tags.remove(at: index)

let indexPath = IndexPath(item: index, section: 0)

tagsCollectionView.performBatchUpdates({
self.tagsCollectionView?.deleteItems(at: [indexPath])
}, completion: nil)
}
}
}

// MARK: - Extension to UICollectionViewDelegate
Expand Down
69 changes: 56 additions & 13 deletions TaggerKit/Classes/Source/CollectionView/TKCollectionView.swift
Expand Up @@ -44,16 +44,16 @@ public class TKCollectionView: UIViewController {
// MARK: - Class properties

/// The actual collectionView inside the controller, where every cell is a tag
public var tagsCollectionView : UICollectionView!
public var tagsCollectionView: UICollectionView!

/// The custom cell layout of the single cell
public var tagCellLayout : TagCellLayout!
public var tagCellLayout: TagCellLayout!

/// If tags in the collection are given an action of type "add", a receiver can be automatically binded on this property
public var receiver : TKCollectionView?
public var receiver: TKCollectionView?

/// A controller that confromed to be a delegate for the tags collection view
public var delegate : TKCollectionViewDelegate?
public var delegate: TKCollectionViewDelegate?

lazy var oneLineHeight: CGFloat = { customFont.pointSize * 2 }()

Expand All @@ -64,6 +64,14 @@ public class TKCollectionView: UIViewController {

// MARK: - Lifecycle methods

public convenience init(tags: [String], action: ActionType, receiver: TKCollectionView?) {
self.init()

self.action = action
self.receiver = receiver
self.tags = tags
}

public override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -76,21 +84,56 @@ public class TKCollectionView: UIViewController {
tagsCollectionView.frame = view.bounds
}

// MARK - Public Methods

/// Adds a tag to the tag view
/// - Parameter tag: the name of the tag to add
public func addNewTag(named tag: String) {
guard
receiver != nil,
!tag.isEmpty
else { return }

if receiver!.tags.contains(tag) {
return
} else {
receiver!.tags.insert(tag, at: 0)
let indexPath = IndexPath(item: 0, section: 0)
receiver!.tagsCollectionView.performBatchUpdates({
receiver!.tagsCollectionView.insertItems(at: [indexPath])
}, completion: nil)
}
}

/// Removes a tag from the tag view
/// - Parameter tag: the name of the tag to remove
public func removeOldTag(named tag: String) {
guard tags.contains(tag) else { return }

if let index = tags.firstIndex(of: tag) {
tags.remove(at: index)

let indexPath = IndexPath(item: index, section: 0)

tagsCollectionView.performBatchUpdates({
self.tagsCollectionView?.deleteItems(at: [indexPath])
}, completion: nil)
}
}

// MARK: - Class Methods

private func setupView() {
tagCellLayout = TagCellLayout(alignment: .left, delegate: self)
tagCellLayout.delegate = self
tagCellLayout = TagCellLayout(alignment: .left, delegate: self)
tagCellLayout.delegate = self

tagsCollectionView = UICollectionView(frame: view.bounds, collectionViewLayout: tagCellLayout)
tagsCollectionView.dataSource = self
tagsCollectionView.delegate = self
tagsCollectionView.alwaysBounceVertical = true
tagsCollectionView.backgroundColor = UIColor.clear
tagsCollectionView = UICollectionView(frame: view.bounds, collectionViewLayout: tagCellLayout)
tagsCollectionView.dataSource = self
tagsCollectionView.delegate = self
tagsCollectionView.alwaysBounceVertical = true
tagsCollectionView.backgroundColor = UIColor.clear
tagsCollectionView.register(TKTagCell.self, forCellWithReuseIdentifier: "TKCell")

view.addSubview(tagsCollectionView)
}

}

11 changes: 0 additions & 11 deletions TaggerKit/Classes/Source/Extensions/UIViewController+.swift
Expand Up @@ -27,19 +27,8 @@ public extension UIViewController {
view.removeFromSuperview()
removeFromParent()
}

}

// MARK: - Extension to TKCollectionViewDelegate

//extension UIViewController: TKCollectionViewDelegate {
//
// @objc open func tagIsBeingAdded(name: String?) { }
//
// @objc open func tagIsBeingRemoved(name: String?) { }
//
//}

extension UIBezierPath {

func shapeImage(view: UIView) -> UIImage? {
Expand Down
4 changes: 2 additions & 2 deletions TaggerKit/Classes/Source/TextField/TKTextField.swift
Expand Up @@ -16,10 +16,10 @@ public class TKTextField: UITextField {
// Objects to operate - obviously should not be the same

/// A collection view of tags that can be sent to a receiver collection
public var sender : TKCollectionView? { didSet { allTags = sender?.tags } }
public var sender: TKCollectionView? { didSet { allTags = sender?.tags } }

/// A collection view of tags that receives tags from other senders
public var receiver : TKCollectionView?
public var receiver: TKCollectionView?

var allTags: [String]!

Expand Down

0 comments on commit 322d8bb

Please sign in to comment.