Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP postponed till next release] Todo app / tutorial #40

Closed
wants to merge 17 commits into from
Closed
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
529 changes: 529 additions & 0 deletions tutorial/TodoApp/TodoApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions tutorial/TodoApp/TodoApp/Base.lproj/Main_iPad.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4451" systemVersion="13A461" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3676"/>
</dependencies>
<scenes>
<!--class Prefix:identifier View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="TViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="20" width="768" height="1004"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar" statusBarStyle="blackOpaque"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
133 changes: 133 additions & 0 deletions tutorial/TodoApp/TodoApp/Base.lproj/Main_iPhone.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="47r-n5-Q0k">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
</dependencies>
<scenes>
<!--Add Todo View Controller-->
<scene sceneID="5Bw-cH-Xn7">
<objects>
<viewController id="t1e-Pe-f2e" customClass="TAddTodoViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="o2f-ae-4fk"/>
<viewControllerLayoutGuide type="bottom" id="Cvh-lk-Sgz"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="NOv-lK-h9X">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2Ze-vr-yX5">
<rect key="frame" x="20" y="25" width="48" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Cancel">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="cancelButtonPress:" destination="t1e-Pe-f2e" eventType="touchUpInside" id="dlK-68-4XX"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="tag-Wb-WnU">
<rect key="frame" x="260" y="20" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<state key="normal" title="Add">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="addTodoPress:" destination="t1e-Pe-f2e" eventType="touchUpInside" id="2jf-sw-Cqg"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="aD2-AP-vwA">
<rect key="frame" x="20" y="68" width="280" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UsU-z8-gsq">
<rect key="frame" x="26" y="120" width="116" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.85098930027173914" green="0.24948018057888441" blue="0.21548504675320662" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<connections>
<outlet property="alertLabel" destination="UsU-z8-gsq" id="fYo-VH-TmE"/>
<outlet property="todoName" destination="aD2-AP-vwA" id="2z0-48-fnK"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Cf0-dX-vjR" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1197" y="256"/>
</scene>
<!--Todo Table View Controller-->
<scene sceneID="k38-x1-PY9">
<objects>
<tableViewController id="zDj-7N-wt1" customClass="TTodoTableViewController" sceneMemberID="viewController">
<tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" showsSelectionImmediatelyOnTouchBegin="NO" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="Rhq-NR-3Sv">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="checkmark" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Todo" textLabel="d66-5w-nvR" style="IBUITableViewCellStyleDefault" id="mZx-V6-d9G">
<rect key="frame" x="0.0" y="86" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mZx-V6-d9G" id="Ygx-mu-pam">
<rect key="frame" x="0.0" y="0.0" width="281" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Tiitle" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="d66-5w-nvR">
<rect key="frame" x="15" y="0.0" width="266" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="zDj-7N-wt1" id="prT-c1-hNq"/>
<outlet property="delegate" destination="zDj-7N-wt1" id="DFD-9u-xMG"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="KYk-Np-bR8">
<barButtonItem key="rightBarButtonItem" title="Add todo" id="yec-QY-Kll">
<connections>
<segue destination="t1e-Pe-f2e" kind="modal" id="B3R-gc-f4f"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qkN-Oa-KZZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="718" y="263"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="GvQ-rD-iZ8">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="47r-n5-Q0k" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="rzV-Qd-38p">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="zDj-7N-wt1" kind="relationship" relationship="rootViewController" id="h4D-Qa-OeS"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="xzn-7w-EHv" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="125" y="246"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"subtype" : "retina4",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
7 changes: 7 additions & 0 deletions tutorial/TodoApp/TodoApp/TAddTodoViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <UIKit/UIKit.h>

@interface TAddTodoViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *todoName;
@property (weak, nonatomic) IBOutlet UILabel *alertLabel;

@end
61 changes: 61 additions & 0 deletions tutorial/TodoApp/TodoApp/TAddTodoViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#import "TAddTodoViewController.h"
#import "TAppDelegate.h"
#import <Tightdb/Tightdb.h>


@interface TAddTodoViewController ()

@end

@implementation TAddTodoViewController


- (void)viewDidLoad
{
[super viewDidLoad];

// Auto select input field when modal is shown
[self.todoName becomeFirstResponder];
}

// Close modal when user presses Cancel button
- (IBAction)cancelButtonPress:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}

// Add todo to db, when user presses Add button
- (IBAction)addTodoPress:(id)sender {

NSString *todo = self.todoName.text;

// Only add to db if todoName has been entered
if(todo.length > 0) {

TAppDelegate* delegate = (TAppDelegate*)[[UIApplication sharedApplication]delegate];

bool success = [delegate.sharedGroup writeWithBlock:^(TightdbGroup *tnx) {

TightdbTable *todoTable = [tnx getTable:@"todos" error:nil];

TightdbCursor *row = [todoTable addEmptyRow];
[row setString:self.todoName.text inColumn:0];

return YES; // Commit
} withError:nil];

if (success) {
// Close modal
[self dismissViewControllerAnimated:YES completion:nil];

// Make parent reload the todos from the db
[self.parentViewController viewWillAppear:YES ];
}

} else {
// If no name has been entered, show an error alert
self.alertLabel.text = @"Enter name for todo";
}
}


@end
9 changes: 9 additions & 0 deletions tutorial/TodoApp/TodoApp/TAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import <UIKit/UIKit.h>
#import <Tightdb/Tightdb.h>

@interface TAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TightdbSharedGroup *sharedGroup;

@end
42 changes: 42 additions & 0 deletions tutorial/TodoApp/TodoApp/TAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#import "TAppDelegate.h"
#import <Tightdb/Tightdb.h>

@implementation TAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

self.sharedGroup = [TightdbSharedGroup sharedGroupWithFile:[self pathForDataFile:@"todosdb2.tightdb"] withError:nil];


TAppDelegate* delegate = (TAppDelegate*)[[UIApplication sharedApplication]delegate];

[delegate.sharedGroup writeWithBlock:^(TightdbGroup *tnx) {


TightdbTable *todoTable = [tnx getTable:@"todos" error:nil];

if([todoTable getColumnCount] == 0) {
[todoTable addColumnWithType:tightdb_String andName:@"todoName"];
[todoTable addColumnWithType:tightdb_Bool andName:@"completed"];
}

return YES; // Commit
} withError:nil];

return YES;
}

- (NSString *) pathForDataFile:(NSString *)filename {
NSArray* documentDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* path = nil;

if (documentDir) {
path = [documentDir objectAtIndex:0];
}

return [NSString stringWithFormat:@"%@/%@", path, filename];
}

@end
5 changes: 5 additions & 0 deletions tutorial/TodoApp/TodoApp/TTodoTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>

@interface TTodoTableViewController : UITableViewController

@end
Loading