Skip to content

Commit

Permalink
Swift Atlassian Example
Browse files Browse the repository at this point in the history
  • Loading branch information
cnstoll committed Jun 21, 2014
1 parent 44169e4 commit 86280e3
Show file tree
Hide file tree
Showing 18 changed files with 1,024 additions and 6 deletions.
433 changes: 433 additions & 0 deletions Examples/MMRecordAtlassian/MMRecordAtlassian.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0600"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "26FA0E9419551BDB008068A2"
BuildableName = "MMRecordAtlassian.app"
BlueprintName = "MMRecordAtlassian"
ReferencedContainer = "container:MMRecordAtlassian.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "26FA0EA919551BDB008068A2"
BuildableName = "MMRecordAtlassianTests.xctest"
BlueprintName = "MMRecordAtlassianTests"
ReferencedContainer = "container:MMRecordAtlassian.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "26FA0E9419551BDB008068A2"
BuildableName = "MMRecordAtlassian.app"
BlueprintName = "MMRecordAtlassian"
ReferencedContainer = "container:MMRecordAtlassian.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "26FA0E9419551BDB008068A2"
BuildableName = "MMRecordAtlassian.app"
BlueprintName = "MMRecordAtlassian"
ReferencedContainer = "container:MMRecordAtlassian.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "26FA0E9419551BDB008068A2"
BuildableName = "MMRecordAtlassian.app"
BlueprintName = "MMRecordAtlassian"
ReferencedContainer = "container:MMRecordAtlassian.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6154.21" systemVersion="14A261i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="t4b-9P-e7D">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.13"/>
</dependencies>
<scenes>
<!--Plans View Controller - Plans-->
<scene sceneID="F3l-fJ-4qS">
<objects>
<tableViewController id="MVv-bU-iyr" customClass="PlansViewController" customModule="MMRecordAtlassian" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" ambiguous="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="Wze-BI-6I5">
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" ambiguous="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="CellIdentifier" id="cVB-GO-hwh">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="cVB-GO-hwh" id="VuR-BK-E0I">
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="MVv-bU-iyr" id="ELg-gC-4OW"/>
<outlet property="delegate" destination="MVv-bU-iyr" id="GS2-xy-E8c"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Plans" id="exC-VY-TNj"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="mgA-NS-yeM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="760" y="387"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="hjg-21-U3h">
<objects>
<navigationController id="t4b-9P-e7D" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="vpQ-g0-UFn">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="barTintColor" red="0.10196078431372549" green="0.23921568627450981" blue="0.42745098039215684" alpha="1" colorSpace="calibratedRGB"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</textAttributes>
</navigationBar>
<connections>
<segue destination="MVv-bU-iyr" kind="relationship" relationship="rootViewController" id="lgQ-Zs-Gfu"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Wvo-WV-jWe" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="60" y="387"/>
</scene>
</scenes>
</document>
118 changes: 118 additions & 0 deletions Examples/MMRecordAtlassian/MMRecordAtlassian/Classes/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// AppDelegate.swift
// MMRecordAtlassian
//
// Created by Conrad Stoll on 6/20/14.
// Copyright (c) 2014 Mutual Mobile. All rights reserved.
//

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
ATLRecord.registerServerClass(MMJSONServer);
MMJSONServer.registerResourceName("plans", forPathComponent: "/plans")

return true
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
self.saveContext()
}

func saveContext () {
var error: NSError? = nil
let managedObjectContext = self.managedObjectContext
if managedObjectContext != nil {
if managedObjectContext.hasChanges && !managedObjectContext.save(&error) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
//println("Unresolved error \(error), \(error.userInfo)")
abort()
}
}
}

// #pragma mark - Core Data stack

