Skip to content

Commit

Permalink
removed c-style code
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Dahan committed Apr 1, 2016
1 parent 08eb2da commit ea25d67
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Graph.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Graph'
s.version = '1.0.10'
s.version = '1.0.11'
s.license = 'BSD'
s.summary = 'An elegant data-driven framework for CoreData in Swift.'
s.homepage = 'http://cosmicmind.io'
Expand Down
21 changes: 15 additions & 6 deletions Sources/GraphSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@ public extension Graph {

if toFilter {
var seen: Dictionary<String, Bool> = Dictionary<String, Bool>()
var i: Int = nodes.count
while 0 <= --i {
var i: Int = nodes.count - 1
while 0 <= i {
if let v: ManagedEntity = nodes[i] as? ManagedEntity {
if nil == seen.updateValue(true, forKey: v.id) {
nodes[i] = Entity(object: v)
i -= 1
continue
}
} else if let v: ManagedEntity = Graph.context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedEntity {
if nil == seen.updateValue(true, forKey: v.id) {
nodes[i] = Entity(object: v)
i -= 1
continue
}
}
nodes.removeAtIndex(i)
i -= 1
}
return nodes as! Array<Entity>
} else {
Expand Down Expand Up @@ -115,20 +118,23 @@ public extension Graph {

if toFilter {
var seen: Dictionary<String, Bool> = Dictionary<String, Bool>()
var i: Int = nodes.count
while 0 <= --i {
var i: Int = nodes.count - 1
while 0 <= i {
if let v: ManagedRelationship = nodes[i] as? ManagedRelationship {
if nil == seen.updateValue(true, forKey: v.id) {
nodes[i] = Relationship(object: v)
i -= 1
continue
}
} else if let v: ManagedRelationship = Graph.context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedRelationship {
if nil == seen.updateValue(true, forKey: v.id) {
nodes[i] = Relationship(object: v)
i -= 1
continue
}
}
nodes.removeAtIndex(i)
i -= 1
}
return nodes as! Array<Relationship>
} else {
Expand Down Expand Up @@ -170,20 +176,23 @@ public extension Graph {

if toFilter {
var seen: Dictionary<String, Bool> = Dictionary<String, Bool>()
var i: Int = nodes.count
while 0 <= --i {
var i: Int = nodes.count - 1
while 0 <= i {
if let v: ManagedAction = nodes[i] as? ManagedAction {
if nil == seen.updateValue(true, forKey: v.id) {
nodes[i] = Action(object: v)
i -= 1
continue
}
} else if let v: ManagedAction = Graph.context!.objectWithID(nodes[i]["node"]! as! NSManagedObjectID) as? ManagedAction {
if nil == seen.updateValue(true, forKey: v.id) {
nodes[i] = Action(object: v)
i -= 1
continue
}
}
nodes.removeAtIndex(i)
i -= 1
}
return nodes as! Array<Action>
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/GraphWatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public extension Graph {
internal func prepareForObservation() {
NSNotificationCenter.defaultCenter().removeObserver(self)
NSNotificationCenter.defaultCenter().removeObserver(self, name: NSManagedObjectContextDidSaveNotification, object: Graph.context)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "managedObjectContextDidSave:", name: NSManagedObjectContextDidSaveNotification, object: Graph.context)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(managedObjectContextDidSave(_:)), name: NSManagedObjectContextDidSaveNotification, object: Graph.context)
}

//
Expand Down
2 changes: 1 addition & 1 deletion Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.10</string>
<string>1.0.11</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
21 changes: 14 additions & 7 deletions Tests/ActionStressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class ActionStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue(5 == action.subjects.count)
XCTAssertTrue(5 == action.objects.count)

if 100 == ++insertActionCount {
insertActionCount += 1
if 100 == insertActionCount {
insertExpectation?.fulfill()
}
}
Expand All @@ -151,7 +152,8 @@ class ActionStressTests : XCTestCase, GraphDelegate {
XCTAssertEqual(5, action.subjects.count)
XCTAssertEqual(5, action.objects.count)

if 100 == ++insertPropertyCount {
insertPropertyCount += 1
if 100 == insertPropertyCount {
insertPropertyExpectation?.fulfill()
}
}
Expand All @@ -162,7 +164,8 @@ class ActionStressTests : XCTestCase, GraphDelegate {
XCTAssertEqual(5, action.subjects.count)
XCTAssertEqual(5, action.objects.count)

if 100 == ++insertGroupCount {
insertGroupCount += 1
if 100 == insertGroupCount {
insertGroupExpectation?.fulfill()
}
}
Expand All @@ -175,7 +178,8 @@ class ActionStressTests : XCTestCase, GraphDelegate {
XCTAssertEqual(5, action.subjects.count)
XCTAssertEqual(5, action.objects.count)

if 100 == ++updatePropertyCount {
updatePropertyCount += 1
if 100 == updatePropertyCount {
updatePropertyExpectation?.fulfill()
}
}
Expand All @@ -185,7 +189,8 @@ class ActionStressTests : XCTestCase, GraphDelegate {
XCTAssertEqual(5, action.subjects.count)
XCTAssertEqual(5, action.objects.count)

if 0 == --insertActionCount {
insertActionCount -= 1
if 0 == insertActionCount {
deleteExpectation?.fulfill()
}
}
Expand All @@ -197,7 +202,8 @@ class ActionStressTests : XCTestCase, GraphDelegate {
XCTAssertEqual(5, action.subjects.count)
XCTAssertEqual(5, action.objects.count)

if 0 == --insertPropertyCount {
insertPropertyCount -= 1
if 0 == insertPropertyCount {
deletePropertyExpectation?.fulfill()
}
}
Expand All @@ -208,7 +214,8 @@ class ActionStressTests : XCTestCase, GraphDelegate {
XCTAssertEqual(5, action.subjects.count)
XCTAssertEqual(5, action.objects.count)

if 0 == --insertGroupCount {
insertGroupCount -= 1
if 0 == insertGroupCount {
deleteGroupExpectation?.fulfill()
}
}
Expand Down
21 changes: 14 additions & 7 deletions Tests/EntityStressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class EntityStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue(entity["P"] as? String == "A")
XCTAssertTrue(entity.hasGroup("G"))

if 1000 == ++insertEntityCount {
insertEntityCount += 1
if 1000 == insertEntityCount {
insertExpectation?.fulfill()
}
}
Expand All @@ -128,7 +129,8 @@ class EntityStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("A" == value as? String)
XCTAssertTrue(entity[property] as? String == value as? String)

if 1000 == ++insertPropertyCount {
insertPropertyCount += 1
if 1000 == insertPropertyCount {
insertPropertyExpectation?.fulfill()
}
}
Expand All @@ -137,7 +139,8 @@ class EntityStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("T" == entity.type)
XCTAssertTrue("G" == group)

if 1000 == ++insertGroupCount {
insertGroupCount += 1
if 1000 == insertGroupCount {
insertGroupExpectation?.fulfill()
}
}
Expand All @@ -148,15 +151,17 @@ class EntityStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("B" == value as? String)
XCTAssertTrue(entity[property] as? String == value as? String)

if 1000 == ++updatePropertyCount {
updatePropertyCount += 1
if 1000 == updatePropertyCount {
updatePropertyExpectation?.fulfill()
}
}

func graphDidDeleteEntity(graph: Graph, entity: Entity) {
XCTAssertTrue("T" == entity.type)

if 0 == --insertEntityCount {
insertEntityCount -= 1
if 0 == insertEntityCount {
deleteExpectation?.fulfill()
}
}
Expand All @@ -166,7 +171,8 @@ class EntityStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("P" == property)
XCTAssertTrue("B" == value as? String)

if 0 == --insertPropertyCount {
insertPropertyCount -= 1
if 0 == insertPropertyCount {
deletePropertyExpectation?.fulfill()
}
}
Expand All @@ -175,7 +181,8 @@ class EntityStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("T" == entity.type)
XCTAssertTrue("G" == group)

if 0 == --insertGroupCount {
insertGroupCount -= 1
if 0 == insertGroupCount {
deleteGroupExpectation?.fulfill()
}
}
Expand Down
21 changes: 14 additions & 7 deletions Tests/RelationshipStressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class RelationshipStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("S" == relationship.subject?.type)
XCTAssertTrue("O" == relationship.object?.type)

if 1000 == ++insertRelationshipCount {
insertRelationshipCount += 1
if 1000 == insertRelationshipCount {
insertExpectation?.fulfill()
}
}
Expand All @@ -136,7 +137,8 @@ class RelationshipStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("S" == relationship.subject?.type)
XCTAssertTrue("O" == relationship.object?.type)

if 1000 == ++insertPropertyCount {
insertPropertyCount += 1
if 1000 == insertPropertyCount {
insertPropertyExpectation?.fulfill()
}
}
Expand All @@ -145,7 +147,8 @@ class RelationshipStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("T" == relationship.type)
XCTAssertTrue("G" == group)

if 1000 == ++insertGroupCount {
insertGroupCount += 1
if 1000 == insertGroupCount {
insertGroupExpectation?.fulfill()
}
}
Expand All @@ -158,7 +161,8 @@ class RelationshipStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("S" == relationship.subject?.type)
XCTAssertTrue("O" == relationship.object?.type)

if 1000 == ++updatePropertyCount {
updatePropertyCount += 1
if 1000 == updatePropertyCount {
updatePropertyExpectation?.fulfill()
}
}
Expand All @@ -168,7 +172,8 @@ class RelationshipStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("S" == relationship.subject?.type)
XCTAssertTrue("O" == relationship.object?.type)

if 0 == --insertRelationshipCount {
insertRelationshipCount -= 1
if 0 == insertRelationshipCount {
deleteExpectation?.fulfill()
}
}
Expand All @@ -180,7 +185,8 @@ class RelationshipStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("S" == relationship.subject?.type)
XCTAssertTrue("O" == relationship.object?.type)

if 0 == --insertPropertyCount {
insertPropertyCount -= 1
if 0 == insertPropertyCount {
deletePropertyExpectation?.fulfill()
}
}
Expand All @@ -191,7 +197,8 @@ class RelationshipStressTests : XCTestCase, GraphDelegate {
XCTAssertTrue("S" == relationship.subject?.type)
XCTAssertTrue("O" == relationship.object?.type)

if 0 == --insertGroupCount {
insertGroupCount -= 1
if 0 == insertGroupCount {
deleteGroupExpectation?.fulfill()
}
}
Expand Down

0 comments on commit ea25d67

Please sign in to comment.