SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Разработка приложений
   для iPhone и iPad
      занятие #8
песочница
а что внутри?
Home Directory Layout
• Each app has its own set of directories
                              я!
• <Application Home> ельз
  !   MyApp.app            т ьн
                       е ня
       ! MyApp     -м
       ! MainWindow.nib

       ! SomeImage.png

  ! Documents - добавления здесь!
  ! Library

       ! Caches
       ! Preferences


• Applications only read and write within their home directory
• Backed up by iTunes during sync (mostly)
File Paths in Your Application
        File Paths in Your Application
         // Basic directories

                    путь к документам
         NSString *homePath = NSHomeDirectory();
         // Basic directories NSTemporaryDirectory();
         NSString *tmpPath =
         NSString *homePath = NSHomeDirectory();
         // Documents directory
         NSString *tmpPath = NSTemporaryDirectory();
         NSArray *paths = NSSearchPathForDirectoriesInDomains
                           (NSDocumentDirectory, NSUserDomainMask, YES);
         // Documents directory
         NSArray *paths = NSSearchPathForDirectoriesInDomains
         NSString *documentsPath = [paths objectAtIndex:0];
                          (NSDocumentDirectory, NSUserDomainMask, YES);
         NSString *documentsPath = [paths objectAtIndex:0];
         // <Application Home>/Documents/foo.plist
         NSString *fooPath =
         // <Application stringByAppendingPathComponent:@“foo.plist”];
         [documentsPath Home>/Documents/foo.plist
         NSString *fooPath =
         [documentsPath stringByAppendingPathComponent:@“foo.plist”];




Tuesday, February 2, 2010                                                  1

Tuesday, February 2, 2010                                             16
SQLite!

• база в файле
• нет сервера
• простая реализация
• включена в iPhone
6 шагов
• находим файл базы
• подключаемся - sqlite3_open
• создаем запрос
• готовим, проверяем - sqlite3_prepare_v2
• выполняем - sqlite3_step
• завершаем - sqlite3_finalize
• закрываем - 
 sqlite3_close
шаг 0 - создать БД
$ sqlite3 ex1
SQLite version 3.6.11
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table tbl1(one varchar(10), two smallint);
sqlite> insert into tbl1 values('hello!',10);
sqlite> insert into tbl1 values('goodbye', 20);
sqlite> select * from tbl1;
hello!|10
goodbye|20
sqlite>
подготовка
  #import <sqlite3.h>

 NSString *databaseName = @"Cocktails.sql";

 NSArray *documentPaths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES);

 NSString *documentsDir = [documentPaths objectAtIndex:0];

 NSString *databasePath = [documentsDir
stringByAppendingPathComponent:databaseName];

 BOOL success;


 NSFileManager *fileManager = [NSFileManager defaultManager];

 success = [fileManager fileExistsAtPath:databasePath];


 if(!success) {
    
 NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath]
    stringByAppendingPathComponent:databaseName];
    
 [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath
    error:nil];
    
 [fileManager release];

 }
чтение
sqlite3 *database;

 if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

 
    const char *sqlStatement = "select * from cocktail;";

 
    sqlite3_stmt *compiledStatement;


 
   if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) ==
SQLITE_OK) {


 
     
 while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

 
     
 
 int anId = sqlite3_column_int(compiledStatement, 0);

 
     
 
 NSString *aName = [NSString stringWithUTF8String:(char
*)sqlite3_column_text(compiledStatement, 1)];
         //...

 
     
 }

 
     }

 
     sqlite3_finalize(compiledStatement);

 }

 sqlite3_close(database);
запись


• просто sqlite3_step(compiledStatement),
  при удаче - SQLITE_DONE
Google
Maps API       Facebook API


              Яндекс Карты
                  API



Twitter API     общение с
              вашим сервером
xml
<?xml version="1.0" encoding="UTF-8" ?>
<painting>
 <img src="madonna.jpg" alt='Foligno Madonna, by
Raphael'/>
 <caption>This is Raphael's "Foligno" Madonna, painted in
  <date>1511</date>–<date>1512</date>.
 </caption>
</painting>
xml

   NSURL *xmlURL = [NSURL URLWithString:URL];

   NSXMLParser * rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];

   [rssParser setDelegate:self];

   [rssParser parse];


- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

- (void)parserDidEndDocument:(NSXMLParser *)parser {
What does a JSON object look like?
                                           json
                {
                      “instructor” : “Josh Shaffer”,
                      “students” : 60,
                      “itunes-u” : true,
                      “midterm-exam” : null,
                      “assignments” : [ “WhatATool”,
                                         “HelloPoly”,
                                         “Presence” ]
                }



            • NSDictionary *result = [jsonString JSONValue];
y, February 2, 2010                                     41
http://empatika.com
oleg.parinov@empatika.com

Weitere ähnliche Inhalte

Was ist angesagt?

Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring DataEric Bottard
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)Chhom Karath
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Comsysto Reply GmbH
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
Node Powered Mobile
Node Powered MobileNode Powered Mobile
Node Powered MobileTim Caswell
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHPThomas Weinert
 
Real Time Web with Node
Real Time Web with NodeReal Time Web with Node
Real Time Web with NodeTim Caswell
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedBertrand Dunogier
 
Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storagedylanks
 
Building .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase LiteBuilding .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase Litegramana
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreStephane Belkheraz
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challengervanphp
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersAmanda Gilmore
 
Persistencia de datos con Parse
Persistencia de datos con ParsePersistencia de datos con Parse
Persistencia de datos con ParseAlfonso Alba
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handlingsparkishpearl
 
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」Tsuyoshi Yamamoto
 

Was ist angesagt? (20)

Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
 
Go database/sql
Go database/sqlGo database/sql
Go database/sql
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Node Powered Mobile
Node Powered MobileNode Powered Mobile
Node Powered Mobile
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
Real Time Web with Node
Real Time Web with NodeReal Time Web with Node
Real Time Web with Node
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster Unleashed
 
Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storage
 
Building .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase LiteBuilding .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase Lite
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net Core
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
File system
File systemFile system
File system
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
 
Persistencia de datos con Parse
Persistencia de datos con ParsePersistencia de datos con Parse
Persistencia de datos con Parse
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
 
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
 

Ähnlich wie занятие8

Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Satoshi Asano
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCAWhymca
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applicationslmrei
 
Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenchesIsmail Mayat
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx FranceDavid Delabassee
 
Make BDD great again
Make BDD great againMake BDD great again
Make BDD great againYana Gusti
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLAll Things Open
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP ApplicationsPavan Kumar N
 
Apache ant
Apache antApache ant
Apache antkoniik
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WPNguyen Tuan
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applicationsjeromevdl
 
iOS: Using persistant storage
iOS: Using persistant storageiOS: Using persistant storage
iOS: Using persistant storageJussi Pohjolainen
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical StuffPetr Dvorak
 

Ähnlich wie занятие8 (20)

Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCA
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applications
 
Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenches
 
iOS5 NewStuff
iOS5 NewStuffiOS5 NewStuff
iOS5 NewStuff
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniques
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France
 
Make BDD great again
Make BDD great againMake BDD great again
Make BDD great again
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQL
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Apache ant
Apache antApache ant
Apache ant
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
 
Persistences
PersistencesPersistences
Persistences
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applications
 
Gl qtp day 3 2
Gl qtp day 3   2Gl qtp day 3   2
Gl qtp day 3 2
 
iOS: Using persistant storage
iOS: Using persistant storageiOS: Using persistant storage
iOS: Using persistant storage
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical Stuff
 
What's Parse
What's ParseWhat's Parse
What's Parse
 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
 

Mehr von Oleg Parinov

'Real agile' coaching session
'Real agile'   coaching session'Real agile'   coaching session
'Real agile' coaching sessionOleg Parinov
 
Oleg+olga product meetup
Oleg+olga product meetupOleg+olga product meetup
Oleg+olga product meetupOleg Parinov
 
[Технопарк] Управление продуктом-1
[Технопарк] Управление продуктом-1[Технопарк] Управление продуктом-1
[Технопарк] Управление продуктом-1Oleg Parinov
 
[Технопарк] Управление продуктом-2
[Технопарк] Управление продуктом-2[Технопарк] Управление продуктом-2
[Технопарк] Управление продуктом-2Oleg Parinov
 
[Технопарк] Управление продуктом-3
[Технопарк] Управление продуктом-3[Технопарк] Управление продуктом-3
[Технопарк] Управление продуктом-3Oleg Parinov
 
