background preloader

Strings

Facebook Twitter

Object alloc questions. Subject: Re: Object alloc questionsFrom: Greg Hurrell <email@hidden>Date: Fri, 27 Feb 2004 19:15:42 +0100 El 26/02/2004, a las 0:10, T Reaves escribis: NSString * aString = [@"How does this initialize the object? "]; That should be NSString* aString = @"How does this initialize the object? "; and is just a short cut. The compiler just takes care of creating the NSString object. Actually, it isn't quite true that they are equivalent, as the following code snippet demonstrates (the actual results are shown as comments): NSString *test1 = @"Test string"; NSLog(@"test1 retain count is: %d", [test1 retainCount]); // 2147483647 [test1 retain]; NSLog(@"test1 retain count is: %d", [test1 retainCount]); // 2147483647 [test1 release]; NSLog(@"test1 retain count is: %d", [test1 retainCount]); // 2147483647 The first string is a constant string object embedded in the binary at compile time that sticks around for the duration of execution.

Contact Apple | Terms of Use | Privacy Policy. Objective c - Can .strings resource files be added at runtime. Objective c - Is there a way to specify argument position/index in NSString stringWithFormat. Objective c - NSString - Convert to pure alphabet only (i.e. remove accents+punctuation) NSString UIKit Additions Reference Class Reference. Overview The UIKit framework adds methods to NSString to support the drawing of strings and to compute the bounding box of a string prior to drawing. None of these methods affects the contents of the string object itself, only how it is drawn on screen. By default, strings are drawn using the native coordinate system of iOS, where content is drawn down and to the right from the specified origin point. Whenever you are positioning string content, you should keep this orientation in mind and use the upper-left corner of the string’s bounding box as the origin point for drawing. The methods described in this class extension must be used from your app’s main thread.

Instance Methods boundingRectWithSize:options:attributes:context: Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics, within the specified rectangle in the current graphics context. Parameters size The size of the rectangle to draw in. options String drawing options. context. CFAttributedString Reference. Overview Instances of CFAttributedString manage character strings and associated sets of attributes (for example, font and kerning information) that apply to individual characters or ranges of characters in the string.

CFAttributedString as defined in Core Foundation provides the basic container functionality, while higher levels provide definitions for standard attributes, their values, and additional behaviors involving these. CFAttributedString represents an immutable string—use CFMutableAttributedStringRef to create and manage an attributed string that can be changed after it has been created. CFAttributedString is not a “subclass” of CFString; that is, it does not respond to CFString function calls.

CFAttributedString conceptually contains a CFString to which it applies attributes. Attributes are identified by key/value pairs stored in CFDictionary objects. CFAttributedString is “toll-free bridged” with its Foundation counterpart, NSAttributedString. Functions Parameters alloc str aStr. Objective c - How to use NSString drawInRect to centre text.