forked from osolano/iOS-Design-Patterns-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataStructuresViewController.m
More file actions
160 lines (131 loc) · 4.37 KB
/
Copy pathDataStructuresViewController.m
File metadata and controls
160 lines (131 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// DataStructuresViewController.m
// iOSFundamentalConcepts_iPad
//
// Created by Oliver Solano on 8/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "DataStructuresViewController.h"
#import "IntegerClass.h"
@interface DataStructuresViewController ()
@end
@implementation DataStructuresViewController
@synthesize toolbar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(NSArray *)createArray{
// NSInteger test = 3;
// NSNumber *tes2 = [[NSNumber alloc] initWithInt:3];
NSArray *array = [[NSArray alloc] initWithObjects:@"Japan",@"US",@"China",@"Italy",@"France",@"Colorado",@"ukraine", nil];
// [array
return array;
}
-(NSArray *)createArray2{
NSNumber *test2 = [[NSNumber alloc] initWithInt:3];
NSArray *array = [[NSArray alloc] initWithObjects:test2, nil];
return array;
}
-(NSArray *)createArray3{
// NSInteger test3 = 4;
IntegerClass *obj = [[IntegerClass alloc] init];
obj.holdInt = 3;
NSArray *array = [[NSArray alloc] initWithObjects:obj, nil];
return array;
}
-(NSSet *)createSet{
NSSet *set = [[NSSet alloc] initWithObjects:@"Japan",@"US",@"China",@"Italy",@"France",@"Colorado",@"ukraine", nil];
return set;
}
-(NSDictionary *)createDictionary{
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Japan",@"Tokyo",@"US",@"DC",@"China",@"Beijing",@"Italy",@"Rome",@"France",@"Paris",@"Colorado",@"Denver",@"ukraine",@"Ukr", nil];
return dictionary;
}
-(void)testCollections{
//Enumaration
for(NSString *string in [self createArray]){
NSLog(@"Array:%@",string);
}
for(NSString *string in [self createSet]){
NSLog(@"Set:%@",string);
}
for(NSString *string in [self createDictionary]){
NSLog(@"Dictionary:%@",string);
}
//Dynamic Enumeration
for(id objectid in [self createArray]){
NSLog(@"Array using ID :%@",objectid);
}
for(id objectid in [self createSet]){
NSLog(@"Set using ID :%@",objectid);
}
for(id objectid in [self createDictionary]){
NSLog(@"Dictionary using ID :%@",objectid);
}
//Sorting
NSArray *sortedArray = [[self createArray] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for(NSString *string in sortedArray){
NSLog(@"Array sorted:%@",string);
}
// [self createArray] sor
// NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
// NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
// NSArray *sortedArray = [[self createArray] sortedArrayUsingDescriptors:sortDescriptors];
/*
for (NSString *string in sortedArray) {
NSLog(@"Sorted Array:%@",string);
}
*/
//Block-Based Enumeration
//Using NSEnumeration
//Enumerated Values
NSLog(@"enum = %i, %i, %i",Japan, US, France);
enum countries Country;
Country = Japan;
Country = France;
NSLog(@"Country %i",Country);
for(NSNumber *num in [self createArray2]){
NSLog(@"%i",[num integerValue]);
}
for(IntegerClass *obj in [self createArray3]){
NSLog(@"%i",obj.holdInt);
}
}
-(IBAction)selectFunctionButton:(id)sender{
[self testCollections];
}
#pragma mark -
#pragma mark Managing the popover
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
// Add the popover button to the toolbar.
NSMutableArray *itemsArray = [toolbar.items mutableCopy];
[itemsArray insertObject:barButtonItem atIndex:0];
[toolbar setItems:itemsArray animated:NO];
}
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
// Remove the popover button from the toolbar.
NSMutableArray *itemsArray = [toolbar.items mutableCopy];
[itemsArray removeObject:barButtonItem];
[toolbar setItems:itemsArray animated:NO];
}
@end