Управление продуктом - 5-я лекция - Технопарк@Mail.Ru
Управление продуктом - 5-я лекция - Технопарк@Mail.RuУправление продуктом - 5-я лекция - Технопарк@Mail.Ru
Управление продуктом - 5-я лекция - Технопарк@Mail.RuOleg Parinov
 
Управление продуктом - Лекция №4
Управление продуктом - Лекция №4Управление продуктом - Лекция №4
Управление продуктом - Лекция №4Oleg Parinov
 
Технопарк - Управление продуктом - Лекция №2
Технопарк - Управление продуктом - Лекция №2Технопарк - Управление продуктом - Лекция №2
Технопарк - Управление продуктом - Лекция №2Oleg Parinov
 
Лекция №2 Курса Product Management в НИУ-ВШЭ
Лекция №2 Курса Product Management в НИУ-ВШЭЛекция №2 Курса Product Management в НИУ-ВШЭ
Лекция №2 Курса Product Management в НИУ-ВШЭOleg Parinov
 
Product management - лекция №1
Product management - лекция №1Product management - лекция №1
Product management - лекция №1Oleg Parinov
 
Презентация проекта In Flow
Презентация проекта In FlowПрезентация проекта In Flow
Презентация проекта In FlowOleg Parinov
 
Pivot + Lean Startup #poSEEDelki Harvest
Pivot + Lean Startup #poSEEDelki HarvestPivot + Lean Startup #poSEEDelki Harvest
Pivot + Lean Startup #poSEEDelki HarvestOleg Parinov
 
Start-up Reality Check - Empatika в ВШЭ
Start-up Reality Check - Empatika в ВШЭStart-up Reality Check - Empatika в ВШЭ
Start-up Reality Check - Empatika в ВШЭOleg Parinov
 
Генетические алгоритмы
Генетические алгоритмыГенетические алгоритмы
Генетические алгоритмыOleg Parinov
 
Четвертое занятие курса iOS-разработки в ГУ-ВШЭ
Четвертое занятие курса iOS-разработки в ГУ-ВШЭЧетвертое занятие курса iOS-разработки в ГУ-ВШЭ
Четвертое занятие курса iOS-разработки в ГУ-ВШЭOleg Parinov
 

Mehr von Oleg Parinov (20)

'Real agile' coaching session
'Real agile'   coaching session'Real agile'   coaching session
'Real agile' coaching session
 
Oleg+olga product meetup
Oleg+olga product meetupOleg+olga product meetup
Oleg+olga product meetup
 
[Технопарк] Управление продуктом-1
[Технопарк] Управление продуктом-1[Технопарк] Управление продуктом-1
[Технопарк] Управление продуктом-1
 
[Технопарк] Управление продуктом-2
[Технопарк] Управление продуктом-2[Технопарк] Управление продуктом-2
[Технопарк] Управление продуктом-2
 
[Технопарк] Управление продуктом-3
[Технопарк] Управление продуктом-3[Технопарк] Управление продуктом-3
[Технопарк] Управление продуктом-3
 
Управление продуктом - 5-я лекция - Технопарк@Mail.Ru
Управление продуктом - 5-я лекция - Технопарк@Mail.RuУправление продуктом - 5-я лекция - Технопарк@Mail.Ru
Управление продуктом - 5-я лекция - Технопарк@Mail.Ru
 
Управление продуктом - Лекция №4
Управление продуктом - Лекция №4Управление продуктом - Лекция №4
Управление продуктом - Лекция №4
 
Технопарк - Управление продуктом - Лекция №2
Технопарк - Управление продуктом - Лекция №2Технопарк - Управление продуктом - Лекция №2
Технопарк - Управление продуктом - Лекция №2
 
Лекция №2 Курса Product Management в НИУ-ВШЭ
Лекция №2 Курса Product Management в НИУ-ВШЭЛекция №2 Курса Product Management в НИУ-ВШЭ
Лекция №2 Курса Product Management в НИУ-ВШЭ
 
Product management - лекция №1
Product management - лекция №1Product management - лекция №1
Product management - лекция №1
 
Презентация проекта In Flow
Презентация проекта In FlowПрезентация проекта In Flow
Презентация проекта In Flow
 
Pivot + Lean Startup #poSEEDelki Harvest
Pivot + Lean Startup #poSEEDelki HarvestPivot + Lean Startup #poSEEDelki Harvest
Pivot + Lean Startup #poSEEDelki Harvest
 
Instagram Design
Instagram DesignInstagram Design
Instagram Design
 
