Data storage and retrieval in ios

Similar documents
Introduction to iphone Development

NSPersistentDocument Core Data Tutorial for Mac OS X v10.4. (Retired Document)

Praktikum Entwicklung von Mediensystemen mit ios

ios Application Development &

MA-WA1920: Enterprise iphone and ipad Programming

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

Event Kit Programming Guide

Beginner level: Modules 1 to 18. Advanced level: Quick review of modules 1 to 18, then following to module A Simple ios Application

Please note that this SDK will only work with Xcode or above. If you need an SDK for an older Xcode version please support.

Star Micronics Cloud Services ios SDK User's Manual

Portability Study of Android and ios

Developing Secure Mobile Apps

ios Cloud Development FOR Neal Goldstein WILEY John Wiley & Sons, Inc.

INTRODUCTION TO IOS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 13 02/22/2011

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

Tag Specification Document

An Introduction to Modern Software Development Tools Creating A Simple GUI-Based Tool Appleʼs XCode Version 3.2.6

Using the Caché Objective-C Binding

Internet services in iphone Apps. Ole Gammelgaard Poulsen

2. About iphone ios 5 Development Essentials. 5. Joining the Apple ios Developer Program

Auto-Archiving your s in Outlook

Poking a Hole in the Sandbox: Using URLs on ios

Application Programming on the Mac COSC346

Penetration Testing for iphone Applications Part 1

Dream Report Version 4.5

About This Document 3. Integration and Automation Capabilities 4. Command-Line Interface (CLI) 8. API RPC Protocol 9.

Mobile Application Development

EXPENSE TRACKER MOBILE APPLICATION. A Thesis. Presented to the. Faculty of. San Diego State University. In Partial Fulfillment

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

LAE 5.1. Windows Server Installation Guide. Version 1.0

Send from your App Part 1

Client/Server Data Synchronization in ios Development

DocAve Upgrade Guide. From Version 4.1 to 4.5

CyberSource ios SDK for Apple Pay

SQLITE C/C++ TUTORIAL

ios App Programming Guide

Key-Value Coding Programming Guide

SharePoint Wiki Redirect Installation Instruction

Leveraging Cloud Storage Through Mobile Applications Using Mezeo Cloud Storage Platform REST API. John Eastman Mezeo

Installing and configuring Microsoft Reporting Services

Using EMC Documentum with Adobe LiveCycle ES

CS3600 SYSTEMS AND NETWORKS

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

9. Database Management Utility

eggon SDK for ios 7 Integration Instructions

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

QGDocs Documentation. Release 1.0. QuantumGraph Engineers

Real Life Oracle Mobile Application Framework. Things that you don't get from the developer guide

Tutorial: ios OData Application Development with REST Services. Sybase Unwired Platform 2.2 SP04

THE NEW DIGITAL EXPERIENCE

A product of Byte Works, Inc. Credits Programming Mike Westerfield. Art Karen Bennett. Documentation Mike Westerfield

Programming in C# with Microsoft Visual Studio 2010

UltraLite C and C++ Programming

Database Programming with PL/SQL: Learning Objectives

BAM Checkout Mobile Implementation Guide for ios

BASIC IPHONE PROGRAMMING Case: Dictionary Application

ios Dev Crib Sheet In the Shadow of C

Vizit 4.1 Installation Guide

SBOP Repository Explorer. Installation and Configuration Guide v (2014)

Software Development Kit for ios and Android

Inventory Manager. Getting started Usage and general How-To

Sophos Mobile Control Installation guide. Product version: 3

DocStore: Document Database for MySQL at Facebook. Peng Tian, Tian Xia 04/14/2015

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

4D Plugin SDK v11. Another minor change, real values on 10 bytes is no longer supported.

THE NEW DIGITAL EXPERIENCE

Chapter 2 Database System Concepts and Architecture

About (EAS) Archived Service

Integrating VoltDB with Hadoop

Creating a Custom Class in Xcode

Library Recovery Center

How To Install Powerpoint 6 On A Windows Server With A Powerpoint 2.5 (Powerpoint) And Powerpoint On A Microsoft Powerpoint 4.5 Powerpoint (Powerpoints) And A Powerpoints 2

Development with Modern Mobile Technologies

ITG Software Engineering

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

Migrating Trend Micro Mobile Security for Enterprise (TMMS) 8.0 to TMMS 9.0 Patch 1

Full version is >>> HERE <<<

What s New in Security

APPLICATION SECURITY: FROM WEB TO MOBILE. DIFFERENT VECTORS AND NEW ATTACK

Designing for the Mobile Web Lesson 3: HTML5 Web Apps

Mobile Application Development

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Using the Database Management Utility to Backup, Restore and Purge the Compass 2.0 Database

โปรแกรมบ นท ก ช อ และ อ เมล โดยจ ดเก บข อม ลลงไปท SQLite

Game Center Programming Guide

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

Known Issues and Work Around

Client Requirement. Master Data Management App. Case Study -

Installing C++ compiler for CSc212 Data Structures

Keep SQL Service Running On Replica Member While Replicating Data In Realtime

Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition

