iOS Development Basics-Fragmentation 1

Source: Internet
Author: User

A: NSString and Nsinteger Interchange

Nsinteger conversion nsstring Type: [NSString stringWithFormat: @ "%d", Nsinteger];

NSString conversion Nsinteger Type: Nsinteger = [NSString intvalue];

* Several other empathy [NSString boolvalue], [NSString Floatvalue], [NSString Doublevalue]

Two: Objective-c in the collection can not be stored in the basic type, such as int string float, can only convert them into objects to be stored, is the class NSNumber

A. The usage of NSNumber is as follows

A convenient constructor for wrapping basic types into objects

-(ID) Initwithchar: (char) value;

-(ID) initwithint: (int) value;

-(ID) initwithfloat: (float) value;

-(ID) Initwithbool: (BOOL) value;

A convenient constructor that wraps basic data types into objects

+ (ID) Numberwithchar: (char) value;

+ (ID) numberwithint: (int) value;

+ (ID) numberwithfloat: (float) value;

+ (ID) Numberwithbool: (BOOL) value;

Get the value from NSNumber

-(char) charvalue;      -(int) intvalue;     -(float) floatvalue;    (BOOL) Boolvalue; (NSString *) stringvalue;

b, in the collection class is not to store nil (empty), because nil as nil Terminator, then how do we store empty objects? The Nsnull, whose function is to wrap the null into an object,

+ (NSNull *) null;

Three: The NSData and the nsstring mutually turn

NSData, data, when we need to write some information into a file or send it to the web, we need to convert that data into a purely 0-, 1-character stream.

NSString * str = @ "Hello, world!";

NSData * data = [str datausingencoding:nsutf8stringencoding]; NSString Convert to NSData type

NSLog (@ "%s", data.bytes);

NSString * Newstr = [[NSString alloc] Initwithdata:data encoding:nsutf8stringencoding];

NSLog (@ "%@", newstr);

Four: Remove the input box space (NSString also applies)

Remove both spaces

NSString *temp = [Textfield.text stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset];

Remove both spaces and carriage returns

NSString *text = [temp stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset];

V: iboutlet,ibaction Description

Instance:

@property (weak,nonatomic) iboutlet Uitextfield *textfile1;

@property (weak,nonatomic) iboutlet UILabel *lable1; -(Ibaction) Save: (ID) sender;

The Iboutlet output port is an instance variable declared using the keyword Iboutlet. The output declaration in the controller header file should look like this: The Iboutlet statement was added before the instance variable declaration, which indicates that the object was created in Interface Builder. Once you link an object to an exit, you can access it as you would any object you create. As far as the compiler is concerned, Iboutlet does not perform any action. Its only function is to tell interface Builder that this instance variable will be connected to the object in the nib. Any instance variables you create that need to be connected to an object in the nib file must begin with the Iboutlet keyword. When you open Interface Builder, it scans the keyword in the project header file, and you can connect the code to the nib based on these (and only those) variables.

The definition of the Iboutlet keyword is as follows:

#ifndef Iboutlet

#define Iboutlet

#endif

The ibaction operation is a method in the Controller class. They are also declared by the Special keyword Ibaction, which tells interface Builder that this method is an action and can be triggered by a control.

iOS Development Basics-Fragmentation 1

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.