Skip to content

Commit

Permalink
using default arguments in function initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshhgupta committed Dec 7, 2015
1 parent e29a7c6 commit b35b0c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions Source/TagCellLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TagCellLayout: UICollectionViewLayout {

var layoutInfoList = Array<TagCellLayoutInfo>()
var lastTagPosition = CGPointZero
var tagAlignmentType: TagAlignmentType?
var tagAlignmentType = TagAlignmentType.Left

var numberOfTagsInCurrentRow = 0
var tagsCount = 0
Expand All @@ -23,7 +23,7 @@ public class TagCellLayout: UICollectionViewLayout {

//MARK: - Init Methods

public init(tagAlignmentType: TagAlignmentType?, delegate: TagCellLayoutDelegate?) {
public init(tagAlignmentType: TagAlignmentType = .Left, delegate: TagCellLayoutDelegate?) {
super.init()
self.delegate = delegate
self.tagAlignmentType = tagAlignmentType
Expand All @@ -34,7 +34,7 @@ public class TagCellLayout: UICollectionViewLayout {
}

override convenience init() {
self.init(tagAlignmentType: nil, delegate: nil)
self.init(delegate: nil)
}

//MARK: - Override Methods
Expand Down Expand Up @@ -202,9 +202,7 @@ private extension TagCellLayout {

func distributionFactor() -> Float {
var factor = Float(1.0)
if let type = tagAlignmentType {
factor = type.distributionFactor
}
factor = tagAlignmentType.distributionFactor
return factor
}

Expand Down
2 changes: 1 addition & 1 deletion TagCellLayout/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi
defaultSetup()

// THIS IS ALL WHAT IS REQUIRED TO SETUP YOUR TAGS
let tagCellLayout = TagCellLayout(tagAlignmentType: .Center, delegate: self)
let tagCellLayout = TagCellLayout(delegate: self)
collectionView?.collectionViewLayout = tagCellLayout
}

Expand Down

0 comments on commit b35b0c1

Please sign in to comment.