Transcription:

Data storage and retrieval in ios Sebastian Ernst, PhD! Department of Applied Computer Science AGH University of Science and Technology

File structure of an ios app ios apps can store they data in files. These files are typically placed in the app s Documents folder. That folder is persistent between app launches and is deleted when the app is uninstalled. The NSSearchPathForDirectoriesInDomains foundation function can be used to find the location of the Documents folder: dirpaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);

File structure of an ios app The first result will contain the path to the folder. docsdir = dirpaths[0]; The full name can be easily concatenated: NSString *datafilepath = [NSString stringwithstring:[docsdir stringbyappendingpathcomponent: @"universities.archive"]];

Archiving Objects can be easily serialized (and deserialized) thanks to the NSKeyedArchiver and NSKeyedUnarchiver objects. [NSKeyedArchiver archiverootobject:self.unidb tofile:datafilepath];! self.unidb = [NSKeyedUnarchiver unarchiveobjectwithfile:datafilepath]; Supported data types: NSArray, NSData, NSDate, NSDictionary, NSNumber and NSString.

SQLite ios contains built-in support for SQLite. However, since SQLite support functions are in plain C, one needs to rememeber about converting proper data types (NSString to const char *, NSNumber to int, etc.). To add SQLite support to an app: link with the libsqlite3.dylib library, include sqlite3.h where appropriate.

Core Data Because of the drawbacks (pure C implementation, requirement to know SQL), ios also includes a higher-level data persistence API called Core Data. The default storage engine still SQLite, but other solutions (incl. XML and binary serialization) can also be used.

Core Data: structure source: techotopia.com

Core Data: elements Managed Objects are what the app actually interacts with. They are instances of the NSManagedObjects class or its children. The Managed Object Context is where the Managed Objects live. The context maps the objects to their counterparts in the permanent store. It acts as a buffer and persists changes only when instructed to do so.

Core Data: elements, cont d. The Managed Object Model is where the structure of data is defined. Xcode includes a GUI to manage the MOM. The model is based on entities and their attributes. Entities are linked using relationships. Fetched Properties are also used to link entities. The docs describe them as weak, one way relationships best suited to loosely coupled relationships The Persistent Store Coordinator and Persistent Object Store are low-level parts of the storage engine.

Core Data: getting the context The context can be obtained from the application delegate: coredataappdelegate *appdelegate = [[UIApplication sharedapplication]! delegate];! NSManagedObjectContext *context = [appdelegate managedobjectcontext];

Creating entity descriptions Entity descriptions are used to manipulate objects. They can be obtained using the NSEntityDescription class. NSEntityDescription *entitydesc = [NSEntityDescription! entityforname:@"contacts"! inmanagedobjectcontext:context];! NSFetchRequest *request = [[NSFetchRequest alloc] init];! [request setentity:entitydesc];

Creating managed objects NSEntityDescription also has a method to create managed objects: NSManagedObject *newcontact;! newcontact = [NSEntityDescription! insertnewobjectforentityforname:@"contacts"! inmanagedobjectcontext:context];! NSError *error;! [context save:&error];

Setting attribute values Of course, the new object still does not have attribute values. They need to be set: [newcontact setvalue:@ John Smith forkey:@"name"];! [newcontact setvalue:@ 123 The Street! forkey:@"address"];! [newcontact setvalue:@ 555-123-1234! forkey:@"phone"];

Getting attribute values Attribute values can be retrieved in a similar manner: NSString *contactname =! [newcontact valueforkey:@ name ];

Fetching objects Objects are retrieved using the fetch operation. NSFetchRequest *request = [[NSFetchRequest alloc] init];! [request setentity:entitydesc];! NSError *error;! NSArray *matching_objects =! [context executefetchrequest:request error:&error];

Fetching using criteria To fetch only objects matching certain criteria, one can use predicates, already presented in an early lecture: NSFetchRequest *request = [[NSFetchRequest alloc] init];!! [request setentity:entitydesc];! NSPredicate *pred = [NSPredicate! predicatewithformat:@"(name = %@)", John Smith ];! [request setpredicate:pred];! NSError *error;! NSArray *matching_objects = [context executefetchrequest:request error:&error]; ;

More on Core Data An ios 7 Core Data Tutorial

Getting data from the server The easiest method to get data from the server is by using RESTful APIs. The built-in methods use ansynchronous calls to retrieve data using HTTP. The connection is set up like so: NSURL *myurl = [NSURL URLWithString:@"http://www.flickr.com/ services/rest/?method=flickr.test.echo&format=json &api_key=8038f7f7d7151ccbf6df2aa10b1b35ae&nojsoncallback=1"]; NSURLRequest *myrequest = [NSURLRequest requestwithurl:myurl]; NSURLConnection *myconnection = [NSURLConnection connectionwithrequest:myrequest delegate:self]; More information: TechRepublic, ios Web Service Tutorial, https:// developer.apple.com/library/ios/documentation/cocoa/conceptual/ URLLoadingSystem/Tasks/UsingNSURLConnection.html