?? datacontroller.m
字號(hào):
/*File: DataController.mAbstract:A simple controller class responsible for managing the application's data.Typically this object would be able to load and save a file containing theappliction's data. This example illustrates just the basic minimum: it createsan array containing information about some plays and provides simple accessormethods for the array and its contents.Version: 2.6Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.("Apple") in consideration of your agreement to the following terms, and youruse, installation, modification or redistribution of this Apple softwareconstitutes acceptance of these terms. If you do not agree with these terms,please do not use, install, modify or redistribute this Apple software.In consideration of your agreement to abide by the following terms, and subjectto these terms, Apple grants you a personal, non-exclusive license, underApple's copyrights in this original Apple software (the "Apple Software"), touse, reproduce, modify and redistribute the Apple Software, with or withoutmodifications, in source and/or binary forms; provided that if you redistributethe Apple Software in its entirety and without modifications, you must retainthis notice and the following text and disclaimers in all such redistributionsof the Apple Software.Neither the name, trademarks, service marks or logos of Apple Inc. may be usedto endorse or promote products derived from the Apple Software without specificprior written permission from Apple. Except as expressly stated in this notice,no other rights or licenses, express or implied, are granted by Apple herein,including but not limited to any patent rights that may be infringed by yourderivative works or by other works in which the Apple Software may beincorporated.The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NOWARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIEDWARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR INCOMBINATION WITH YOUR PRODUCTS.IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTEGOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/ORDISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OFCONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IFAPPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Copyright (C) 2008 Apple Inc. All Rights Reserved.*/#import "DataController.h"@interface DataController ()@property (nonatomic, copy, readwrite) NSMutableArray *list;- (void)createDemoData;@end@implementation DataController@synthesize list;- (id)init { if (self = [super init]) { [self createDemoData]; } return self;}// Custom set accessor to ensure the new list is mutable- (void)setList:(NSMutableArray *)newList { if (list != newList) { [list release]; list = [newList mutableCopy]; }}// Accessor methods for list- (unsigned)countOfList { return [list count];}- (id)objectInListAtIndex:(unsigned)theIndex { return [list objectAtIndex:theIndex];}- (void)dealloc { [list release]; [super dealloc];}- (void)createDemoData { /* Create an array containing some demonstration data. Each data item is a dicionary that contains information about a play -- its list of characters, its genre, and its year of publication. Typically the data would be comprised of instances of custom classes rather than dictionaries, but using dictionaries means fewer distractions in the example. */ NSMutableArray *playList = [[NSMutableArray alloc] init]; NSMutableDictionary *dictionary; NSMutableDictionary *characters; NSDateComponents *dateComponents = [[NSDateComponents alloc] init]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *date; characters = [[NSArray alloc] initWithObjects:@"Antony", @"Artemidorus", @"Brutus", @"Caesar", @"Calpurnia", @"Casca", @"Cassius", @"Cicero", @"Cinna", @"Cinna the Poet", @"Citizens", @"Claudius", @"Clitus", @"Dardanius", @"Decius Brutus", @"First Citizen", @"First Commoner", @"First Soldier", @"Flavius", @"Fourth Citizen", @"Lepidus", @"Ligarius", @"Lucilius", @"Lucius", @"Marullus", @"Messala", @"Messenger", @"Metellus Cimber", @"Octavius", @"Pindarus", @"Poet", @"Popilius", @"Portia", @"Publius", @"Second Citizen", @"Second Commoner", @"Second Soldier", @"Servant", @"Soothsayer", @"Strato", @"Third Citizen", @"Third Soldier", @"Tintinius", @"Trebonius", @"Varro", @"Volumnius", @"Young Cato", nil]; [dateComponents setYear:1599]; date = [calendar dateFromComponents:dateComponents]; dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Julius Caesar", @"title", characters, @"mainCharacters", date, @"date", @"Tragedy", @"genre", nil]; [playList addObject:dictionary]; [dictionary release]; [characters release]; characters = [[NSArray alloc] initWithObjects:@"Captain", @"Cordelia", @"Curan", @"Doctor", @"Duke of Albany", @"Duke of Burgundy", @"Duke of Cornwall", @"Earl of Gloucester", @"Earl of Kent", @"Edgar", @"Edmund", @"Fool", @"Gentleman", @"Goneril", @"Herald", @"King of France", @"Knight", @"Lear", @"Messenger", @"Old Man", @"Oswald", @"Regan", @"Servant 1", @"Servant 2", @"Servant 3", nil]; [dateComponents setYear:1605]; date = [calendar dateFromComponents:dateComponents]; dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"King Lear", @"title", characters, @"mainCharacters", date, @"date", @"Tragedy", @"genre", nil]; [playList addObject:dictionary]; [dictionary release]; [characters release]; characters = [[NSArray alloc] initWithObjects:@"Bianca", @"Brabantio", @"Cassio", @"Clown", @"Desdemona", @"Duke of Venice", @"Emilia", @"First Gentleman", @"First Musician", @"First Officer", @"First Senator", @"Fourth Gentleman", @"Gentleman", @"Gratiano", @"Herald", @"Iago", @"Lodovico, Kinsman to Brabantio", @"Messenger", @"Montano", @"Othello", @"Roderigo", @"Sailor", @"Second Gentleman", @"Second Senator", @"Third Gentleman", nil]; [dateComponents setYear:1604]; date = [calendar dateFromComponents:dateComponents]; dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Othello", @"title", characters, @"mainCharacters", date, @"date", @"Tragedy", @"genre", nil]; [playList addObject:dictionary]; [dictionary release]; [characters release]; characters = [[NSArray alloc] initWithObjects:@"Archbishop Scroop", @"Blunt", @"Carrier", @"Chamberlain", @"Earl of Douglas", @"Earl of Northumberland", @"Earl of Westmoreland", @"Earl of Worcester", @"Edward Poins", @"Falstaff", @"First Carrier", @"First Traveller", @"Francis", @"Gadshill", @"Glendower", @"Henry IV", @"Henry V", @"Hostess Quickly", @"Hotspur (Henry Percy)", @"Lady Percy", @"Lord Bardolph", @"Messenger", @"Mortimer", @"Ostler", @"Peto", @"Prince John, of Lancaster", @"Second Carrier", @"Servant", @"Sheriff", @"Sir Michael", @"Vernon", @"Vintner", nil]; [dateComponents setYear:1597]; date = [calendar dateFromComponents:dateComponents]; dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Henry IV, Pt 1", @"title", characters, @"mainCharacters", date, @"date", @"History", @"genre", nil]; [playList addObject:dictionary]; [dictionary release]; [characters release]; characters = [[NSArray alloc] initWithObjects:@"Adrian", @"Alonso", @"Antonio", @"Ariel", @"Boatswain", @"Caliban", @"Ceres", @"Ferdinand", @"Francisco", @"Gonzalo", @"Iris", @"Juno", @"Master", @"Miranda", @"Prospero", @"Sebastian", @"Stephano", @"Trinculo", nil]; [dateComponents setYear:1611]; date = [calendar dateFromComponents:dateComponents]; dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"The Tempest", @"title", characters, @"mainCharacters", date, @"date", @"Comedy", @"genre", nil]; [playList addObject:dictionary]; [dictionary release]; [characters release]; self.list = playList; [playList release]; [dateComponents release]; [calendar release];}@end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -