Last week we began creating an iOS application.
We covered most of what is required but we did not tackle persistence, which we will do today.
This post is based on my Pluralsight course Beginning Mobile Development with Xamarin.
We begin by adding a package to our project: Sqlite-net.
Posted in Essentials
In the previous two posts in this series, I demonstrated how to create a simple to-do list using Xamarin.Forms. In this and the next post, I’ll show how to create pretty much the same program for iOS using Xamarin native code.
To begin, open Xamarin Studio and create a new solution, choosing iOS/App -> Single View App and name it ToDoiOS. We’ll begin by roughing out the UI. Open the file Main.storyboard. You’ll find a View Controller. Go to the toolbox and drag a Navigation Controller onto the storyboard — notice that it brings its own ViewController.
In the previous posting I started a new project in Xamarin.Forms that I will reproduce in
iOS and Android in coming posts.
Today, we’ll take a look at the second page in the Xamarin.Forms version: ListTasksPage.
This lists the tasks that you entered and persisted in the previous posting.
[Originally posted Oct. 12, 2009]
Spent the early hours of this morning reading a great blog post by Jeff Atwoodwhich makes reference to a Elizer S. Yudkowsky’s Intuitive Explanationof Bayesian Probability. The timing was good as I had just finished the (highly recommended) book The Drunkard’s Walk which agreed with Jeff that most humans simply are not wired to deal with probability very well.
In this and a number of following posts, I’ll build the same program three times: once in Xamarin.Forms, once in iOS and once in Android.
This is directly based on my Pluralsight course, Beginning Mobile Development with Xamarin
To get started, we’ll go through the Xamarin.Forms application fairly quickly as this series has already covered a lot of material on writing Xamarin.Forms applications. Let’s begin by creating our model class: ToDoItem
Last week we looked at a simple example of customizing a control and creating a custom renderer. This week we go a bit deeper. Our goal is to give a BoxView a border, and to adjust that border dynamically.
[ This content is taken from my forthcoming Pluralsight course ]
As noted last week, we start with an Element and a Renderer. In our case, the element will be a SpecialBoxView. Unlike last week, however, this custom class will have contents; specifically the properties we want to be able to bind to.
Xamarin.Forms is a killer framework, and it has a wide variety of very flexible controls. But sometimes you run into restrictions on the control that you really need to override. The answer to this dilemma is to create a customized control.
To understand how to create a customized control, you must first understand that every control consists of an element (e.g., a button) and a renderer (the platform-specific code that tells the phone how to draw the element.
The trick to customizing a control is to override one or more methods in the renderer. To see this at work, we’re going to start very easy with a shaded button. Future postings will tackle more complex rendering.
[This blog post is based on material from my forthcoming Pluralsight course]
Last week we created the code to add and find a “person” in our SQLite database. This week we’ll finish up by creating the View and the ViewModel.
The View is where most of the action is, in this small demo project. We’ll have two views: one to capture the information and one to display it (see figure).
Create a page named EnterPerson.xaml to capture the user name. The user interface is very simple: there is a label to indicate that we are capturing a new person’s name, two entry boxes: one for the first and one for the last name, and three buttons: one for save, one for cancel and one for review that takes you to the second page.
Working with SQLite as your database in Xamarin.Forms is not difficult but it does involve some specific steps:
- Add the SQLite-.Net PCL library to all three projects
- Create the ISQLite interface
- Add a singleton to your app class
- Open your database in the appropriate directory and use DependencyService to access it
- Create your table(s)
- Write your CRUD operations
Piece of cake.
In this and the next posting I’ll go over these steps in detail and in context.
Until now, our tests have focused on the model, Projects. The point of MVVM, however, is to enable sufficient separation of concerns to allow testing of the program’s logic in the ViewModel.
Today, we turn to ViewModel tests, using these tests both to drive the development of the ViewModel, and also to ensure the integrity and correctness of the logic as we refactor the code.