// Returns the managed object context for the application.
// If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
var managedObjectContext: NSManagedObjectContext {
if !_managedObjectContext {
let coordinator = self.persistentStoreCoordinator
if coordinator != nil {
_managedObjectContext = NSManagedObjectContext()
_managedObjectContext!.persistentStoreCoordinator = coordinator
}
}
return _managedObjectContext!
}
var _managedObjectContext: NSManagedObjectContext? = nil

// Returns the managed object model for the application.
// If the model doesn't already exist, it is created from the application's model.
var managedObjectModel: NSManagedObjectModel {
if !_managedObjectModel {
let modelURL = NSBundle.mainBundle().URLForResource("MMRecordAtlassian", withExtension: "momd")
_managedObjectModel = NSManagedObjectModel(contentsOfURL: modelURL)
}
return _managedObjectModel!
}
var _managedObjectModel: NSManagedObjectModel? = nil

// Returns the persistent store coordinator for the application.
// If the coordinator doesn't already exist, it is created and the application's store added to it.
var persistentStoreCoordinator: NSPersistentStoreCoordinator {
if !_persistentStoreCoordinator {
let storeURL = self.applicationDocumentsDirectory.URLByAppendingPathComponent("MMRecordAtlassian.sqlite")
var error: NSError? = nil
_persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
if _persistentStoreCoordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil, error: &error) == nil {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
Typical reasons for an error here include:
* The persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.
If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
If you encounter schema incompatibility errors during development, you can reduce their frequency by:
* Simply deleting the existing store:
NSFileManager.defaultManager().removeItemAtURL(storeURL, error: nil)
* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
[NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true}
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
*/
//println("Unresolved error \(error), \(error.userInfo)")
abort()
}
}
return _persistentStoreCoordinator!
}
var _persistentStoreCoordinator: NSPersistentStoreCoordinator? = nil

// #pragma mark - Application's Documents directory

// Returns the URL to the application's Documents directory.
var applicationDocumentsDirectory: NSURL {
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.endIndex-1] as NSURL
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ATLRecord.swift
// MMRecordAtlassian
//
// Created by Conrad Stoll on 6/20/14.
// Copyright (c) 2014 Mutual Mobile. All rights reserved.
//

import CoreData

class ATLRecord: MMRecord {
override class func keyPathForResponseObject() -> String {
return "plans.plan"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Plan.swift
// MMRecordAtlassian
//
// Created by Conrad Stoll on 6/20/14.
// Copyright (c) 2014 Mutual Mobile. All rights reserved.
//

import CoreData

class Plan: ATLRecord {
@NSManaged var name: NSString
@NSManaged var id: NSString
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ "expand":"plans",
"link": {"rel":"self","href":"http:https://myhost:8085/rest/api/latest/plan"},
"plans": { "expand":"plan",
"size":2,
"max-result":2,
"start-index":0,
"plan":[
{"name":"My Plan 1","key":"MYPLAN1","link":{"rel":"self","href":"http:https://myhost:8085/rest/api/latest/plan/MYPLAN1"}},
{"name":"My Plan 2","key":"MYPLAN2","link":{"rel":"self","href":"http:https://myhost:8085/rest/api/latest/plan/MYPLAN2"}},
{"name":"My Plan 3","key":"MYPLAN3","link":{"rel":"self","href":"http:https://myhost:8085/rest/api/latest/plan/MYPLAN3"}}
]}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// ViewController.swift
// MMRecordAtlassian
//
// Created by Conrad Stoll on 6/20/14.
// Copyright (c) 2014 Mutual Mobile. All rights reserved.
//

import UIKit

class PlansViewController: UITableViewController, UITableViewDataSource {
var plans: Plan[] = []

override func viewDidLoad() {
super.viewDidLoad()

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

Plan.startRequestWithURN("/plans",
data: nil,
context: managedObjectContext,
domain: self,
resultBlock: {records in
var results: Plan[] = records as Plan[]

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

})
}

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

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return plans.count
}

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

cell.textLabel.text = plan.name

return cell
}
}

Loading

0 comments on commit 86280e3

Please sign in to comment.