1. Traversal of qualifying characters
1-(Nsattributedstring *) Characterswithattribute: (NSString *) AttributeName2 {3Nsmutableattributedstring *characters =[[Nsmutableattributedstring alloc] init];4 5 intindex =0;6 while(Index <[self.texttoanalyze length]) {7 Nsrange Range;8 IDValue =[Self.texttoanalyze attribute:attributename9 Atindex:indexTeneffectiverange:&Range]; One if(value) { A [characters Appendattributedstring:[self.texttoanalyze Attributedsubstringfromrange:range]; -index = range.location +range.length; -}Else { theindex++; - } - } - + returncharacters; -}
1 -(void) UpdateUI2{3 Self.colorfulCharactersLabel.text = [NSString stringWithFormat:@ "%d colorful characters" , [[self characterswithattribute:nsforegroundcolorattributename] length]]; 4 Self.outlinedCharactersLabel.text = [NSString stringWithFormat:@ "%d outlined characters" , [[self characterswithattribute:nsstrokewidthattributename] length]]; 5 }
2. Segue Identification code
1-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender2 {3 if([Segue.identifier isequaltostring:@"Analyze Text"]) {4 if([Segue.destinationviewcontroller Iskindofclass:[textstatsviewcontrollerclass]]) {5Textstatsviewcontroller *tsvc = (Textstatsviewcontroller *) Segue.destinationviewcontroller;6Tsvc.texttoanalyze =Self.body.textStorage;7 }8 }9}
IOS7 Notes-6, controller polymorphism, navigation Controller, TAB bar Controller