{"id":812,"date":"2010-12-13T15:34:28","date_gmt":"2010-12-13T06:34:28","guid":{"rendered":"http:\/\/yamazon.org\/?p=812"},"modified":"2010-12-13T15:34:28","modified_gmt":"2010-12-13T06:34:28","slug":"8sqlite%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6todo%e3%83%aa%e3%82%b9%e3%83%88%e3%82%a2%e3%83%97%e3%83%aa%e3%82%92%e4%bd%9c%e6%88%904","status":"publish","type":"post","link":"https:\/\/apr20.net\/?p=812","title":{"rendered":"[9]:SQLite\u3092\u4f7f\u3063\u3066ToDo\u30ea\u30b9\u30c8\u30a2\u30d7\u30ea\u3092\u4f5c\u6210(4)"},"content":{"rendered":"<p>\u4eca\u56de\u304cTodo\u30ea\u30b9\u30c8\u306e\u6700\u5f8c\u306b\u306a\u308a\u307e\u3059\u3002SQLite\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u3001todo\u30a2\u30a4\u30c6\u30e0\u3092\u8ffd\u52a0\u30fb\u7de8\u96c6\u304a\u3088\u3073\u3001\u524a\u9664\u3059\u308b\u8a73\u7d30\u306b\u3064\u3044\u3066\u6271\u3063\u3066\u884c\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\uff13\u3064\u306e\u8a18\u4e8b\u3092\u65e2\u306b\u8aad\u307e\u308c\u3066\u3044\u308b\u65b9\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u307e\u3060\u306e\u304b\u305f\u306f\u3001\u5148\u306b\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<ul style=\"padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; margin: 0px;\">\n<li style=\"padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; list-style-position: inside; margin: 0px;\"><a style=\"color: #2970a6; text-decoration: none;\" href=\"http:\/\/yamazon.org\/iphone-app-develop-tips\/681\">[6]:SQLite\u3092\u4f7f\u3063\u3066ToDo\u30ea\u30b9\u30c8\u30a2\u30d7\u30ea\u3092\u4f5c\u6210(1)<\/a><\/li>\n<li style=\"padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; list-style-position: inside; margin: 0px;\"><a style=\"color: #2970a6; text-decoration: none;\" href=\"http:\/\/yamazon.org\/iphone-app-develop-tips\/681\"><\/a><a style=\"color: #2970a6; text-decoration: none;\" href=\"http:\/\/yamazon.org\/iphone-app-develop-tips\/703\">[7]:SQLite\u3092\u4f7f\u3063\u3066ToDo\u30ea\u30b9\u30c8\u30a2\u30d7\u30ea\u3092\u4f5c\u6210(2)<\/a><\/li>\n<li style=\"padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; list-style-position: inside; margin: 0px;\"><a style=\"color: #2970a6; text-decoration: none;\" href=\"http:\/\/yamazon.org\/iphone-app-develop-tips\/tutorial\/792\">[8]:SQLite\u3092\u4f7f\u3063\u3066ToDo\u30ea\u30b9\u30c8\u30a2\u30d7\u30ea\u3092\u4f5c\u6210(3)<\/a><\/li>\n<\/ul>\n<p><!--more-->\u3067\u306f\u3001\u306f\u3058\u3081\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001\u7de8\u96c6\u3001\u65b0\u898f\u8ffd\u52a0\u306e\u305f\u3081\u306e\u30dc\u30bf\u30f3\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001UIBarButtonItem \u306e\u90e8\u54c1\u3092NavigationBar \u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>RootViewController.m<\/strong>\u3092\u958b\u304d\u3001<strong>viewDidLoad <\/strong>\u30e1\u30bd\u30c3\u30c9\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">void<\/span>)viewDidLoad {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">self<\/span>.title = <span style=\"color: #d12e1b;\">@&#8221;Todo <\/span><span style=\"font: 11.0px 'Hiragino Kaku Gothic ProN'; color: #d12e1b;\">\u30ea\u30b9\u30c8<\/span><span style=\"color: #d12e1b;\">&#8220;<\/span>;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">self<\/span>.navigationItem.leftBarButtonItem = <span style=\"color: #bb2da2;\">self<\/span>.editButtonItem;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>UIBarButtonItem * btn = [[UIBarButtonItem alloc] initWithTitle:<span style=\"color: #d12e1b;\">@&#8221;Add&#8221;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span> style:UIBarButtonItemStyleBordered<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span> target:<span style=\"color: #bb2da2;\">self<\/span> action:<span style=\"color: #bb2da2;\">@selector<\/span>(<span style=\"color: #31595e;\">addTodo<\/span>:)];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">self<\/span>.navigationItem.rightBarButtonItem = btn;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u8ffd\u52a0\u3057\u305f\u6700\u521d\u306e\u884c\u306f\u3001leftBarButtonItem \u3092 self.editButtonItem \u306b\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3067\u3001\u81ea\u52d5\u7684\u306b&#8221;\u7de8\u96c6&#8221;\u30dc\u30bf\u30f3\u304c\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u306b\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002\u540c\u6642\u306b\u3001\u201d\u7de8\u96c6\u201d\u30dc\u30bf\u30f3\u304c\u62bc\u3055\u308c\u305f\u6642\u306b\u3001\u201d\u524a\u9664\u201d\u30dc\u30bf\u30f3\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u72b6\u614b\u3067\u3001\u4e00\u5ea6\u3001\u30d3\u30eb\u30c9\uff06\u5b9f\u884c\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\u4ee5\u4e0b\u306e\u753b\u9762\u306e\u3088\u3046\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-814\" title=\"812-1\" src=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-1-160x300.png\" alt=\"812-1\" width=\"160\" height=\"300\" \/><\/a><\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u8aac\u660e\u306b\u623b\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u6b21\u306b\u3001\u624b\u52d5\u3067\u3001UIBarButtonItem\u3092\u4f5c\u6210\u3057\u3001\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u4f5c\u696d\u306fInterface Builder\u3067\u5b8c\u7d50\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u307e\u3059\u304c\u3001\u3053\u3053\u3067\u306f\u3001\u4f5c\u6210\u304b\u3089\u3001\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u5272\u308a\u5f53\u3066\u308b\u3068\u3053\u308d\u307e\u3067\u624b\u52d5\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n<ul style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 22px; margin-left: 2.5em; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; list-style-type: disc; list-style-position: initial; list-style-image: initial; text-align: left; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;\">\n<li style=\"outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;\">initWithTitle \u2013 \u30dc\u30bf\u30f3\u306b\u8868\u793a\u3055\u308c\u308b\u30bf\u30a4\u30c8\u30eb\u3067\u3059\u3002<\/li>\n<li style=\"outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;\">style \u2013 \u30dc\u30bf\u30f3\u306e\u898b\u305f\u76ee\u3067\u3059\u3002<\/li>\n<li style=\"outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;\">target \u2013 \u3053\u306e\u30dc\u30bf\u30f3\u304b\u3089\u9001\u3089\u308c\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u30cf\u30f3\u30c9\u30eb\u30af\u30e9\u30b9\u3067\u3059\u3002<\/li>\n<li style=\"outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;\">action \u2013 \u30dc\u30bf\u30f3\u304c\u62bc\u3055\u308c\u305f\u6642\u306b\u547c\u3070\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002@selector \u3092\u4f7f\u3044\u3001\u547c\u3073\u3060\u3059\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u540d\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>\u6700\u5f8c\u306b\u3001rightBarButtonItem \u306b\u3053\u306e\u30dc\u30bf\u30f3\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u72b6\u614b\u3067\u306f\u3001\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u306b\u30dc\u30bf\u30f3\u3092\u8ffd\u52a0\u3057\u305f\u3060\u3051\u3067\u3059\u306e\u3067\u3001\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u6642\u306e\u30a2\u30af\u30b7\u30e7\u30f3\u306f\u672a\u8a2d\u5b9a\u3067\u3059\u3002\u306a\u306e\u3067\u3001\u3053\u306e\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001Todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5185\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>Todo.h<\/strong>\u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">void<\/span>)deleteFromDatabase;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">+ (NSInteger)insertNewTodoIntoDatabase:(sqlite3 *)<span style=\"color: #4e8187;\">database<\/span>;<\/p>\n<\/blockquote>\n<p><strong>insertNewTodoIntoDatabase<\/strong>\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u540c\u6642\u306b\u3001deleteFromDatabase\u3082\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u306d\u3002\u3053\u308c\u306b\u3064\u3044\u3066\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u306e\u30c7\u30fc\u30bf\u306e\u524a\u9664\u3092\u6271\u3046\u6642\u306b\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p><strong>insertNewTodoIntoDatabase<\/strong>\u30e1\u30bd\u30c3\u30c9\u306e\u5148\u982d\u306b\u3064\u3044\u3066\u3044\u308b\u201d\uff0b\u201d\u306f\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u306a\u304f\u3001\u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9\u3092\u8868\u3057\u3066\u3044\u307e\u3059\u3002\u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9\u306a\u306e\u3067\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u305b\u305a\u306b\u3001\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3059\u308b\u524d\u306b\u3001\u9759\u7684\u306asqlite3_statement \u3092\u3044\u304f\u3064\u304b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>Todo.m <\/strong>\u306b\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">static<\/span> sqlite3_stmt *delete_statment = <span style=\"color: #bb2da2;\">nil<\/span>;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">static<\/span> sqlite3_stmt *insert_statement = <span style=\"color: #bb2da2;\">nil<\/span>;<\/p>\n<\/blockquote>\n<p>\u305d\u308c\u3067\u306f\u3001<strong>insertNewTodoIntoDatabase<\/strong>\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">+ (NSInteger)insertNewTodoIntoDatabase:(sqlite3 *)<span style=\"color: #4e8187;\">database<\/span> {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"> <\/span><span style=\"color: #bb2da2;\">if<\/span><span style=\"color: #000000;\"> (<\/span>insert_statement<span style=\"color: #000000;\"> == <\/span><span style=\"color: #bb2da2;\">nil<\/span><span style=\"color: #000000;\">) {<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"> <\/span><span style=\"color: #bb2da2;\">static<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #bb2da2;\">char<\/span><span style=\"color: #000000;\"> *sql = <\/span>&#8220;INSERT INTO todo (text,priority,complete) VALUES(&#8216;\u65b0\u898f\u30a2\u30a4\u30c6\u30e0&#8217;,&#8217;3&#8242;,&#8217;0&#8242;)&#8221;<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">if<\/span> (sqlite3_prepare_v2(<span style=\"color: #4e8187;\">database<\/span>, sql, &#8211;<span style=\"color: #252bd8;\">1<\/span>, &amp;<span style=\"color: #4e8187;\">insert_statement<\/span>, <span style=\"color: #bb2da2;\">NULL<\/span>) != SQLITE_OK) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"> NSAssert1(<\/span><span style=\"color: #252bd8;\">0<\/span><span style=\"color: #000000;\">, <\/span>@&#8221;Error: failed to prepare statement with message &#8216;%s&#8217;.&#8221;<span style=\"color: #000000;\">, sqlite3_errmsg(<\/span><span style=\"color: #4e8187;\">database<\/span><span style=\"color: #000000;\">));<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">int<\/span> success = sqlite3_step(<span style=\"color: #4e8187;\">insert_statement<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">sqlite3_reset(<span style=\"color: #4e8187;\">insert_statement<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">if<\/span> (success != SQLITE_ERROR) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">return<\/span> sqlite3_last_insert_rowid(<span style=\"color: #4e8187;\">database<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"> NSAssert1(<\/span><span style=\"color: #252bd8;\">0<\/span><span style=\"color: #000000;\">, <\/span>@&#8221;Error: failed to insert into the database with message &#8216;%s&#8217;.&#8221;<span style=\"color: #000000;\">, sqlite3_errmsg(<\/span><span style=\"color: #4e8187;\">database<\/span><span style=\"color: #000000;\">));<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">return<\/span> &#8211;<span style=\"color: #252bd8;\">1<\/span>;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u66f4\u65b0\u3059\u308b\u6642\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u4f3c\u3066\u3044\u307e\u3059\u306d\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u633f\u5165\u3057\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u3001null\u3084nil\u3092\u542b\u3080\u30c8\u30e9\u30d6\u30eb\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u6700\u3082\u5927\u5207\u306a\u3053\u3068\u306f\u3001\u65b0\u3057\u304f\u4f5c\u6210\u3055\u308c\u305ftodo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30e9\u30a4\u30de\u30ea\u30fc\u30ad\u30fc\u3092\u8fd4\u3059\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001\u201dAdd\u201d\u30dc\u30bf\u30f3\u304c\u62bc\u3055\u308c\u305f\u6642\u306b\u3001\u5373\u5ea7\u306btodo\u306b\u5909\u9077\u3059\u308b\u305f\u3081\u306b\u3001\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n<p>todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5bfe\u3057\u3066\u884c\u3046\u6700\u5f8c\u306e\u4f5c\u696d\u306f\u3001todo\u30c6\u30ad\u30b9\u30c8\u304c\u5909\u66f4\u3055\u308c\u305f\u6642\u306b\u4fdd\u5b58\u3055\u308c\u308b\u3088\u3046\u306bdehydrate\u30e1\u30bd\u30c3\u30c9\u3092\u66f4\u65b0\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>dehydrate\u30e1\u30bd\u30c3\u30c9\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">void<\/span>) dehydrate {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">if<\/span>(<span style=\"color: #4e8187;\">dirty<\/span>) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">if<\/span><span style=\"color: #000000;\"> (<\/span>dehydrate_statment<span style=\"color: #000000;\"> == <\/span><span style=\"color: #bb2da2;\">nil<\/span><span style=\"color: #000000;\">) {<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #bb2da2;\">char<\/span><span style=\"color: #000000;\"> *sql = <\/span>&#8220;UPDATE todo SET text = ? , priority = ?,complete = ? WHERE pk=?&#8221;<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">if<\/span> (sqlite3_prepare_v2(<span style=\"color: #4e8187;\">database<\/span>, sql, &#8211;<span style=\"color: #252bd8;\">1<\/span>, &amp;<span style=\"color: #4e8187;\">dehydrate_statment<\/span>, <span style=\"color: #bb2da2;\">NULL<\/span>) != SQLITE_OK) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #78492a;\">NSAssert1<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #252bd8;\">0<\/span><span style=\"color: #000000;\">, <\/span>@&#8221;Error: failed to prepare statement with message &#8216;%s&#8217;.&#8221;<span style=\"color: #000000;\">, sqlite3_errmsg(<\/span><span style=\"color: #4e8187;\">database<\/span><span style=\"color: #000000;\">));<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span>sqlite3_bind_int(<\/span>dehydrate_statment<span style=\"color: #000000;\">, <\/span><span style=\"color: #252bd8;\">4<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>primaryKey<span style=\"color: #000000;\">);<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>sqlite3_bind_int(<span style=\"color: #4e8187;\">dehydrate_statment<\/span>, <span style=\"color: #252bd8;\">3<\/span>, <span style=\"color: #bb2da2;\">self<\/span>.<span style=\"color: #4e8187;\">status<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>sqlite3_bind_int(<span style=\"color: #4e8187;\">dehydrate_statment<\/span>, <span style=\"color: #252bd8;\">2<\/span>, <span style=\"color: #bb2da2;\">self<\/span>.<span style=\"color: #4e8187;\">priority<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>sqlite3_bind_text(<span style=\"color: #4e8187;\">dehydrate_statment<\/span>, <span style=\"color: #252bd8;\">1<\/span>, [<span style=\"color: #bb2da2;\">self<\/span>.<span style=\"color: #4e8187;\">text<\/span> <span style=\"color: #3d1e81;\">UTF8String<\/span>], &#8211;<span style=\"color: #252bd8;\">1<\/span>, SQLITE_TRANSIENT);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">int<\/span> success = sqlite3_step(<span style=\"color: #4e8187;\">dehydrate_statment<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">if<\/span> (success != SQLITE_DONE) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #78492a;\">NSAssert1<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #252bd8;\">0<\/span><span style=\"color: #000000;\">, <\/span>@&#8221;Error: failed to save priority with message &#8216;%s&#8217;.&#8221;<span style=\"color: #000000;\">, sqlite3_errmsg(<\/span><span style=\"color: #4e8187;\">database<\/span><span style=\"color: #000000;\">));<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>sqlite3_reset(<span style=\"color: #4e8187;\">dehydrate_statment<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #4e8187;\">dirty<\/span> = <span style=\"color: #bb2da2;\">NO<\/span>;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u7d30\u304b\u3044\u5909\u66f4\u304c\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u3002\u307e\u305a\u3001\u201ctext = ?\u201d\u3068\u3044\u3046\u8a18\u8ff0\u304csql\u6587\u306b\u8ffd\u52a0\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u5358\u7d14\u306btodo\u30c6\u30ad\u30b9\u30c8\u3092\u66f4\u65b0\u3059\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u4ed6\u306e\u5909\u66f4\u70b9\u3068\u3057\u3066\u3001self.text property \u3092sql\u6587\u5185\u306e\u6700\u521d\u306e\u201d\uff1f\u201d\u306b\u95a2\u9023\u3065\u3051\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>[self.text UTF8String] \u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u306f\u3001sqlite3_bind_text\u304c\u3001char\u578b\u3092\u3068\u308b\u306e\u3067\u3001NSString \u3092\u8a31\u5bb9\u53ef\u80fd\u306a\u5f62\u5f0f\u306b\u5909\u63db\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>todo\u3092\u8ffd\u52a0\u3059\u308b\u305f\u3081\u306b\u3001RootViewController\u5185\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u304c\u3001&#8221;Add&#8221;\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u6642\u306b\u547c\u3070\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n<p><strong>RootViewController.m<\/strong> \u5185\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">void<\/span>) addTodo:(<span style=\"color: #bb2da2;\">id<\/span>)sender {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #4e8187;\">todoAppDelegate<\/span> *appDelegate = (<span style=\"color: #4e8187;\">todoAppDelegate<\/span> *)[[<span style=\"color: #703daa;\">UIApplication<\/span> <span style=\"color: #3d1e81;\">sharedApplication<\/span>] delegate];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">if<\/span>(<span style=\"color: #bb2da2;\">self<\/span>.<span style=\"color: #4e8187;\">todoView<\/span> == <span style=\"color: #bb2da2;\">nil<\/span>) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span>TodoViewController<span style=\"color: #000000;\"> *viewController = [[<\/span>TodoViewController<span style=\"color: #000000;\"> <\/span><span style=\"color: #3d1e81;\">alloc<\/span><span style=\"color: #000000;\">] <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span> <span style=\"color: #31595e;\">initWithNibName<\/span>:<span style=\"color: #d12e1b;\">@&#8221;TodoViewController&#8221;<\/span> <span style=\"color: #31595e;\">bundle<\/span>:[<span style=\"color: #703daa;\">NSBundle<\/span> <span style=\"color: #3d1e81;\">mainBundle<\/span>]];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">self<\/span>.<span style=\"color: #4e8187;\">todoView<\/span> = viewController;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>[viewController <span style=\"color: #3d1e81;\">release<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #4e8187;\">Todo<\/span> *<span style=\"color: #4e8187;\">todo<\/span> = [appDelegate <span style=\"color: #31595e;\">addTodo<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span>[<\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>navigationController<span style=\"color: #000000;\"> <\/span><span style=\"color: #3d1e81;\">pushViewController<\/span><span style=\"color: #000000;\">:<\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>todoView<span style=\"color: #000000;\"> <\/span><span style=\"color: #3d1e81;\">animated<\/span><span style=\"color: #000000;\">:<\/span><span style=\"color: #bb2da2;\">YES<\/span><span style=\"color: #000000;\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>todoView<span style=\"color: #000000;\">.<\/span>todo<span style=\"color: #000000;\"> = <\/span>todo<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>todoView<span style=\"color: #000000;\">.<\/span><span style=\"color: #703daa;\">title<\/span><span style=\"color: #000000;\"> = <\/span>todo<span style=\"color: #000000;\">.<\/span>text<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span>[<\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>todoView<span style=\"color: #000000;\">.<\/span>todoText<span style=\"color: #000000;\"> <\/span><span style=\"color: #31595e;\">setText<\/span><span style=\"color: #000000;\">:<\/span>todo<span style=\"color: #000000;\">.<\/span><span style=\"color: #31595e;\">text<\/span><span style=\"color: #000000;\">];<span style=\"white-space: pre;\"> <\/span><\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u307e\u305a\u3001appDelegate \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u53c2\u7167\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002\u7406\u7531\u3068\u3057\u3066\u306f\u3001\u305d\u308c\u81ea\u8eab\u306eaddTodo \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u5fc5\u8981\u304c\u3042\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001TodoViewController \u304c\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u51e6\u7406\u304c\u5fc5\u8981\u306a\u7406\u7531\u306f\u3001\u65b0\u3057\u3044todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u305f\u5f8c\u306b\u3001view\u3092\u5909\u9077\u3055\u305b\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001appDelegate \u306e\u00a0addTodo \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u307e\u3059\u3002\u305d\u308c\u306f\u3001\u65b0\u3057\u3044todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u3001todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u8a73\u7d30\u3092\u7de8\u96c6\u3059\u308b\u305f\u3081\u306b\u3001\u8a73\u7d30\u60c5\u5831\u753b\u9762\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n<p>appDelegate \u5185\u306baddTodo \u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong>todoAppDelegate.h<\/strong> \u3092\u958b\u3044\u3066\u3001\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">-(<span style=\"color: #4e8187;\">Todo<\/span> *)addTodo;<\/p>\n<\/blockquote>\n<p><strong>todoAppDelegate.m<\/strong> \u3078\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">-(<span style=\"color: #4e8187;\">Todo<\/span> *) addTodo {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #31595e;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #703daa;\">NSInteger<\/span><span style=\"color: #000000;\"> primaryKey = [<\/span><span style=\"color: #4e8187;\">Todo<\/span><span style=\"color: #000000;\"> <\/span>insertNewTodoIntoDatabase<span style=\"color: #000000;\">:<\/span><span style=\"color: #4e8187;\">database<\/span><span style=\"color: #000000;\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #4e8187;\">Todo<\/span> *newTodo = [[<span style=\"color: #4e8187;\">Todo<\/span> <span style=\"color: #3d1e81;\">alloc<\/span>] <span style=\"color: #31595e;\">initWithPrimaryKey<\/span>:primaryKey <span style=\"color: #31595e;\">database<\/span>:<span style=\"color: #4e8187;\">database<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>[<span style=\"color: #4e8187;\">todos<\/span> <span style=\"color: #3d1e81;\">addObject<\/span>:newTodo];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">return<\/span> newTodo;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u307e\u305a\u3001Todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306einsertNewTodoIntoDatabase \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002\u6ce8\u76ee\u3059\u3079\u304d\u306f\u3001todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306a\u304f\u3001\u5358\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u70b9\u3067\u3059\u3002\u3053\u308c\u306f\u3001\u65e2\u306b\u89e6\u308c\u307e\u3057\u305f\u304c\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u9759\u7684\u3067\u3001\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u305b\u305a\u306b\u547c\u3070\u308c\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001initWithPrimaryKey \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3076\u3053\u3068\u3067\u3001todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u65b0\u3057\u3044todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u53c2\u7167\u3092\u5f97\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001\u3053\u306etodo\u30a2\u30a4\u30c6\u30e0\u3092\u3001\u65e2\u5b58\u306etodo\u914d\u5217\u306e\u6700\u5f8c\u306b\u3001\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>UITableView \u306f\u3001\u3053\u306e\u914d\u5217\u306b\u3088\u3063\u3066\u66f4\u65b0\u3055\u308c\u308b\u306e\u3067\u3001\u81ea\u52d5\u7684\u306b\u3001\u65b0\u3057\u3044todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3082\u542b\u307e\u308c\u307e\u3059\u3002\u6700\u5f8c\u306e\u884c\u306f\u3001\u3053\u306etodo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u524d\u56de\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u3001status\u3068priority\u304c\u66f4\u65b0\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u540c\u3058\u3088\u3046\u306b\u3001todo\u306e\u30c6\u30ad\u30b9\u30c8\u3082\u66f4\u65b0\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>TodoViewController.h<\/strong> \u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #78492a;\">#import <\/span>&lt;UIKit\/UIKit.h&gt;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #78492a;\">#import <span style=\"color: #d12e1b;\">&#8220;Todo.h&#8221;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">@interface<\/span> TodoViewController : UIViewController {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">IBOutlet<\/span><span style=\"color: #000000;\"> <\/span>UITextField<span style=\"color: #000000;\"> *<\/span>todoText<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">IBOutlet<\/span><span style=\"color: #000000;\"> <\/span>UISegmentedControl<span style=\"color: #000000;\"> *<\/span>todoPriority<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">IBOutlet<\/span><span style=\"color: #000000;\"> <\/span>UILabel<span style=\"color: #000000;\"> *<\/span>todoStatus<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">IBOutlet<\/span><span style=\"color: #000000;\"> <\/span>UIButton<span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span>*<\/span>todoButton<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #4e8187;\">Todo<\/span><span style=\"white-space: pre;\"> <\/span>*<span style=\"color: #4e8187;\">todo<\/span>;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">@property<\/span>(<span style=\"color: #bb2da2;\">nonatomic<\/span>,<span style=\"color: #bb2da2;\">retain<\/span>) <span style=\"color: #bb2da2;\">IBOutlet<\/span> UITextField\u00a0 \u00a0 \u00a0 \u00a0 *todoText;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">@property<\/span>(<span style=\"color: #bb2da2;\">nonatomic<\/span>,<span style=\"color: #bb2da2;\">retain<\/span>) <span style=\"color: #bb2da2;\">IBOutlet<\/span> UISegmentedControl *todoPriority;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">@property<\/span>(<span style=\"color: #bb2da2;\">nonatomic<\/span>,<span style=\"color: #bb2da2;\">retain<\/span>) <span style=\"color: #bb2da2;\">IBOutlet<\/span> UILabel\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 *todoStatus;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">@property<\/span>(<span style=\"color: #bb2da2;\">nonatomic<\/span>,<span style=\"color: #bb2da2;\">retain<\/span>) <span style=\"color: #bb2da2;\">IBOutlet<\/span> UIButton \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 *todoButton;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bb2da2;\">@property<span style=\"color: #000000;\">(<\/span>nonatomic<span style=\"color: #000000;\">,<\/span>retain<span style=\"color: #000000;\">) Todo<span style=\"white-space: pre;\"> <\/span>*todo;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">IBAction<\/span>) updateStatus:(<span style=\"color: #bb2da2;\">id<\/span>) sender;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">IBAction<\/span>) updatePriority:(<span style=\"color: #bb2da2;\">id<\/span>) sender;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">IBAction<\/span>) updateText:(<span style=\"color: #bb2da2;\">id<\/span>) sender;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bb2da2;\">@end<\/p>\n<\/blockquote>\n<p>todoText \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u305f\u3081\u306eUITextView\u304c\u306a\u305cUITextField\u306b\u5909\u308f\u308a\u307e\u3057\u305f\u306d\u3002\u306a\u305c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u7406\u7531\u306f\u3001 UITextView\u306b\u306f\u3001\u79c1\u305f\u3061\u306e\u73fe\u5728\u306e\u30c7\u30b6\u30a4\u30f3\u3067\u30c6\u30ad\u30b9\u30c8\u3092\u4fdd\u5b58\u3059\u308b\u306e\u306b\u5fc5\u8981\u306a\u30e1\u30bd\u30c3\u30c9\u304c\u306a\u3044\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u5f8c\u3067\u3001Interface Builder \u5185\u3067\u3082\u3053\u306e\u7b87\u6240\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u8ffd\u52a0\u3057\u305f\u30e1\u30bd\u30c3\u30c9\u306f\u3001updateText \u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u3053\u306eIBAction \u306f\u30e6\u30fc\u30b6\u304c\u3001todo\u30c6\u30ad\u30b9\u30c8\u3092\u8a2d\u5b9a\u3057\u305f\u5f8c\u306b\u3001\u30ad\u30fc\u30dc\u30fc\u30c9\u306e\u201dDone\u201d\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u6642\u306b\u547c\u3070\u308c\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>TodoViewController.m<\/strong> \u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">IBAction<\/span>) updateText:(<span style=\"color: #bb2da2;\">id<\/span>) sender {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>todo<span style=\"color: #000000;\">.<\/span>text<span style=\"color: #000000;\"> = <\/span><span style=\"color: #bb2da2;\">self<\/span><span style=\"color: #000000;\">.<\/span>todoText<span style=\"color: #000000;\">.<\/span>text<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u3053\u308c\u304c\u884c\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001todo\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u3001UITextField \u5185\u3067\u30e6\u30fc\u30b6\u304c\u5165\u529b\u3057\u305f\u30c6\u30ad\u30b9\u30c8\u3078\u66f4\u65b0\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u6b21\u306b\u3001UITextView \u3092 UITextField \u306b\u7f6e\u304d\u63db\u3048\u3001updateText \u30e1\u30bd\u30c3\u30c9\u3068\u63a5\u7d9a\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>TodoViewController.xib \u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30d6\u30eb\u30af\u30ea\u30c3\u30af\u3057\u3001Interface Builder \u3092\u8d77\u52d5\u3057\u307e\u3059\u3002\u8d77\u52d5\u3057\u305f\u3089\u3001\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u4e0a\u306eUITextView \u3092\u30af\u30ea\u30c3\u30af\u3057\u3001\u524a\u9664\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u30e9\u30a4\u30d6\u30e9\u30ea\u304b\u3089\u3001UITextField \u3092\u30c9\u30e9\u30c3\u30b0\u3057\u3001\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306b\u914d\u7f6e\u3057\u307e\u3059\u3002\u9069\u5f53\u306b\u30b5\u30a4\u30ba\u8abf\u6574\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-815\" title=\"812-2\" src=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-2-198x300.png\" alt=\"812-2\" width=\"198\" height=\"300\" \/><\/a>\u914d\u7f6e\u3057\u305f\u3060\u3051\u3067\u306f\u3001\u52d5\u4f5c\u3057\u306a\u3044\u306e\u3067\u3001\u63a5\u7d9a\u3057\u307e\u3059\u3002<\/p>\n<p>Tool &gt; Connections Inspector \u3092\u30af\u30ea\u30c3\u30af\u3057\u3001Connections Inspector \u3092\u958b\u304d\u307e\u3059\u3002<\/p>\n<p>\u201dDid End On Exit\u201d \u306e\u6a2a\u306e\u25cb\u3092File&#8217;s Owner \u4e0a\u3078\u30c9\u30e9\u30c3\u30b0\u3057\u307e\u3059\u3002\u300cudpateText\u300d \u304c\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u3055\u308c\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u3001\u63a5\u7d9a\u3057\u307e\u3059\u3002(udpateText \u304c\u8868\u793a\u3055\u308c\u306a\u3044\u5834\u5408\u306f\u3001XCode\u4e0a\u306e\u5909\u66f4\u304c\u5168\u3066\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002)<\/p>\n<p>\u6b21\u306b\u3001\u201cNew Referencing Outlet\u201d \u306e\u6a2a\u306e\u25cb\u3092File&#8217;s Owner \u4e0a\u3078\u30c9\u30e9\u30c3\u30b0\u3057\u307e\u3059\u3002\u300ctodoText\u300d\u304c\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u3055\u308c\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u9078\u629e\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u753b\u50cf\u306e\u3088\u3046\u306b\u306a\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-816\" title=\"812-3\" src=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-3-131x300.png\" alt=\"812-3\" width=\"131\" height=\"300\" \/><\/a>\u3053\u308c\u3092\u4fdd\u5b58\u3057\u3066\u3001Interface Builder \u306f\u7d42\u4e86\u3057\u307e\u3059\u3002\u3053\u308c\u3067\u3001todo\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3059\u3079\u304d\u3053\u3068\u306f\u3001todo \u3092\u30ea\u30b9\u30c8\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u524a\u9664\u3059\u308b\u6a5f\u80fd\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u306fInterface Builder\u3092\u4f7f\u308f\u305a\u3001XCode\u4e0a\u306e\u307f\u3067\u5b8c\u4e86\u3057\u307e\u3059\u3002<\/p>\n<p>appDelegate \u306b\u3001todo\u524a\u9664\u3092\u6271\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<strong>todoAppDelegate.h<\/strong> \u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">-(<span style=\"color: #bb2da2;\">void<\/span>)removeTodo:(<span style=\"color: #4e8187;\">Todo<\/span> *)<span style=\"color: #4e8187;\">todo<\/span>;<\/p>\n<\/blockquote>\n<p>removeTodo \u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u4ee5\u4e0b\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u6587\u3082\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #78492a;\">#import <span style=\"color: #d12e1b;\">&#8220;Todo.h&#8221;<\/span><\/p>\n<\/blockquote>\n<p>\u3053\u308c\u3067\u3001todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6271\u3046\u3053\u3068\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001removeTodo \u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong>todoAppDelegate.m<\/strong> \u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">-(<span style=\"color: #bb2da2;\">void<\/span>)removeTodo:(<span style=\"color: #4e8187;\">Todo<\/span> *)<span style=\"color: #4e8187;\">todo<\/span> {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #703daa;\">NSUInteger<\/span> index = [<span style=\"color: #4e8187;\">todos<\/span> <span style=\"color: #3d1e81;\">indexOfObject<\/span>:<span style=\"color: #4e8187;\">todo<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"color: #bb2da2;\">if<\/span> (index == <span style=\"color: #3d1e81;\">NSNotFound<\/span>) <span style=\"color: #bb2da2;\">return<\/span>;<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #31595e;\"><span style=\"color: #000000;\"> [<\/span><span style=\"color: #4e8187;\">todo<\/span><span style=\"color: #000000;\"> <\/span>deleteFromDatabase<span style=\"color: #000000;\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1e81;\"><span style=\"color: #000000;\"> [<\/span><span style=\"color: #4e8187;\">todos<\/span><span style=\"color: #000000;\"> <\/span>removeObject<span style=\"color: #000000;\">:<\/span><span style=\"color: #4e8187;\">todo<\/span><span style=\"color: #000000;\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u6700\u521d\u306e\u884c\u306f\u3001todo\u306eNSArray\u914d\u5217\u3092\u691c\u7d22\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u524a\u9664\u3055\u308c\u308btodo\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001deleteFromDatabase \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3093\u3067\u3001\u8a72\u5f53\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092todo\u914d\u5217\u304b\u3089\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<p>UITableView\u306f\u3001\u3053\u306e\u914d\u5217\u3092\u4ecb\u3057\u3066\u66f4\u65b0\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u7279\u5225\u306a\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u306a\u304f\u3001\u81ea\u52d5\u7684\u306b\u3001ToDo\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<p>todo\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bremoveTodo \u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>Todo.h<\/strong> \u306b\u65e2\u306b\u30e1\u30bd\u30c3\u30c9\u306e\u5ba3\u8a00\u306f\u3057\u3066\u3044\u308b\u306e\u3067\u3001<strong>Todo.m<\/strong> \u3092\u958b\u3044\u3066\u3001\u30b3\u30fc\u30c9\u3092\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">-(<span style=\"color: #bb2da2;\">void<\/span>) deleteFromDatabase {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8187;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">if<\/span><span style=\"color: #000000;\"> (<\/span>delete_statment<span style=\"color: #000000;\"> == <\/span><span style=\"color: #bb2da2;\">nil<\/span><span style=\"color: #000000;\">) {<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #bb2da2;\">char<\/span><span style=\"color: #000000;\"> *sql = <\/span>&#8220;DELETE FROM todo WHERE pk=?&#8221;<span style=\"color: #000000;\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">if<\/span> (sqlite3_prepare_v2(<span style=\"color: #4e8187;\">database<\/span>, sql, &#8211;<span style=\"color: #252bd8;\">1<\/span>, &amp;<span style=\"color: #4e8187;\">delete_statment<\/span>, <span style=\"color: #bb2da2;\">NULL<\/span>) != SQLITE_OK) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #78492a;\">NSAssert1<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #252bd8;\">0<\/span><span style=\"color: #000000;\">, <\/span>@&#8221;Error: failed to prepare statement with message &#8216;%s&#8217;.&#8221;<span style=\"color: #000000;\">, sqlite3_errmsg(<\/span><span style=\"color: #4e8187;\">database<\/span><span style=\"color: #000000;\">));<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>sqlite3_bind_int(<span style=\"color: #4e8187;\">delete_statment<\/span>, <span style=\"color: #252bd8;\">1<\/span>, <span style=\"color: #bb2da2;\">self<\/span>.<span style=\"color: #4e8187;\">primaryKey<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">int<\/span> success = sqlite3_step(<span style=\"color: #4e8187;\">delete_statment<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #bb2da2;\">if<\/span> (success != SQLITE_DONE) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12e1b;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #78492a;\">NSAssert1<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #252bd8;\">0<\/span><span style=\"color: #000000;\">, <\/span>@&#8221;Error: failed to save priority with message &#8216;%s&#8217;.&#8221;<span style=\"color: #000000;\">, sqlite3_errmsg(<\/span><span style=\"color: #4e8187;\">database<\/span><span style=\"color: #000000;\">));<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>sqlite3_reset(<span style=\"color: #4e8187;\">delete_statment<\/span>);<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>delete_statement \u306f\u3001\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u6700\u521d\u306e\u65b9\u3067\u5ba3\u8a00\u3057\u305f\u3001\u9759\u7684\u306asqlite3_stmt \u3067\u3059\u3002\u307e\u305a\u3001\u3053\u308c\u304c\u3001nil \u304b\u3069\u3046\u304b\u8abf\u3079\u307e\u3059\u3002\u3082\u3057\u3001\u305d\u3046\u306a\u3089\u3001sqlite3_prepare \u6587\u3092\u4f7f\u3044\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001sqlite3 \u5185\u306e\u201d\uff1f\u201d \u306b\u3001\u73fe\u5728\u306etodo\u306e\u30d7\u30e9\u30a4\u30de\u30ea\u30fc\u30ad\u30fc\u3092\u3042\u3066\u306f\u3081\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u5f8c\u3001\u5b9f\u884c\u3057\u3001\u30ea\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089todo \u3092\u524a\u9664\u3059\u308b\u306e\u306b\u3001\u6700\u5f8c\u306b\u3059\u308b\u3053\u3068\u306f\u3001\u30e6\u30fc\u30b6\u304c\u201ddelete\u201d\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u3068\u304d\u306e\u52d5\u4f5c\u3092\u7279\u5b9a\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<p><strong>RootViewController.m<\/strong> \u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<blockquote>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400;\">\/\/ Override if you support editing the list<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">&#8211; (<span style=\"color: #bb2da2;\">void<\/span>)tableView:(<span style=\"color: #703daa;\">UITableView<\/span> *)tableView commitEditingStyle:<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>(<span style=\"color: #703daa;\">UITableViewCellEditingStyle<\/span>)editingStyle forRowAtIndexPath:(<span style=\"color: #703daa;\">NSIndexPath<\/span> *)indexPath {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #4e8187;\">todoAppDelegate<\/span> *appDelegate = (<span style=\"color: #4e8187;\">todoAppDelegate<\/span> *)[[<span style=\"color: #703daa;\">UIApplication<\/span> <span style=\"color: #3d1e81;\">sharedApplication<\/span>] delegate];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span><span style=\"color: #4e8187;\">Todo<\/span> *<span style=\"color: #4e8187;\">todo<\/span> = (<span style=\"color: #4e8187;\">Todo<\/span> *)[appDelegate.<span style=\"color: #4e8187;\">todos<\/span> <span style=\"color: #3d1e81;\">objectAtIndex<\/span>:indexPath.<span style=\"color: #703daa;\">row<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;\"><span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1e81;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span><span style=\"color: #bb2da2;\">if<\/span><span style=\"color: #000000;\"> (editingStyle == <\/span>UITableViewCellEditingStyleDelete<span style=\"color: #000000;\">) {<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>[appDelegate <span style=\"color: #31595e;\">removeTodo<\/span>:<span style=\"color: #4e8187;\">todo<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span><\/span>\/\/ Delete the row from the data source<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1e81;\"><span style=\"color: #000000;\"><span style=\"white-space: pre;\"> <\/span>[tableView <\/span>deleteRowsAtIndexPaths<span style=\"color: #000000;\">:[<\/span><span style=\"color: #703daa;\">NSArray<\/span><span style=\"color: #000000;\"> <\/span>arrayWithObject<span style=\"color: #000000;\">:indexPath] <\/span>withRowAnimation<span style=\"color: #000000;\">:<\/span><span style=\"color: #bb2da2;\">YES<\/span><span style=\"color: #000000;\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\"><span style=\"white-space: pre;\"> <\/span>}<span style=\"white-space: pre;\"> <\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;\">}<\/p>\n<\/blockquote>\n<p>\u307e\u305a\u3001appDelegate \u3078\u306e\u53c2\u7167\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002\u6b21\u306b\u3001\u73fe\u5728\u7de8\u96c6\u4e2d\u304b\u3069\u3046\u304b\u8abf\u3079\u307e\u3059\u3002\u3082\u3057\u3001\u7de8\u96c6\u4e2d\u306a\u3089\u3001appDelegate \u4e0a\u306e\u3001removeTodo \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306e\u884c\u3067\u306f\u3001\u4e0e\u3048\u3089\u308c\u305findexPath \u306e\u5217\u3092UITableView \u304b\u3089\u524a\u9664\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u30d3\u30eb\u30c9\uff06\u5b9f\u884c\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\u65b0\u898f\u30a2\u30a4\u30c6\u30e0\u306e\u8ffd\u52a0\u3001\u30a2\u30a4\u30c6\u30e0\u306e\u7de8\u96c6\u3001\u30a2\u30a4\u30c6\u30e0\u306e\u524a\u9664\u304c\u51fa\u6765\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u304a\u75b2\u308c\u3055\u307e\u3067\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-819\" title=\"812-4\" src=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-4-276x300.png\" alt=\"812-4\" width=\"276\" height=\"300\" \/><\/a><\/p>\n<p><a href=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-820\" title=\"812-5\" src=\"http:\/\/yamazon.org\/wp-content\/uploads\/2010\/12\/812-5-276x300.png\" alt=\"812-5\" width=\"276\" height=\"300\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u304cTodo\u30ea\u30b9\u30c8\u306e\u6700\u5f8c\u306b\u306a\u308a\u307e\u3059\u3002SQLite\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u3001todo&#8230;<\/p>\n","protected":false},"author":1,"featured_media":814,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-812","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-old-blog"],"_links":{"self":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=812"}],"version-history":[{"count":0,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}