Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 6. Manipulating Strings > Storing Rich Text - Pg. 133

Storing Rich Text argument. This will work fine until someone uses a string with a percent symbol in it as an argument to this program. Then the function will look at the second argument and try to interpret it. Unfortunately, there is no second argument, so will read a random value from a register. If it's interpreting this as some kind of number, it's not a big problem. If it's interpreting it as a pointer (to a C string or Objective-C object), it will almost certainly crash. By passing @"%@" we tell NSLog() that there is only one real argument, and that it's an object. 133 Storing Rich Text 6 7 8 9 10 11 12 13 14 15 16 NSDictionary *keyword = [[NSDictionary dictionaryWithObject: @"keyword" forKey: @"type"] retain]; NSMutableAttributedString *program = [NSMutableAttributedString new]; NSAttributedString *fragment = [[NSAttributedString alloc] initWithString: @"int" attributes: keyword]; [program appendAttributedString: fragment]; From: richText.m A string is just a list of characters. Before you display a string, you generally need some other attributes. These attributes describe the typeface, the size, the alignment and underline