Start-up Reality Check - Empatika в ВШЭ
Start-up Reality Check - Empatika в ВШЭStart-up Reality Check - Empatika в ВШЭ
Start-up Reality Check - Empatika в ВШЭ
 
Генетические алгоритмы
Генетические алгоритмыГенетические алгоритмы
Генетические алгоритмы
 
Squeek school 2
Squeek school 2Squeek school 2
Squeek school 2
 
Squeek 1
Squeek 1Squeek 1
Squeek 1
 
занятие7
занятие7занятие7
занятие7
 
занятие6
занятие6занятие6
занятие6
 
Четвертое занятие курса iOS-разработки в ГУ-ВШЭ
Четвертое занятие курса iOS-разработки в ГУ-ВШЭЧетвертое занятие курса iOS-разработки в ГУ-ВШЭ
Четвертое занятие курса iOS-разработки в ГУ-ВШЭ
 

занятие8

  • 1. Разработка приложений для iPhone и iPad занятие #8
  • 3. а что внутри? Home Directory Layout • Each app has its own set of directories я! • <Application Home> ельз ! MyApp.app т ьн е ня ! MyApp -м ! MainWindow.nib ! SomeImage.png ! Documents - добавления здесь! ! Library ! Caches ! Preferences • Applications only read and write within their home directory • Backed up by iTunes during sync (mostly)
  • 4. File Paths in Your Application File Paths in Your Application // Basic directories путь к документам NSString *homePath = NSHomeDirectory(); // Basic directories NSTemporaryDirectory(); NSString *tmpPath = NSString *homePath = NSHomeDirectory(); // Documents directory NSString *tmpPath = NSTemporaryDirectory(); NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); // Documents directory NSArray *paths = NSSearchPathForDirectoriesInDomains NSString *documentsPath = [paths objectAtIndex:0]; (NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; // <Application Home>/Documents/foo.plist NSString *fooPath = // <Application stringByAppendingPathComponent:@“foo.plist”]; [documentsPath Home>/Documents/foo.plist NSString *fooPath = [documentsPath stringByAppendingPathComponent:@“foo.plist”]; Tuesday, February 2, 2010 1 Tuesday, February 2, 2010 16
  • 5. SQLite! • база в файле • нет сервера • простая реализация • включена в iPhone
  • 6. 6 шагов • находим файл базы • подключаемся - sqlite3_open • создаем запрос • готовим, проверяем - sqlite3_prepare_v2 • выполняем - sqlite3_step • завершаем - sqlite3_finalize • закрываем - sqlite3_close
  • 7. шаг 0 - создать БД $ sqlite3 ex1 SQLite version 3.6.11 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table tbl1(one varchar(10), two smallint); sqlite> insert into tbl1 values('hello!',10); sqlite> insert into tbl1 values('goodbye', 20); sqlite> select * from tbl1; hello!|10 goodbye|20 sqlite>
  • 8. подготовка #import <sqlite3.h> NSString *databaseName = @"Cocktails.sql"; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; success = [fileManager fileExistsAtPath:databasePath]; if(!success) { NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; [fileManager release]; }
  • 9. чтение sqlite3 *database; if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { const char *sqlStatement = "select * from cocktail;"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { while(sqlite3_step(compiledStatement) == SQLITE_ROW) { int anId = sqlite3_column_int(compiledStatement, 0); NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; //... } } sqlite3_finalize(compiledStatement); } sqlite3_close(database);
  • 11. Google Maps API Facebook API Яндекс Карты API Twitter API общение с вашим сервером
  • 12. xml <?xml version="1.0" encoding="UTF-8" ?> <painting> <img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/> <caption>This is Raphael's "Foligno" Madonna, painted in <date>1511</date>–<date>1512</date>. </caption> </painting>
  • 13. xml NSURL *xmlURL = [NSURL URLWithString:URL]; NSXMLParser * rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; [rssParser setDelegate:self]; [rssParser parse]; - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string - (void)parserDidEndDocument:(NSXMLParser *)parser {
  • 14. What does a JSON object look like? json { “instructor” : “Josh Shaffer”, “students” : 60, “itunes-u” : true, “midterm-exam” : null, “assignments” : [ “WhatATool”, “HelloPoly”, “Presence” ] } • NSDictionary *result = [jsonString JSONValue]; y, February 2, 2010 41

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n