Skip to main content

iOS Persisting Data

After completing the first PluralSight course and a working App, the first thing I noticed is that my app does not persist data. One of the main goals of this app is to help you track, over time, how many carbs you eat. You can enter data into the app, interact with that data, but once you close the app it all goes away. Thats not terrible useful, so I needed to find a way to store the data that is entered.

I know a little about iOS, and knew that CoreData was a framework that iOS has to store data within an app, so I searched on PluralSight for CoreData and found one course, Introduction to iOS for .NET Developers, by Jon Flanders. I thought, "Hey! That is me, awesome." First major difference in this course over others I have watched, he has broken it up into almost all 1 minute segments. That sort of makes sense here because he is mostly just relating .NET to iOS development, and assumes that once you know how to translate what you want to do in .NET to iOS that you can either figure out what question to ask next or figure it out on your own. Given that, I expect that I will return to this course more when I don't know what to ask Google. Disappointingly, this course did not go into CoreData in a significant way, so I wasn't able to get what I wanted at this time out of this course.

I went back and searched again using the term Core Data instead of CoreData. I found an entire course devoted to Core Data, Core Data Fundamentals, by Brice Wilson. Hopefully this course will provide the information I need to get started with saving data entered into my app. During the introduction, Brice talks about another course of his for consuming web services and storing smaller, more simple data in an app. It sounds like that might be a very good course to come back to if I need to have a web service feeding me data. He also talked about the demo app he will build in this course, which sounds like a great way for me to learn what I was looking for.

At first glance, even though he says it is not, the closest comparison I can make for CoreData is Entity Framework Code-First. Similar to EF, an Entity relates to a table and Attributes relate to a Column in that table. You can define relationships between Entities very much like a Database Foreign Key Constraint, including the ability to cascade delete.

Getting started creating an Entity is really very easy. You add a File and choose the Core Data -> Data Model file type. Then you can start adding Entities using the plus button. Adding Attributes is also as easy as a plus button. Looking at the properties of an attribute I see some things you would expect like data type and whether or not the Attribute is optional. I also found something I was not expecting, validation fields. Core Data has built into it the ability to define minimums and maximums. I will be curious to see how these work out, it can get tiresome always needing to do sanity checks in .NET because none of the objects you are working with are smart enough to know that they can't be below zero or before the year 1/1/1900, EF on a SQL 2005 Server, I am looking at you.

Comments

Popular posts from this blog

Converting a Large AngularJS Application to TypeScript Part 1

I work on a project that uses AngularJS heavily. Recently we wondered if using a preprocesser like CoffeeScript or TypeScript for our JavaScript would be beneficial. If our team is going to switch languages, we would need to be able to convert existing code over without much pain and we would have to find enough value in switching that it would be worth the conversion.

I had read an article that stated that because TypeScript is a SuperSet of JavaScript, you could convert a plain JavaScript file to TypeScript by changing the extension to .ts and not much else would need to change. I wanted to test out this claim, so I took a file that I was familiar with, an Angular Controller, and tried to convert it to TypeScript to see how much effort it would take and then try to figure out where we would benefit from using TypeScript.

This is what the controller JavaScript file looked like to start out with:
(function () { 'use strict'; angular .module('app') …

Converting a Large AngularJS Application to TypeScript Part 2

In part 1 I was able to take an Angular controller written in JavaScript and convert it to a TypeScript file while doing very little to change the code. In this post I am going to explore transitioning that same controller to actually use the features provided in TypeScript. This is how I left off my controller:
declare var angular: any; (function () { 'use strict'; var controller: any = function($scope){ ... } angular .module('app') .controller('controller', controller); controller.$inject = ["$scope"]; })();
While performing the translation from JavaScript to TypeScript, I would make sure at every step that the functionality I expected still worked, so if anything I did broke the system I would change it back and try again with another approach. Also if something seemed like it worked too easily, I would break it on purpose to make sure I wasn't getting a false result through browser caching a previously working fil…

Gamify TDD

I like it when things that would not normally be associated with games add concepts from games as a way to incentives you to accomplish things. Why simply go for a run if you can have an app that will track you and give you a gold star if you do better than you did the last time? Why go to the coffee shop that only gives you coffee if the other one will give you points that you can redeem for free drinks eventually?

I was recently introduced to CodeSchool, an online training system similar to PluralSight, it has video courses and challenges you can take to prove that you retained what the video taught. CodeSchool also adds badges and tracks to your learning, so as you complete a video and its challenges you get a badge. Complete a collection of courses within a specific discipline and you become a master of that discipline.

Some of these incentives are not tangible and really don't mean much in the real world, but they tend to work for me. If I start working towards a large goal a…