Skip to content

Commit

Permalink
Working Swiftly
Browse files Browse the repository at this point in the history
  • Loading branch information
cnstoll committed Jun 25, 2014
1 parent b9a391f commit 2482fa2
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@
import CoreData

class InwardLink: Link {
override class func shouldUseSubEntityRecordClassToRepresentData(dict : NSDictionary) -> Bool {
let inwardIssue : AnyObject! = dict["inwardIssue"]

if (inwardIssue) {
return true
}

return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import CoreData

class Issue: ATLRecord {
@NSManaged var key: NSString
@NSManaged var primaryKey: NSString
@NSManaged var id: NSString
@NSManaged var issueLinks: NSSet
@NSManaged var issueLinks: NSOrderedSet
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import CoreData

class Link: ATLRecord {
@NSManaged var name: NSString
@NSManaged var id: NSString
@NSManaged var name: NSString
@NSManaged var key: NSString
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
import CoreData

class OutwardLink: Link {
override class func shouldUseSubEntityRecordClassToRepresentData(dict : NSDictionary) -> Bool {
let outwardIssue : AnyObject! = dict["outwardIssue"]

if (outwardIssue) {
return true
}

return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,46 @@ import UIKit
import CoreData

class IssuesViewController: UITableViewController {

var issue : Issue?
var links : Link[] = []

override func viewDidLoad() {
super.viewDidLoad()

var appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
var managedObjectContext = appDelegate.managedObjectContext

// var options = Issue.defaultOptions()
// options.entityPrimaryKeyInjectionBlock =
// {(entity: NSEntityDescription, dictionary: NSDictionary, parentProtoRecord: MMRecordProtoRecord) -> NSCopying in
// return ""
// }
var options = Issue.defaultOptions()

options.entityPrimaryKeyInjectionBlock = {(entity, dictionary, parentProtoRecord) -> NSCopying in
let dict = dictionary as Dictionary
let key : AnyObject? = dict["id"]
let returnKey = key as String
return returnKey
}

options.recordPrePopulationBlock = { protoRecord in
let proto : MMRecordProtoRecord = protoRecord
let entity : NSEntityDescription = protoRecord.entity

var dictionary : AnyObject! = proto.dictionary.mutableCopy()
var mutableDictionary : NSMutableDictionary = dictionary as NSMutableDictionary
var primaryKey : AnyObject! = ""

if (entity.name == "OutwardLink") {
primaryKey = mutableDictionary.valueForKeyPath("outwardIssue.key")
}

if (entity.name == "InwardLink") {
primaryKey = mutableDictionary.valueForKeyPath("inwardIssue.key")
}

mutableDictionary.setValue(primaryKey, forKey: "PrimaryKey")

proto.dictionary = mutableDictionary
}

Issue.setOptions(options)

Issue.startRequestWithURN("/issue",
data: nil,
Expand All @@ -30,11 +58,41 @@ class IssuesViewController: UITableViewController {
resultBlock: {records in
var results: Issue[] = records as Issue[]
print("\(results)")
self.issue = results[results.startIndex]

self.title = "Linked Issues for \(self.issue?.id)"

let array = self.issue?.issueLinks.array
let linksArray : Link[] = array as Link[]

if (array) {
self.links = linksArray
}

self.tableView.reloadData()
},
failureBlock: { error in

})
}

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
return 1
}

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
print("\(links)")
return links.count
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell = tableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: indexPath) as UITableViewCell
var link = links[indexPath.row]

//print("\(link.key) \(link.name)\n")
cell.textLabel.text = link.key

return cell
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6172.15" systemVersion="14A261i" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="InwardLink" representedClassName="MMRecordAtlassian.InwardLink" parentEntity="Link" syncable="YES"/>
<entity name="InwardLink" representedClassName="MMRecordAtlassian.InwardLink" parentEntity="Link" syncable="YES">
<userInfo>
<entry key="MMRecordEntityPrimaryAttributeKey" value="id"/>
</userInfo>
</entity>
<entity name="Issue" representedClassName="MMRecordAtlassian.Issue" syncable="YES">
<attribute name="id" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="key" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="issueLinks" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Link" inverseName="issue" inverseEntity="Link" syncable="YES"/>
<attribute name="primaryKey" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="issueLinks" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="Link" inverseName="issue" inverseEntity="Link" syncable="YES">
<userInfo>
<entry key="MMRecordAttributeAlternateNameKey" value="fields.issuelinks"/>
</userInfo>
</relationship>
<userInfo>
<entry key="MMRecordEntityPrimaryAttributeKey" value="id"/>
<entry key="MMRecordEntityPrimaryAttributeKey" value="primaryKey"/>
</userInfo>
</entity>
<entity name="Link" representedClassName="MMRecordAtlassian.Link" syncable="YES">
<attribute name="id" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="key" optional="YES" attributeType="String" syncable="YES">
<userInfo>
<entry key="MMRecordAttributeAlternateNameKey" value="PrimaryKey"/>
</userInfo>
</attribute>
<attribute name="name" optional="YES" attributeType="String" syncable="YES">
<userInfo>
<entry key="MMRecordAttributeAlternateNameKey" value="id"/>
Expand All @@ -21,7 +34,11 @@
<entry key="MMRecordEntityPrimaryAttributeKey" value="id"/>
</userInfo>
</entity>
<entity name="OutwardLink" representedClassName="MMRecordAtlassian.OutwardLink" parentEntity="Link" syncable="YES"/>
<entity name="OutwardLink" representedClassName="MMRecordAtlassian.OutwardLink" parentEntity="Link" syncable="YES">
<userInfo>
<entry key="MMRecordEntityPrimaryAttributeKey" value="id"/>
</userInfo>
</entity>
<entity name="Plan" representedClassName="MMRecordAtlassian.Plan" syncable="YES">
<attribute name="id" optional="YES" attributeType="String" syncable="YES">
<userInfo>
Expand All @@ -34,10 +51,10 @@
</userInfo>
</entity>
<elements>
<element name="Plan" positionX="-63" positionY="-18" width="128" height="75"/>
<element name="InwardLink" positionX="-36" positionY="45" width="128" height="45"/>
<element name="Issue" positionX="-63" positionY="0" width="128" height="88"/>
<element name="Link" positionX="-45" positionY="36" width="128" height="88"/>
<element name="InwardLink" positionX="-36" positionY="45" width="128" height="43"/>
<element name="Link" positionX="-45" positionY="36" width="128" height="105"/>
<element name="OutwardLink" positionX="-18" positionY="54" width="128" height="43"/>
<element name="Plan" positionX="-63" positionY="-18" width="128" height="75"/>
</elements>
</model>

0 comments on commit 2482fa2

Please sign in to comment.