Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion IMGTreeTableView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@
24C3DE7E1AC4B617008E3087 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0620;
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Geoff MacDonald";
TargetAttributes = {
24386E111B389007009DA1A6 = {
Expand Down Expand Up @@ -310,6 +312,7 @@
INFOPLIST_FILE = "$(SRCROOT)/IMGTreeTableViewDemo/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -323,6 +326,7 @@
INFOPLIST_FILE = "$(SRCROOT)/IMGTreeTableViewDemo/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -346,6 +350,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -370,6 +375,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -398,6 +404,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down
50 changes: 25 additions & 25 deletions IMGTreeTableView/IMGTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class IMGTree: NSObject, NSCoding, NSCopying {

// go through each top level object creating the resulting node subtree for each one recursively with the process(:::) method
for rootObject in rootArray {
let rootNode = nodeClass(parentNode: tree.rootNode)
let rootNode = nodeClass.init(parentNode: tree.rootNode)
constructorDelegate.configureNode(rootNode, modelObject: rootObject)
if let childObjects = constructorDelegate.childrenForNodeObject(rootObject) {
rootNode.children = IMGTree.process(tree.rootNode, childObjects: childObjects, tree: tree, constructorDelegate: constructorDelegate) as! [IMGTreeNode]
Expand All @@ -69,7 +69,7 @@ public class IMGTree: NSObject, NSCoding, NSCopying {
let nodeClass = constructorDelegate.classForNode()
var childNodes: [IMGTreeNode] = []
for childObject in childObjects {
let childNode = nodeClass(parentNode: parentNode)
let childNode = nodeClass.init(parentNode: parentNode)
constructorDelegate.configureNode(childNode, modelObject: childObject)
if let childObjects = constructorDelegate.childrenForNodeObject(childObject) {
childNode.children = IMGTree.process(tree.rootNode, childObjects: childObjects, tree: tree, constructorDelegate: constructorDelegate) as! [IMGTreeNode]
Expand All @@ -88,7 +88,7 @@ public class IMGTree: NSObject, NSCoding, NSCopying {

//MARK: NSCoding

required convenience public init(coder aDecoder: NSCoder) {
required convenience public init?(coder aDecoder: NSCoder) {
self.init()
//TODO: implementation
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {
*/
public var children: [IMGTreeNode] = [] {
didSet {
children = children.map({ (var node: IMGTreeNode) -> IMGTreeNode in
children = children.map({ (node: IMGTreeNode) -> IMGTreeNode in
node.parentNode = self
node.controller = self.controller
return node
Expand Down Expand Up @@ -317,7 +317,7 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {

//MARK: NSCoding

public required init(coder aDecoder: NSCoder) {
public required init?(coder aDecoder: NSCoder) {
fatalError("")
}

Expand All @@ -343,7 +343,7 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {
Remove a child.
*/
func removeChild(child: IMGTreeNode) {
if let targetIndex = find(children, child) {
if let targetIndex = children.indexOf(child) {
children.removeAtIndex(targetIndex)
}
}
Expand Down Expand Up @@ -373,23 +373,23 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {
Finds the location, if any, of the node with this instances children regardless of visibility
*/
func indexForNode(node: IMGTreeNode) -> Int? {
var traversal = infixTraversal(visible: false)
return find(traversal, node)
let traversal = infixTraversal(false)
return traversal.indexOf(node)
}

/**
Finds the location, if any, of the node with this instances visible children
*/
func visibleIndexForNode(node: IMGTreeNode) -> Int? {
var traversal = infixTraversal()
return find(traversal, node)
let traversal = infixTraversal()
return traversal.indexOf(node)
}

/**
Finds the number of visible child nodes
*/
func traversalCount() -> Int {
return infixTraversal(visible: false).count ?? 0
return infixTraversal(false).count ?? 0
}

/**
Expand Down Expand Up @@ -421,7 +421,7 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {
Does there exist a user selection within any of this nodes subtree
*/
func isSelectionNodeInTraversal(visible: Bool? = true) -> Bool {
let traversal = infixTraversal(visible: visible!)
let traversal = infixTraversal(visible!)
for node in traversal {
if node.isKindOfClass(IMGTreeSelectionNode) {
return true
Expand All @@ -444,11 +444,11 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {
*/
func infixTraversal(visible: Bool = true) -> [IMGTreeNode] {

var traversal = { (childNodes: [IMGTreeNode]) -> [IMGTreeNode] in
let traversal = { (childNodes: [IMGTreeNode]) -> [IMGTreeNode] in
var traversal: [IMGTreeNode] = []
for node in childNodes {
traversal.append(node)
traversal.extend(node.infixTraversal(visible: visible))
traversal.appendContentsOf(node.infixTraversal(visible))
}
if visible && self.rootNode == self && !self.preventCacheUse {
self.visibleInfixCache = traversal
Expand All @@ -457,7 +457,7 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {
}

if visible {
var childNodes = children.filter({ (node: IMGTreeNode) -> Bool in
let childNodes = children.filter({ (node: IMGTreeNode) -> Bool in
return node.isVisible
})
return traversal(childNodes)
Expand Down Expand Up @@ -516,7 +516,7 @@ public class IMGTreeNode: NSObject, NSCoding, NSCopying {
//MARK: NSCopying

public func copyWithZone(zone: NSZone) -> AnyObject {
let nodeCopy = self.dynamicType(parentNode: parentNode!)
let nodeCopy = self.dynamicType.init(parentNode: parentNode!)
nodeCopy.controller = controller
nodeCopy.isVisible = isVisible
nodeCopy.parentNode = parentNode
Expand Down Expand Up @@ -544,7 +544,7 @@ public class IMGTreeActionNode : IMGTreeNode {
/**
Class for nodes that represent collapsed sections
*/
public class IMGTreeCollapsedSectionNode : IMGTreeNode, NSCopying {
public class IMGTreeCollapsedSectionNode : IMGTreeNode {

/**
The anchor or top level node this collapsed node is ancestor to
Expand Down Expand Up @@ -572,8 +572,8 @@ public class IMGTreeCollapsedSectionNode : IMGTreeNode, NSCopying {
var indicesForContainingNodes: [NSIndexPath] {
var rowsToHide: [NSIndexPath] = []

rowsToHide.extend(originatingNode.visibleIndicesForTraversal())
originatingNode.children.map({ (var child: IMGTreeNode) -> IMGTreeNode in
rowsToHide.appendContentsOf(originatingNode.visibleIndicesForTraversal())
originatingNode.children.map({ (child: IMGTreeNode) -> IMGTreeNode in
child.isVisible = false
return child
})
Expand All @@ -590,22 +590,22 @@ public class IMGTreeCollapsedSectionNode : IMGTreeNode, NSCopying {
var indicesToBeHidden: NSIndexSet {
let rowsDeleted = NSMutableIndexSet()

var firstRemovalIndex = anchorNode.visibleTraversalIndex()! + 1
var removeRange = anchorNode.visibleTraversalCount
let firstRemovalIndex = anchorNode.visibleTraversalIndex()! + 1
let removeRange = anchorNode.visibleTraversalCount

rowsDeleted.addIndexesInRange(NSMakeRange(firstRemovalIndex, removeRange))

return rowsDeleted.copy() as! NSIndexSet
}

var nodesToBeHidden: [IMGTreeNode] {
var nodes = anchorNode.infixTraversal()
let nodes = anchorNode.infixTraversal()
return nodes
}

// MARK: Initializers

public required init(coder aDecoder: NSCoder) {
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down Expand Up @@ -648,7 +648,7 @@ public class IMGTreeCollapsedSectionNode : IMGTreeNode, NSCopying {
//MARK: NSCopying

public override func copyWithZone(zone: NSZone) -> AnyObject {
var nodeCopy = self.dynamicType(parentNode: originatingNode)
let nodeCopy = self.dynamicType.init(parentNode: originatingNode)
nodeCopy.isVisible = isVisible
nodeCopy.children = children.map({ (childNode: IMGTreeNode) -> IMGTreeNode in
return childNode.copy() as! IMGTreeNode
Expand All @@ -661,4 +661,4 @@ public class IMGTreeCollapsedSectionNode : IMGTreeNode, NSCopying {
public override var description : String {
return "Collapsed Node: \(rootNode.visibleIndexForNode(self)!) \n"
}
}
}
20 changes: 10 additions & 10 deletions IMGTreeTableView/IMGTreeTableController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class IMGTreeTableController: NSObject, UITableViewDataSource{
func setNodeChildrenVisiblility(parentNode: IMGTreeNode, visibility: Bool) {

if !visibility {
for child in reverse(parentNode.children) {
for child in Array(parentNode.children.reverse()) {
child.isVisible = visibility
}
} else {
Expand Down Expand Up @@ -158,7 +158,7 @@ public class IMGTreeTableController: NSObject, UITableViewDataSource{
}

public func hideActionNode () {
if let currentActionNode = actionNode {
if let _ = actionNode {
transactionInProgress = true
//hide previous selection node
actionNode?.removeFromParent()
Expand All @@ -168,7 +168,7 @@ public class IMGTreeTableController: NSObject, UITableViewDataSource{
}

public func nodePassingTest(test: (node: IMGTreeNode) -> Bool) -> IMGTreeNode? {
if let traversal = tree?.rootNode.infixTraversal(visible: false) {
if let traversal = tree?.rootNode.infixTraversal(false) {
for node in traversal {
if test(node: node) {
return node
Expand All @@ -185,13 +185,13 @@ public class IMGTreeTableController: NSObject, UITableViewDataSource{
var currentNode = node
var selectedNodes: [IMGTreeNode] = []
while currentNode.parentNode != nil {
var selectedNode = currentNode.parentNode!
let selectedNode = currentNode.parentNode!
selectedNodes.append(selectedNode)
currentNode = selectedNode
}

disableAnimation = true
for selectedNode in reverse(selectedNodes) {
for selectedNode in Array(selectedNodes.reverse()) {
didSelectNode(selectedNode)
}
disableAnimation = false
Expand Down Expand Up @@ -270,7 +270,7 @@ public class IMGTreeTableController: NSObject, UITableViewDataSource{
//delete rows collapsed section will hide
let nodesToHide = collapsedNode.nodesToBeHidden
let nodeIndicesToHide = collapsedNode.indicesToBeHidden
for internalNode in reverse(nodesToHide) {
for internalNode in Array(nodesToHide.reverse()) {
internalNode.isVisible = false
}

Expand Down Expand Up @@ -406,23 +406,23 @@ public class IMGTreeTableController: NSObject, UITableViewDataSource{
tableView.beginUpdates()
}

var addedIndices: [AnyObject] = []
var addedIndices: [NSIndexPath] = []
for node in insertedNodes {

if let rowIndex = node.visibleTraversalIndex() {
let indexPath = NSIndexPath(forRow: rowIndex, inSection: 0)
addedIndices.append(indexPath)
}
addedIndices.extend(node.visibleIndicesForTraversal() as [AnyObject])
addedIndices.appendContentsOf(node.visibleIndicesForTraversal() as [NSIndexPath])
}

var deletedIndices: [AnyObject] = []
var deletedIndices: [NSIndexPath] = []
for node in deletedNodes {
if let rowIndex = node.previousVisibleIndex {
let indexPath = NSIndexPath(forRow: rowIndex, inSection: 0)
deletedIndices.append(indexPath)
}
deletedIndices.extend(node.previousVisibleChildren! as [AnyObject])
deletedIndices.appendContentsOf(node.previousVisibleChildren! as [NSIndexPath])
}

if !disableAnimation {
Expand Down
2 changes: 1 addition & 1 deletion IMGTreeTableView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>Imgur.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 2 additions & 2 deletions IMGTreeTableViewDemo/IMGSampleTreeConstructor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import UIKit
import IMGTreeTableView

class IMGCommentNode: IMGTreeNode, NSCopying {
class IMGCommentNode: IMGTreeNode {
var comment: String?

override var description : String {
return "Node: \(comment!)"
}

override func copyWithZone(zone: NSZone) -> AnyObject {
var copy = super.copyWithZone(zone) as! IMGCommentNode
let copy = super.copyWithZone(zone) as! IMGCommentNode
copy.comment = comment
return copy
}
Expand Down
2 changes: 1 addition & 1 deletion IMGTreeTableViewDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>imgur.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion IMGTreeTableViewDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ViewController: UIViewController, IMGTreeTableControllerDelegate, UITableV
// MARK: IMGTreeTableControllerDelegate

func cell(node: IMGTreeNode, indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.accessoryType = .None
switch node {
case let commentNode as IMGCommentNode:
Expand Down