"ios Development objective-c" Bookmark Manager Project
Source: Internet
Author: User
<span id="Label3"></p>1. Project<p><p>Create a new Bookmark Manager project that can store bookmarked urls, Chinese names, stars, visits, and permission Information. Has the function of adding, deleting, changing, checking and sorting.</p></p>2. Find objects, Abstract classes<p><p>Bookmark manager, Bookmark Manager. Bookmark Manager ... Read a few more times to find the Object. Bookmarks and Manager. Bookmarks include information such as url, Chinese name, and star Rating. There are bookmarks inside the Manager. Then I can abstract out two Classes. One is the bookmark class. One is the manager class.</p></p><p><p></p></p><p><p>We add, delete, change, check and sort bookmarks in the bookmark manager. Save the Bookmark's property data in a Bookmark.</p></p><p><p></p></p>3. Object properties and Behavior analysis<p><p><br>Analysis of the storage relationships of the bookmark manager:<br><br></p></p>4. Implementation of Classes<p><p></p></p>1. Implementation of the Bookmark class<p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">#import <foundation/foundation.h>//bookmark class store bookmarks detailed information/data @interface bookmark:nsobject{nsstring * _url; URL NSString * _title; Title Nsuinteger _stars; Star Nsuinteger _vist; Number of visitors char _level; Permissions}-(void) seturl: (nsstring *) url;-(void) settitle: (nsstring *) title;-(void) setstars: (nsuinteger) stars;-(void) Setvist: (nsuinteger) vist;-(void) setLevel: (char) level;-(nsstring *) geturl;-(nsstring *) gettitle;-(nsuinteger) Getstars;-(nsuinteger) Getvist;-(char) Getlevel;//construction Method stores Data-(instancetype) initwithurl: (nsstring *) URL Withtitle: (nsstring *) title withsarts: (nsuinteger) stars withvist: (nsuinteger) vist withlevel: (char) level; @end</pre></pre><p><p></p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">#import "BookMark.h" @implementation bookmark-(instancetype) initwithurl: (nsstring *) url withtitle: (nsstring *) title Withsarts: (nsuinteger) stars withvist: (nsuinteger) vist withlevel: (char) level{self = [super init];if (self) {_url = url;_ title = Title;_stars = Stars;_vist = Vist;_level = level;} Return self;} -(void) seturl: (nsstring *) url{_url = url;} -(void) settitle: (nsstring *) title{_title = title;} -(void) setstars: (nsuinteger) stars{_stars = stars;} -(void) setvist: (nsuinteger) vist{_vist = vist;} -(void) setLevel: (char) level{_level = level;} -(nsstring *) Geturl{return _url;} -(nsstring *) Gettitle{return _title;} -(nsuinteger) Getstars{return _stars;} -(nsuinteger) Getvist{return _vist;} -(char) Getlevel{return _level;} @end</pre></pre><p><p></p></p>2. Implementation of the manager class<p><p></p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc"> #import <Foundation/Foundation.h> #import "BookMark.h"//bookmark Manager Class @interface Bookmanager:nsobject{nsmutablearray * _array;} -(instancetype) init;//delete-(void) removebookmark: (nsstring *) title;//add-(void) addbookmarkwithurl: (nsstring *) URL wi Thtitle: (nsstring *) title withstars: (nsuinteger) stars withvist: (nsuinteger) vist withlevel: (char) level;//change-(v Oid) modifytitle: (nsstring *) title withnewtitle: (nsstring *) newtitle;//lookup-(void) searchwithtitle: (nsstring *) title;- (void) sortwithstars;-(void) showallbookmark; @end </pre></pre><pre name="code" class="objc">#import "BookManager.h" @implementation Bookmanager-(instancetype) init{self = [super init];if (self) {_array = [[ Nsmutablearray alloc] init];} Return self;} Add bookmark-(void) addbookmarkwithurl: (nsstring *) url withtitle: (nsstring *) title withstars: (nsuinteger) stars Withvist: (N Suinteger) vist withlevel: (char) level{for (int i = 0; i < [_array count]; i + +) {if ([title isequaltostring:[_array[i] getTitle]] {NSLog (@ "repeatedly added"); return;}} The following can be used both to construct methods and to use the set method of the BookMark *book = [[BookMark alloc] initwithurl:url withtitle:title withsarts:stars withvist: Vist withlevel:level];//bookmark * book = [[BookMark alloc] init];//[book seturl:url];//[book Settitle:title];//[book Setstars:stars];//[book Setvist:vist];//[book setlevel:level]; [_array addobject:book];} Delete Bookmark-(void) removebookmark: (nsstring *) title{for (int i = 0; i < [_array count]; i + +) {if ([title isequaltostring:[ _array[i] GetTitle]) {[_array removeobject:_array[i]];return;} else NSLog (@ "without this bookmark");}} Change Bookmark-(void) modifytitle: (nsstring *) title withnewtitle: (nsstring *) newtitle{for (int i = 0; i < [_array count]; i + +) {if ([title Isequaltostring:[_arra y[i] GetTitle]) {[_array[i] settitle:newtitle];}}} Find Bookmark-(void) searchwithtitle: (nsstring *) title{int Index =-1; Save Bookmark Location//index = 1 indicates that no corresponding Bookmark//traversal bookmark was found. After you locate the destination bookmark location, exit the loop for (int i = 0; i < [_array count]; i + +) {if ([title isequaltostring:[_array[i] getTitle]) {index = i; break;}} If (index = =-1) {NSLog (@ "no bookmark needed to find");} else NSLog (@ "found the bookmark pos =%d", index);} -(void) sortwithstars{//the Bookmark object with a bubbling sort for (int i = 0; i < [_array count]-1; i + +) {//control the number of rounds for the sort for (int j = 0; J < ; [_array count]-1-i; J + +) {//control Comparison of the number of times if ([_array[j] getstars] > [_array[j + 1] getstars]) {nsarray * temp;temp = _array[j];_array[j] = _arr Ay[j + 1];_array[j + 1] = temp;}}} -(void) showallbookmark{for (int i = 0; i < [_array count]; i + +) {NSLog @ "url:%@ title:%@ star:%ld access:%ld permissions:%c", [_array [i] getUrl], [_array[i] getTitle], [_array[i] getstars], [_array[i] getvist], [_array[i] getlevel]);}} @end</pre><p><p></p></p>5. Actions of the bookmark manager<p><p></p></p><p><p>In this step we imagine that a person is manipulating a bookmark manager with an interface, because without the interface, we can just manipulate it inside the main function. Like what:</p></p><p><p></p></p><pre name="code" class="objc">#import <Foundation/Foundation.h> #import "BookMark.h" #import "BookManager.h" int main (int argc, const char * argv[ ] {@autoreleasepool {//create A bookmark for baidu bookmanager* Mybookmanager = [[bookmanager alloc] init];[ Mybookmanager addbookmarkwithurl:@ "www.baidu.com" withtitle:@ "baidu" withstars:3 withvist:123 withlevel: ' A '];// Create a new Sina bookmark [mybookmanager addbookmarkwithurl:@ "www.sina.com" withtitle:@ "sina" withstars:7 withvist:456 withlevel: ' B '] ;//create a new Sohu bookmark [mybookmanager addbookmarkwithurl:@ "www.souhu.com" withtitle:@ "sohu" withstars:5 withvist:756 withlevel: ' C '];//repeatedly joined [mybookmanager addbookmarkwithurl:@ "www.souhu.com" withtitle:@ "sohu" withstars:5 withvist:756 withlevel: ' C ' ];//show all bookmarks NSLog (@ "all added bookmarks"); [mybookmanager showallbookmark];//find [mybookmanager searchwithtitle:@ "sina"];//delete [mybookmanager removeBookMark:@ "baidu" ]; NSLog (@ "deleted bookmarks"); [mybookmanager Showallbookmark];//sort [mybookmanager sortwithstars]; NSLog (@ "sorted bookmarks"); [mybookmanager showallbookmark];//change [mybookmanager modifytitle:@ "sina" withnewtitle:@ "123"]; NSLog (@ "changed bookmarks"); [mybookmanager showallbookmark];} Return 0;}</pre><p><p></p></p><p><p>First of all, we have three bookmarks: baidu, Sina and Sohu.</p></p><p><p>The content of the bookmark is the contents of the Program.</p></p><p><p>We then verify the correct way to add bookmarks, find bookmarks, Delete bookmarks, sort bookmarks, and change bookmarks.</p></p><p><p>The output of the final program Is:</p></p><p><p></p></p><pre name="code" class="objc">2015-07-22 20:15:58.560 3. Bookmark Manager [3,083:303] repeatedly added 2015-07-22 20:15:58.562 3. Bookmark Manager [3,083:303] all bookmarks added 2015-07-22 20:15:58.563 3. Bookmark Manager [3,083:303] url: www.baidu.com title: Baidu star: 3 visits: 123 permissions: a2015-07-22 20:15:58.565 3. Bookmark Manager [3,083:303] Url: www.sina.com title: Sina star: 7 visits: 456 permissions: b2015-07-22 20:15:58.565 3. Bookmark Manager [3,083:303] url: www.souhu.com title: Sohu star: 5 interview volume: 756 Permissions: C 2015-07-22 20:15:58.566 3. Bookmark Manager [3,083:303] found the bookmark pos = 12015-07-22 20:15:58.568 3. Bookmark Manager [3,083:303] bookmark after delete 2015-07-22 20:15:58.568 3. Bookmark Manager [3,083:303] url: www.sina.com title: Sina star: 7 visits: 456 permissions: b2015-07-22 20:15:58.569 3. Bookmark Manager [3,083:303] Website: www.souhu.com title: Sohu star: 5 visits: 756 permissions: c2015-07-22 20:15:58.570 3. Bookmark manager [3,083:303] after sorting 2015-07-22 20:15:58.571 3. Bookmark Manager [3,083:303] Web address: www.souhu.com title: Sohu star: 5 visits: 756 permissions: c2015-07-22 20:15:58.573 3. Bookmark Manager [3,083:303] url: www.sina.com title: Sina star: 7 Visitors Q: 456 permissions: b2015-07-22 20:15:58.574 3. Bookmark manager [3,083:303] changed bookmarks 2015-07-22 20:15:58.576 3. Bookmark Manager [3,083:303] Url: www.souhu.com Title: Sohu star: 5 interview volume: 756 permissions: c2015-07-22 20:15:58.577 3. Bookmark Manager [3,083:303] Url: Www.sina. com title: 123 stars: 7 visits: 456 permissions: Bprogram ended with exit code:0 </pre>As we expected, the project features of our bookmark Manager are Implemented.<p><p></p></p>6. Summary<p><p>In this bookmark manager we have the following points to Learn:</p></p><p><p>1. Analysis of Project requirements;</p></p><p><p><strong><span style="font-size: 18px; color: #ff0000">2. Find the object and abstract out the class. Analyze the properties and behavior of the class;</span></strong></p></p><p><p>3. Implementation class;</p></p><p><p>4. Verify that the relevant behavior or method is Correct.</p></p><p><p>Bookmark Manager is stored in the bookmark, the bookmark is stored in the Data. Here I set the behavior of a mutable array in the Bookmark manager to store the address of the Bookmark. Each time we add a bookmark, we create a bookmark object. and write the data in the Bookmark.</p></p><p><p>When you delete a bookmark, you can delete the Bookmark's position in the Array.</p></p> <p><p>"ios Development objective-c" Bookmark Manager Project</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service