iOS Basic notes Finishing chapter I first section

Source: Internet
Author: User
<span id="Label3"></p><p><p><strong>A: NSString and Nsinteger Interchange</strong></p></p><pre><pre>Nsinteger conversion NSString type: [nsstring stringwithformat: @<span style="color: #800000;">"<span style="color: #800000;">%d<span style="color: #800000;">"<span style="color: #000000;">, nsinteger]; NSString conversion Nsinteger type: Nsinteger =<span style="color: #000000;"> [nsstring intvalue]; * Several other empathy [nsstring boolvalue], [nsstring floatvalue], [nsstring doublevalue]</span> </span> </span> </span> </span></pre></pre><p><p></p></p><p><p><strong>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</strong></p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre><span style="color: #000000;">A. The use of NSNumber is as follows to wrap a basic type into an Object's convenience constructor-(id) initwithchar: (<span style="color: #0000ff;">Char<span style="color: #000000;"><span style="color: #000000;">) value;-(id) initwithint: (<span style="color: #0000ff;">int<span style="color: # 000000; ">) value;-(id) initwithfloat: (<span style="color: #0000ff;">float<span style="color: #000000;">) Value;-<span style="color: #000000;"> (id) initwithbool: (BOOL) value; The convenience builder + (id) numberwithchar: (<span style="color: #0000ff;">char<span style="color: #000000;">) value;+ (id) numberwithint: (<span style="color: #0000ff;">int<span style="color: #0000ff;" ] value;+ (id) numberwithfloat: (<span>float<span style="color: # 000000; " ] value;+<span> (id) numberwithbool: (BOOL) value; get value from Nsnumber-(<span style="color: #0000ff;">char) charvalue;-(<span style=" Color: #0000ff; ">int) intvalue; -(<span style="color: #0000ff;">float) floatvalue; (BOOL) boolvalue; (nsstring *) stringvalue; </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p>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,</p></p><p><p>+ (NSNull *) null;</p></p><p><p></p></p><p><p><strong>Three: the NSData and the nsstring mutually turn</strong></p></p><p><p>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.</p></p><pre><pre><span style="color: #800000;">@ "<span style="color: #800000;">hello, world! <span style="color: #800000;">"<span style="color: #000000;"><span style="color: #008000;">//<span style="color: #008000;">NSString converted to NSData type NSLog (<span style="color: #800000;">@"<span style="color: #800000;">%s<span style="color: #800000;">"<span style="color: #000000;">, data.bytes); NSString * newstr =<span style="color: #000000;"> [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; NSLog (<span style="color: #800000;">@ "<span style="color: #800000;">%@<span style="color: #800000;">", newstr);</span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span> </span> </span></span></pre></pre><p><p></p></p><p><p><strong>Four: Remove the input box space (nsstring also applies)</strong></p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre><pre><span style="color: #000000;">Remove both ends of the space nsstring *temp =<span style="color: #000000;"> [textfield.text stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]] ; Remove both spaces and carriage return nsstring *text = [temp Stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]] ;</span></span></pre></pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p></p></p><p><p><strong>V: Iboutlet,ibaction Description</strong></p></p><p><p>Instance:</p></p><p><p>@property (weak,nonatomic) Iboutlet Uitextfield *textfile1;</p></p><p><p>@property (weak,nonatomic) Iboutlet UILabel *lable1; -(ibaction) save: (id) sender;</p></p><p><p>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.</p></p><p><p>The definition of the Iboutlet keyword is as follows:</p></p><p><p>#ifndef Iboutlet</p></p><p><p>#define Iboutlet</p></p><p><p>#endif</p></p><p><p>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.</p></p><p><p></p></p>Six pointer types <ul> <ul> <li>short, modifier int, Double</li> <li>long, modifier int, Double</li> <li>Signed signed, modified int, Char</li> <li>unsigned unsigned, modifier int, Char</li> </ul> </ul><p><p>The following explanation is required for type modifiers</p></p> <ol> <ol> <li>These modifiers are often used to modify the int type, and int can be omitted when the int is modified;</li> <li>Short and long will change the length of the int type, the length of different compiler items is not the same, but the short length is not much longer than Int,int length;</li> <li>signed, unsigned does not change the type length, only indicates whether the highest level is a sign bit, unsigned represents a positive number greater than or equal to 0;</li> </ol> </ol><p><p>of course, sometimes we have to be aware of the bytes occupied by each type, and the following table lists the storage space used by common data types</p></p><p><p></p></p> <blockquote> <blockquote> <p>Note: the char type is the smallest unit of data type and occupies 1 bytes under any type of compiler, and variable assignments of type char can be assigned directly to a character or to an integer (corresponding ASCII value); You can use two long to decorate a shape (that is, the 8-byte long Long that is used frequently), but two long cannot be modified by a double and there is no two short, otherwise a compile warning, or a floating-point constant if the F compiler considers it to be a float type, otherwise, The double type, For example 10.0 is a double type, and 10.0f is the float type.</p> </blockquote> </blockquote><p id="calculate"><p id="calculate"><strong>Seven: iboutlet,ibaction Description</strong></p></p><p><p>There are 34 operators in c, not much different from languages such as C #, java, and here are some caveats</p></p> <ol> <ol> <li>The relational operator returns 1 for true, 0 for false, and true for non-0 in the conditional language (negative, positive is true), and only 0 is false;</li> <li>The C language can not save the value of the relational operator;</li> <li>The final value of the comma expression is the value of the last expression;</li> </ol> </ol><p><p>For the above points, see the following example</p></p><pre class="code"><span style="color: green;">main.c//c language foundation////Created by Kenshin Cui on 14-7-12.//Copyright (c) 2014 cmjstudio. All Rights reserved.//<span style="color: blue;">#include<span style="color: #a31515;"><stdio.h><span style="color: blue;">Int<span style="color: black;">Main<span style="color: blue;">Int<span style="color: black;">argc<span style="color: blue;">const CHAR<span style="color: black;">* Argv[]) {<span style="color: blue;">Int<span style="color: black;">a=2>1,b=2<1,c=99,d=0;<span style="color: blue;">Int<span style="color: black;"><span style="color:black;">f=0,g=0,h=0,e= (f=3,g=4,h=5); a>0; <span style="color:green;">//did not save the results <span style="color:black">printf (<span style="color: #a31515;"> "%d,%d\ n "<span style=" color:black; >,a,b); <span style= " color:green;">//result: 1,0 <span style="color:blue;">if<span style="color:black;"> (c) {<span style=" color:green; ">//can be <span style="color:black; >printf (<span style=" color: #a31515; ">" true.\n "<span style=" color:black; ">) ; } <span style="color:blue;">if<span style="color:black;"> (d) {<span style="color:green; >//cannot pass <span style=" color:black; ">printf (<span style="color: #a31515;"> "false\n" <span style="color:black;" );} printf ( <span "%d\n">,e); <span style="color:green;">//result: 5 <span style="color:blue; >return <span style=" color:black; ">0;} </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span> </span></span></span></span></span></span></span></span></span></span></span></span></span></pre>Common functions printf () functions<p><p>The printf () function is used to output data to a standard output device, with a format character that can perform powerful output functions, which we have already used in the example Above.</p></p><p><p>Usually our output is not fixed content but contains some variables, this time we need to use the format, commonly used format characters are as follows</p></p><p><p></p></p><p><p>We can precisely control the output width of the format character and the number of decimal points of floating-point numbers.</p></p><pre class="code"><span style="color: green;">main.c//c language foundation////Created by Kenshin Cui on 14-7-12.//Copyright (c) 2014 cmjstudio. All Rights reserved.//<span style="color: blue;">#include<span style="color: #a31515;"><stdio.h><span style="color: blue;"><span style="color: blue;">int <span style="color: black;">Main (<span style="color: blue;">int <span style="color: black;">argc, <span style="color: blue;">const char <span style="color: black;">* Argv[]) { <span style="color: blue;">int <span style="color: black;">a=16; <span style="color: blue;">float <span style="color: black;">b=79.3f; printf (<span style="color: #a31515;">"[a=%4d]\n"<span style="color: black;">, a), printf (<span style="color: #a31515;">"[a=%-4d]\n"<span style="color: black;">, a); printf (<span style="color: #a31515;">"[b=%10f]\n" <span style="color: black;">, b); printf ("<span style="color: #a31515;">[b=%.2f]\n"<span style="color: black;">, b); printf (<span style="color: #a31515;">"[b=%4.2f]\n"<span style="color: black;">, b); <span style="color: blue;">return <span style="color: black;">0;}</span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></pre><p><p>The operation results are as follows</p></p><p><p></p></p><p><p>From the running results we are not difficult to find a positive number before the format character% can be set front-end, negative number set Back-end alignment, if the total length of the data exceeds the decorated length of the set, then the actual length of the display; the integer after the decimal point is used to control the length of the decimal place after the Point.</p></p>scanf () function<p><p>The scanf () function is used to receive input data from a standard input device</p></p><pre class="code"><pre class="code"><span style="color:green;">////main.c//c language foundation////Created by Kenshin Cui on 14-7-12.//Copyright ( C) 2014 Cmjstudio. All rights Reserved.//<span style="color:blue;"> #include <span style="color: #a31515;"><stdio.h><span style="color:blue;">int <span style="color:black; >main (<span style=" color:blue; ">int <span style=" color:black; >argc, <span style = " color:blue;">const Char <span style="color:black; >* argv[]) {<span style=" color:blue; ">int <span style=" color:black; ">a,b,c ; scanf (<span style="color:black; >,&a,&b,&c); <span style=" "%d,%d,%d" <span color:green; ">//need to enter at this time: <span and then enter the style="color:black; >printf (<span style=" color: #a31515; ">" a=%d,b=%d,c=%d\n "<span style="color:black;">,a,b,c); <span style="color:blue;">return <span style="color:black;">0;} </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></pre></pre><p><p></p></p><p><p>iOS Basic notes Finishing chapter I first section</p></p></span>

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.