Objective-c:foundation Frame

Source: Internet
Author: User

Foundation framework


NSString, Nsmutablestring, NSNumber (Basic data Type wrapper class), Nsvalue (special type wrapper class: pointer, array, struct), Nsarray, Nsmutablearray, Nsdectionary, Nsset and so on.
one, immutable string NSString class, mutable string Nsmutablestring class (subclass of immutable string)
1. Creation of String objects

<1> constant String object: The most basic format nsstring *str = @ "DSHSD";


<2> Create a string from a class method: + (nsstring*)stringwithstring: (NSString *)
<3> created by instance method: -(nsstring*)initwithstring: (nsstring*)
<4> format string creation:+ (nsstring*)stringWithFormat: (nsstring* ...)
<5> creation of a C-language string:+ (nsstring*)stringwithutf8string: (char *)
<6> Create a string by file:-(nsstring*)Initwithcontentsoffile:(nsstring *path) usedencoding: (Nsuinteger) Error: (nserror*) <7> creating strings from network data:+ (nsstring*)Stringwithcontentsofurl:(nsurl*) Encoding: (nsstringencoding) Error:(nserror*)
2. Search by String
Note: Nsrange is a struct with two data: Nsuinteger location (the index of the start of the specified string) , nsuinteger Length (Specify string lengths)
<1> search string:
-(Nsrange) rangeofstring: (NSString *)
<2> Find out if a string is starting with a prefix:
-(BOOL) Hasprefix: (NSString *)
<3> Find if the string is starting with what suffix:
-(BOOL) Hassuffix: (NSString *)
<4> intercept strings in a string:
-( nsstring*) Substringwithrange: (nsrange)
or-(nsstring*) Substringfromindex: (Nsuinteger)
3. Comparison of strings
<1> Determine whether two objects are not the same object
-(BOOL) IsEqual: (ID) object;
or-(BOOL) Isequalto: (ID) object;
<2> determine if strings are equal
-(BOOL) isequaltostring: (NSString *) astring;
<3> Comparison of strings
-(Nscomparisonresult) Compare: (nsstring*) string;
The return value of Nscomparisonresult has the following three:

Nsorderedascending: means "<", Nsorderedsame: "=", nsordereddescending: ">"

4. String and other types of transitions
<1> other types converted to strings
+ (nsstring*) Stringwithformat:foomat ...;
<2> string Conversion to Integer, real, Boolean, etc.
-(Nsinteger) IntegerValue
-(int) intvalue;
-(CGFloat) Doublevalue;
-(double) doublevalue;

-(float) floatvalue;

-(BOOL) boolvalue

<4> string converted to C language
-(const void *) utf8string; 5. Variable string nsmutablestring (add, delete, change, check) <1> Create a variable array of fixed capacity

+ (ID) stringwithcapacity: (Nsuinteger) capacity;

<2> Insert content at index

-(void) insertstring: (NSString *) astring Atindex: (nsuinteger) Loc;

<3> Delete Content

-(void) Deletecharactersinrange: (nsrange) range;

<4> Add content (add at trailer)

-(void) appendString: (NSString *) astring;

-(void) AppendFormat: (NSString *) format, ... (ns_format_function);

<5> fully set to other strings

-(void) setString: (NSString *) astring;

<6> replacement

-(void) Replacecharactersinrange: (nsrange) Range withstring: (NSString *) astring;

Second, NSNumber class

(1) wrapping a basic data type as a class type that is a basic data type wrapper class

-(ID) Initwithchar: (char) value;

-(ID) Initwithunsignedchar: (unsigned char) value;

-(ID) Initwithshort: (short) value;

-(ID) Initwithunsignedshort: (unsigned short) value;

-(ID) initwithint: (int) value;

-(ID) Initwithunsignedint: (unsigned int) value;

-(ID) Initwithlong: (long) value;

-(ID) Initwithunsignedlong: (unsigned long) value;

-(ID) Initwithlonglong: (Long long) value;

-(ID) Initwithunsignedlonglong: (unsigned long) value;

-(ID) initwithfloat: (float) value;

-(ID) initwithdouble: (double) value;

-(ID) Initwithbool: (BOOL) value;

+ (NSNumber *) Numberwithchar: (char) value;

+ (NSNumber *) Numberwithunsignedchar: (unsigned char) value;

+ (NSNumber *) Numberwithshort: (short) value;

+ (NSNumber *) Numberwithunsignedshort: (unsigned short) value;

+ (NSNumber *) Numberwithint: (int) value;

+ (NSNumber *) Numberwithunsignedint: (unsigned int) value;

+ (NSNumber *) Numberwithlong: (long) value;

+ (NSNumber *) Numberwithunsignedlong: (unsigned long) value;

+ (NSNumber *) Numberwithlonglong: (Long long) value;

+ (NSNumber *) Numberwithunsignedlonglong: (unsigned long long) value;

+ (NSNumber *) Numberwithfloat: (float) value;

+ (NSNumber *) Numberwithdouble: (double) value;

+ (NSNumber *) Numberwithbool: (BOOL) value;

(2) After the packaging of the class data to be removed from the original type

-(char) charvalue;

-(unsigned char) unsignedcharvalue;

-(short) shortvalue;

-(unsigned short) unsignedshortvalue;

-(int) intvalue;

-(unsigned int) unsignedintvalue;

-(long) longvalue;

-(unsigned long) unsignedlongvalue;

-(long long) longlongvalue;

-(unsigned long long) unsignedlonglongvalue;

-(float) floatvalue;

-(double) doublevalue;

-(BOOL) boolvalue;

Third, Nsvalue class

(1) Wrapping a special basic type as an object (for example, struct, array, pointer)

a.//wrapping an array as a class type

+ (Nsvalue *) Valuewithbytes: (const void *) value objctype: (const char *) type;

or + (Nsvalue *) Valuewithpointer: (const void *) pointer;

Remove array type

-(void *) Pointervalue;

b.//wrapping the pointer as a class type

+ (Nsvalue *) Valuewithpointer: (const void *) pointer;

Remove pointer type

-(void *) Pointervalue;

c.//wrapping a struct as a class type (structure commonly used in Foundation: nsrange\nsrect\nssize\nspoint)

First, create the struct: (x, Y is the coordinate origin).

Nsrange range = Nsmakerange (location,length)

Nsrect rect = nsmakerect (x, y, width, height)

Nsrange size = nsmakesize (width,height)

Nsrect point= nsmakepoint (x, y)

Use a struct as a parameter

+ (Nsvalue *) Valuewithrange: (nsrange) range;

+ (Nsvalue *) Valuewithpoint: (nspoint) point;

+ (Nsvalue *) Valuewithsize: (nssize) size;

+ (Nsvalue *) Valuewithrect: (nsrect) rect;

Remove structure Type

-(Nspoint) Pointvalue;

-(nssize) Sizevalue;

-(Nsrect) Rectvalue;

-(Nsrange) Rangevalue;

Objective-c:foundation Frame

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.