commit 76634086c65fcdc3791c1cc5b90910781d56c014
parent 4a2a9cab63507ecf85396eeaede743381c37e9a9
Author: Kyle Milz <kyle@Kyles-MacBook-Pro.local>
Date: Mon, 29 Jun 2015 22:32:23 -0600
ios: fix a bug and reindent
Diffstat:
16 files changed, 283 insertions(+), 279 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,2 +1,2 @@
db
-
+.DS_Store
diff --git a/ios-ng/DBManager.m b/ios-ng/DBManager.m
@@ -14,144 +14,156 @@
@implementation DBManager
--(instancetype)initWithDatabaseFilename:(NSString *)dbFilename
+- (instancetype)initWithDatabaseFilename:(NSString *)dbFilename
{
- self = [super init];
+ self = [super init];
- if (self) {
- // Set the documents directory path to the documentsDirectory property.
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- self.documentsDirectory = [paths objectAtIndex:0];
-
- // Keep the database filename.
- self.databaseFilename = dbFilename;
-
- // Copy the database file into the documents directory if necessary.
- [self copyDatabaseIntoDocumentsDirectory];
- }
- return self;
+ if (self) {
+ // Set the documents directory path to the documentsDirectory property.
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ self.documentsDirectory = [paths objectAtIndex:0];
+
+ // Keep the database filename.
+ self.databaseFilename = dbFilename;
+
+ // Copy the database file into the documents directory if necessary.
+ [self copyDatabaseIntoDocumentsDirectory];
+ }
+ return self;
}
--(void)copyDatabaseIntoDocumentsDirectory
+- (void)copyDatabaseIntoDocumentsDirectory
{
- // Check if the database file exists in the documents directory.
- NSString *destinationPath = [self.documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
- if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
- // The database file does not exist in the documents directory, so copy it from the main bundle now.
- NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseFilename];
- NSError *error;
- [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:destinationPath error:&error];
-
- // Check if any error occurred during copying and display it.
- if (error != nil) {
- NSLog(@"%@", [error localizedDescription]);
- }
- }
+ // Check if the database file exists in the documents directory.
+ NSString *destinationPath = [self.documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
+ if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
+ // The database file does not exist in the documents directory,
+ // so copy it from the main bundle now.
+ NSString *sourcePath;
+ NSError *error;
+ sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseFilename];
+ [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:destinationPath error:&error];
+
+ // Check if any error occurred during copying and display it.
+ if (error != nil) {
+ NSLog(@"%@", [error localizedDescription]);
+ }
+ }
}
--(void)runQuery:(const char *)query isQueryExecutable:(BOOL)queryExecutable
+- (void)runQuery:(const char *)query isQueryExecutable:(BOOL)queryExecutable
{
- // Create a sqlite object.
- sqlite3 *sqlite3Database;
-
- // Set the database file path.
- NSString *databasePath = [self.documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
+ // Create a sqlite object.
+ sqlite3 *sqlite3Database;
- // Initialize the results array.
- if (self.arrResults != nil) {
- [self.arrResults removeAllObjects];
- self.arrResults = nil;
- }
- self.arrResults = [[NSMutableArray alloc] init];
+ // Set the database file path.
+ NSString *databasePath;
+ databasePath = [self.documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
- // Initialize the column names array.
- if (self.arrColumnNames != nil) {
- [self.arrColumnNames removeAllObjects];
- self.arrColumnNames = nil;
- }
- self.arrColumnNames = [[NSMutableArray alloc] init];
+ // Initialize the results array.
+ if (self.arrResults != nil) {
+ [self.arrResults removeAllObjects];
+ self.arrResults = nil;
+ }
+ self.arrResults = [[NSMutableArray alloc] init];
- // Open the database.
- BOOL openDatabaseResult = sqlite3_open([databasePath UTF8String], &sqlite3Database);
- if (openDatabaseResult != SQLITE_OK) {
- NSLog(@"opening database %@ failed: %s", databasePath, sqlite3_errmsg(sqlite3Database));
- return;
- }
+ // Initialize the column names array.
+ if (self.arrColumnNames != nil) {
+ [self.arrColumnNames removeAllObjects];
+ self.arrColumnNames = nil;
+ }
+ self.arrColumnNames = [[NSMutableArray alloc] init];
- // Declare a sqlite3_stmt object in which will be stored the query after having been compiled into a SQLite statement.
- sqlite3_stmt *compiledStatement;
+ // Open the database.
+ BOOL openDatabaseResult = sqlite3_open([databasePath UTF8String], &sqlite3Database);
+ if (openDatabaseResult != SQLITE_OK) {
+ NSLog(@"opening database %@ failed: %s", databasePath,
+ sqlite3_errmsg(sqlite3Database));
+ return;
+ }
- // Load all data from database to memory.
- BOOL prepareStatementResult = sqlite3_prepare_v2(sqlite3Database, query, -1, &compiledStatement, NULL);
- if (prepareStatementResult != SQLITE_OK) {
- NSLog(@"preparing query %s failed: %s", query, sqlite3_errmsg(sqlite3Database));
- sqlite3_close(sqlite3Database);
-
- return;
- }
+ // Declare a sqlite3_stmt object in which will be stored the query after
+ // having been compiled into a SQLite statement.
+ sqlite3_stmt *compiledStatement;
- // Check if the query is non-executable.
- if (!queryExecutable) {
- // In this case data must be loaded from the database.
+ // prepare statement
+ BOOL prepareStatementResult = sqlite3_prepare_v2(sqlite3Database, query, -1, &compiledStatement, NULL);
+ if (prepareStatementResult != SQLITE_OK) {
+ NSLog(@"preparing query %s failed: %s", query,
+ sqlite3_errmsg(sqlite3Database));
+ sqlite3_close(sqlite3Database);
+
+ return;
+ }
+
+ // Check if the query is non-executable.
+ if (!queryExecutable) {
+ // In this case data must be loaded from the database.
- // Declare an array to keep the data for each fetched row.
- NSMutableArray *arrDataRow;
+ // Declare an array to keep the data for each fetched row.
+ NSMutableArray *arrDataRow;
- // Loop through the results and add them to the results array row by row.
- while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
- // Initialize the mutable array that will contain the data of a fetched row.
- arrDataRow = [[NSMutableArray alloc] init];
-
- // Get the total number of columns.
- int totalColumns = sqlite3_column_count(compiledStatement);
+ // Loop through the results and add them to the results array
+ // row by row.
+ while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
+ // Initialize the mutable array that will contain the
+ // data of a fetched row.
+ arrDataRow = [[NSMutableArray alloc] init];
- // Go through all columns and fetch each column data.
- for (int i=0; i<totalColumns; i++){
- // Convert the column data to text (characters).
- char *dbDataAsChars = (char *)sqlite3_column_text(compiledStatement, i);
-
- // If there are contents in the currenct column (field) then add them to the current row array.
- if (dbDataAsChars != NULL) {
- // Convert the characters to string.
- [arrDataRow addObject:[NSString stringWithUTF8String:dbDataAsChars]];
- }
-
- // Keep the current column name.
- if (self.arrColumnNames.count != totalColumns) {
- dbDataAsChars = (char *)sqlite3_column_name(compiledStatement, i);
- [self.arrColumnNames addObject:[NSString stringWithUTF8String:dbDataAsChars]];
- }
- }
+ // Get the total number of columns.
+ int totalColumns = sqlite3_column_count(compiledStatement);
- // Store each fetched data row in the results array, but first check if there is actually data.
- if (arrDataRow.count > 0) {
- [self.arrResults addObject:arrDataRow];
- }
- }
- }
- else {
- // This is the case of an executable query (insert, update, ...).
-
- // Execute the query.
- BOOL executeQueryResults = sqlite3_step(compiledStatement);
- if (executeQueryResults == SQLITE_DONE) {
- // Keep the affected rows.
- self.affectedRows = sqlite3_changes(sqlite3Database);
-
- // Keep the last inserted row ID.
- self.lastInsertedRowID = sqlite3_last_insert_rowid(sqlite3Database);
- }
- else {
- // If could not execute the query show the error message on the debugger.
- NSLog(@"DB Error: %s", sqlite3_errmsg(sqlite3Database));
- }
- }
-
- // Release the compiled statement from memory.
- sqlite3_finalize(compiledStatement);
+ // Go through all columns and fetch each column data.
+ for (int i = 0; i < totalColumns; i++) {
+ // Convert the column data to text (characters).
+ char *dbDataAsChars = (char *)sqlite3_column_text(compiledStatement, i);
+
+ // If there are contents in the current column
+ // (field) then add them to the current row
+ // array.
+ if (dbDataAsChars != NULL) {
+ // Convert the characters to string.
+ [arrDataRow addObject:[NSString stringWithUTF8String:dbDataAsChars]];
+ }
+
+ // Keep the current column name.
+ if (self.arrColumnNames.count != totalColumns) {
+ dbDataAsChars = (char *)sqlite3_column_name(compiledStatement, i);
+ [self.arrColumnNames addObject:[NSString stringWithUTF8String:dbDataAsChars]];
+ }
+ }
- // Close the database.
- sqlite3_close(sqlite3Database);
+ // Store each fetched data row in the results array, but
+ // first check if there is actually data.
+ if (arrDataRow.count > 0) {
+ [self.arrResults addObject:arrDataRow];
+ }
+ }
+ }
+ else {
+ // executable query (insert, update, ...)
+
+ // Execute the query.
+ BOOL executeQueryResults = sqlite3_step(compiledStatement);
+ if (executeQueryResults == SQLITE_DONE) {
+ // Keep the affected rows.
+ self.affectedRows = sqlite3_changes(sqlite3Database);
+
+ // Keep the last inserted row ID.
+ self.lastInsertedRowID = sqlite3_last_insert_rowid(sqlite3Database);
+ }
+ else {
+ // If could not execute the query show the error message
+ // on the debugger.
+ NSLog(@"DB Error: %s", sqlite3_errmsg(sqlite3Database));
+ }
+ }
+
+ // Release the compiled statement from memory.
+ sqlite3_finalize(compiledStatement);
+
+ // Close the database.
+ sqlite3_close(sqlite3Database);
}
-@end
-\ No newline at end of file
+@end
diff --git a/ios-ng/shlist.xcodeproj/project.pbxproj b/ios-ng/shlist.xcodeproj/project.pbxproj
@@ -36,7 +36,7 @@
/* Begin PBXFileReference section */
27C70EFF1B32AF8000DADEB3 /* shlist.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = shlist.app; sourceTree = BUILT_PRODUCTS_DIR; };
27C70F031B32AF8000DADEB3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
- 27C70F041B32AF8000DADEB3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 27C70F041B32AF8000DADEB3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 1; };
27C70F061B32AF8000DADEB3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
27C70F071B32AF8000DADEB3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
27C70F091B32AF8000DADEB3 /* Server.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Server.h; path = shlist/Server.h; sourceTree = "<group>"; };
@@ -55,7 +55,7 @@
27C70F2F1B33F4FA00DADEB3 /* SharedListsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharedListsTableViewController.m; sourceTree = "<group>"; };
27C70F311B3650CB00DADEB3 /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
27C70F331B36513200DADEB3 /* DBManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBManager.h; sourceTree = "<group>"; };
- 27C70F341B36513200DADEB3 /* DBManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBManager.m; sourceTree = "<group>"; };
+ 27C70F341B36513200DADEB3 /* DBManager.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = DBManager.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 1; };
BF7776B71B38928D00526CB0 /* ListDetailTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListDetailTableViewController.h; sourceTree = "<group>"; };
BF7776B81B38928D00526CB0 /* ListDetailTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListDetailTableViewController.m; sourceTree = "<group>"; };
BF7776BA1B38D0DB00526CB0 /* ListItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListItem.h; sourceTree = "<group>"; };
diff --git a/ios-ng/shlist/AppDelegate.h b/ios-ng/shlist/AppDelegate.h
@@ -4,6 +4,4 @@
@property (strong, nonatomic) UIWindow *window;
-
@end
-
diff --git a/ios-ng/shlist/AppDelegate.m b/ios-ng/shlist/AppDelegate.m
@@ -20,6 +20,7 @@
// (such as an incoming phone call or SMS message) or when the user
// quits the application and it begins the transition to the background
// state.
+ //
// Use this method to pause ongoing tasks, disable timers, and throttle
// down OpenGL ES frame rates. Games should use this method to pause the
// game.
diff --git a/ios-ng/shlist/Base.lproj/Main.storyboard b/ios-ng/shlist/Base.lproj/Main.storyboard
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="0GJ-5e-Vr4">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="0GJ-5e-Vr4">
<dependencies>
<deployment identifier="iOS"/>
- <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
@@ -23,7 +23,7 @@
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rxW-Ue-XrL">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Q7z-lr-GKp">
@@ -63,13 +63,13 @@
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="zqW-ht-Knz">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="C9r-D2-l6m">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
@@ -115,9 +115,9 @@
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="new list name" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="gPO-fo-XXP">
<rect key="frame" x="0.0" y="88" width="600" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
- <textInputTraits key="textInputTraits"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections>
- <action selector="textField:" destination="BYZ-38-t0r" eventType="editingDidEnd" id="x6t-Ub-mbI"/>
+ <action selector="textField" destination="BYZ-38-t0r" eventType="editingDidEnd" id="x6t-Ub-mbI"/>
</connections>
</textField>
<datePicker contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="date" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="6qD-8D-Z17">
@@ -150,7 +150,7 @@
</barButtonItem>
</navigationItem>
<connections>
- <outlet property="date" destination="6qD-8D-Z17" id="pFe-hc-J9g"/>
+ <outlet property="datePicker" destination="6qD-8D-Z17" id="IVw-Zy-wT1"/>
<outlet property="saveButton" destination="gBs-i9-WN3" id="MOy-AZ-jOX"/>
<outlet property="textField" destination="gPO-fo-XXP" id="A02-ZD-oNk"/>
</connections>
diff --git a/ios-ng/shlist/ListDetailTableViewController.m b/ios-ng/shlist/ListDetailTableViewController.m
@@ -11,69 +11,69 @@
- (void)load_initial_data
{
- NSLog(@"ListDetailTableViewController::load_initial_data()");
-
- ListItem *item1 = [[ListItem alloc] init];
- item1.name = @"Axe";
- item1.owner = @"Kyle";
- [self.list_items addObject:item1];
-
- ListItem *item2 = [[ListItem alloc] init];
- item2.name = @"Camp Stove";
- item2.owner = @"<none>";
- [self.list_items addObject:item2];
-
- ListItem *item3 = [[ListItem alloc] init];
- item3.name = @"Tent";
- item3.owner = @"David";
- [self.list_items addObject:item3];
+ NSLog(@"ListDetailTableViewController::load_initial_data()");
+
+ ListItem *item1 = [[ListItem alloc] init];
+ item1.name = @"Axe";
+ item1.owner = @"Kyle";
+ [self.list_items addObject:item1];
+
+ ListItem *item2 = [[ListItem alloc] init];
+ item2.name = @"Camp Stove";
+ item2.owner = @"<none>";
+ [self.list_items addObject:item2];
+
+ ListItem *item3 = [[ListItem alloc] init];
+ item3.name = @"Tent";
+ item3.owner = @"David";
+ [self.list_items addObject:item3];
}
- (void)viewDidLoad
{
- [super viewDidLoad];
-
- // Uncomment the following line to preserve selection between presentations.
- // self.clearsSelectionOnViewWillAppear = NO;
-
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- // self.navigationItem.leftBarButtonItem = self.editButtonItem;
-
- self.list_items = [[NSMutableArray alloc] init];
- [self load_initial_data];
+ [super viewDidLoad];
+
+ // Uncomment the following line to preserve selection between
+ // presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the
+ // navigation bar for this view controller.
+ // self.navigationItem.leftBarButtonItem = self.editButtonItem;
+
+ self.list_items = [[NSMutableArray alloc] init];
+ [self load_initial_data];
}
- (void)didReceiveMemoryWarning
{
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
- return 1;
+ return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- return [self.list_items count];
+ return [self.list_items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListDetailPrototypeCell" forIndexPath:indexPath];
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListDetailPrototypeCell" forIndexPath:indexPath];
- NSLog(@"ListDetailTableViewController::cellForRowAtIndexPath()");
+ NSLog(@"ListDetailTableViewController::cellForRowAtIndexPath()");
- // Configure the cell...
-
- ListItem *item = [self.list_items objectAtIndex:indexPath.row];
- cell.textLabel.text = item.name;
- cell.detailTextLabel.text = item.owner;
-
- return cell;
+ ListItem *item = [self.list_items objectAtIndex:indexPath.row];
+ cell.textLabel.text = item.name;
+ cell.detailTextLabel.text = item.owner;
+
+ return cell;
}
/*
diff --git a/ios-ng/shlist/ListItem.h b/ios-ng/shlist/ListItem.h
@@ -5,4 +5,4 @@
@property NSString *name;
@property NSString *owner;
-@end
-\ No newline at end of file
+@end
diff --git a/ios-ng/shlist/ListItem.m b/ios-ng/shlist/ListItem.m
@@ -2,4 +2,4 @@
@implementation ListItem
-@end
-\ No newline at end of file
+@end
diff --git a/ios-ng/shlist/NewListViewController.m b/ios-ng/shlist/NewListViewController.m
@@ -1,9 +1,10 @@
#import "NewListViewController.h"
@interface NewListViewController ()
+
@property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;
@property (weak, nonatomic) IBOutlet UITextField *textField;
-@property (weak, nonatomic) IBOutlet UIDatePicker *date;
+@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;
@end
@@ -11,31 +12,32 @@
- (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
+ [super viewDidLoad];
+ // Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
-// In a storyboard-based application, you will often want to do a little preparation before navigation
+// preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
-
- if (sender != self.saveButton) return;
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
- if (self.textField.text.length > 0) {
- self.shared_list = [[SharedList alloc] init];
- self.shared_list.list_name = self.textField.text;
- self.shared_list.list_members = @"Test, Test";
-
- NSLog(@"prepareForSegue(): %@", self.textField.text);
- }
+ if (sender != self.saveButton) return;
+
+ if (self.textField.text.length > 0) {
+ self.shared_list = [[SharedList alloc] init];
+ self.shared_list.list_name = self.textField.text;
+ // self.shared_list.list_date = self.datePicker.date;
+ self.shared_list.list_members = @"Test, Test";
+
+ NSLog(@"NewListViewController::prepareForSegue(): %@", self.textField.text);
+ }
}
-@end
-\ No newline at end of file
+@end
diff --git a/ios-ng/shlist/Server.h b/ios-ng/shlist/Server.h
@@ -2,4 +2,7 @@
@interface Server : NSObject <NSStreamDelegate>
-@end
-\ No newline at end of file
+- (void)read;
+- (void)write;
+
+@end
diff --git a/ios-ng/shlist/Server.m b/ios-ng/shlist/Server.m
@@ -1,6 +1,7 @@
#import "Server.h"
@interface Server ()
+
- (void)network_init;
@end
@@ -9,40 +10,42 @@
NSInputStream *inputStream;
NSOutputStream *outputStream;
-bool initialized = 0;
+bool initialized = 0;
- (void)network_init
{
- CFReadStreamRef readStream;
- CFWriteStreamRef writeStream;
-
- CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"absentmindedproductions.ca", 5437, &readStream, &writeStream);
- inputStream = (__bridge NSInputStream *)readStream;
- outputStream = (__bridge NSOutputStream *)writeStream;
-
- [inputStream setDelegate:self];
- [outputStream setDelegate:self];
-
- [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
-
- [inputStream open];
- [outputStream open];
+ CFReadStreamRef readStream;
+ CFWriteStreamRef writeStream;
+
+ CFStringRef host_name = CFSTR("absentmindedproductions.ca");
+
+ CFStreamCreatePairWithSocketToHost(NULL, host_name, 5437, &readStream, &writeStream);
+ inputStream = (__bridge NSInputStream *)readStream;
+ outputStream = (__bridge NSOutputStream *)writeStream;
+
+ [inputStream setDelegate:self];
+ [outputStream setDelegate:self];
+
+ [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+ [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+
+ [inputStream open];
+ [outputStream open];
}
- (void)read
{
- if (!initialized) {
- [self network_init];
- }
+ if (!initialized) {
+ [self network_init];
+ }
}
- (void)write
{
- if (!initialized) {
- [self network_init];
- }
+ if (!initialized) {
+ [self network_init];
+ }
}
diff --git a/ios-ng/shlist/SharedList.h b/ios-ng/shlist/SharedList.h
@@ -13,4 +13,4 @@
- (void)set_name:(NSString*)name;
@end
-#endif
-\ No newline at end of file
+#endif
diff --git a/ios-ng/shlist/SharedList.m b/ios-ng/shlist/SharedList.m
@@ -3,9 +3,4 @@
@implementation SharedList
-- (void)set_name:(NSString*)name
-{
- self.list_name = name;
-}
-
-@end
-\ No newline at end of file
+@end
diff --git a/ios-ng/shlist/SharedListsTableViewController.m b/ios-ng/shlist/SharedListsTableViewController.m
@@ -10,91 +10,88 @@
- (void)load_initial_data
{
- // load local shared list data from db
- // sync with server and check if there's any updates
+ // load local shared list data from db
+ // sync with server and check if there's any updates
- NSLog(@"SharedListsTableViewController::load_initial_data()");
+ NSLog(@"SharedListsTableViewController::load_initial_data()");
- SharedList *list1 = [[SharedList alloc] init];
- list1.list_name = @"Camping";
- list1.list_members = @"David, Kyle, Greg";
- [self.shared_lists addObject:list1];
-
- SharedList *list2 = [[SharedList alloc] init];
- list2.list_name = @"Wedding";
- list2.list_members = @"Kyle, Stephanie";
- [self.shared_lists addObject:list2];
+ SharedList *list1 = [[SharedList alloc] init];
+ list1.list_name = @"Camping";
+ list1.list_members = @"David, Kyle, Greg";
+ [self.shared_lists addObject:list1];
+ SharedList *list2 = [[SharedList alloc] init];
+ list2.list_name = @"Wedding";
+ list2.list_members = @"Kyle, Stephanie";
+ [self.shared_lists addObject:list2];
}
- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
- NewListViewController *source = [segue sourceViewController];
- SharedList *list = source.shared_list;
+ NewListViewController *source = [segue sourceViewController];
+ SharedList *list = source.shared_list;
- if (list != nil) {
- [self.shared_lists addObject:list];
- [self.tableView reloadData];
- }
+ if (list != nil) {
+ [self.shared_lists addObject:list];
+ [self.tableView reloadData];
+ }
- NSLog(@"unwindToList(): done");
+ NSLog(@"unwindToList(): done");
}
- (void)viewDidLoad
{
- [super viewDidLoad];
+ [super viewDidLoad];
- // Uncomment the following line to preserve selection between presentations.
- // self.clearsSelectionOnViewWillAppear = NO;
+ // Uncomment the following line to preserve selection between
+ // presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- self.navigationItem.leftBarButtonItem = self.editButtonItem;
+ // display an Edit button in the navigation bar for this view controller
+ self.navigationItem.leftBarButtonItem = self.editButtonItem;
- self.shared_lists = [[NSMutableArray alloc] init];
- [self load_initial_data];
+ self.shared_lists = [[NSMutableArray alloc] init];
+ [self load_initial_data];
}
- (void)didReceiveMemoryWarning
{
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
- return 1;
+ return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- return [self.shared_lists count];
+ return [self.shared_lists count];
}
-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SharedListPrototypeCell" forIndexPath:indexPath];
- // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SharedListPrototypeCell"];
+ UITableViewCell *cell;
+ cell = [tableView dequeueReusableCellWithIdentifier:@"SharedListPrototypeCell" forIndexPath:indexPath];
+ // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SharedListPrototypeCell"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SharedListPrototypeCell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
+ if (cell == nil) {
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SharedListPrototypeCell"];
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+ }
-
- NSLog(@"cellForRowAtIndexPath(): start");
-
- // Configure the cell...
-
- SharedList *shared_list = [self.shared_lists objectAtIndex:indexPath.row];
- cell.textLabel.text = shared_list.list_name;
- cell.detailTextLabel.text = shared_list.list_members;
+ NSLog(@"SharedListsTableViewController::cellForRowAtIndexPath()");
- return cell;
-}
+ // configure the cell
+ SharedList *shared_list = [self.shared_lists objectAtIndex:indexPath.row];
+ cell.textLabel.text = shared_list.list_name;
+ cell.detailTextLabel.text = shared_list.list_members;
+ return cell;
+}
/*
// Override to support conditional editing of the table view.
diff --git a/ios-ng/shlist/main.m b/ios-ng/shlist/main.m
@@ -2,7 +2,7 @@
#import "AppDelegate.h"
int main(int argc, char *argv[]) {
- @autoreleasepool {
- return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
- }
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
}