. NET code farming to IOS-a preliminary study

Source: Internet
Author: User

Haven't written a blog for a long time, before also intends to graduate design involved in the two algorithms come out to say (face analysis + sound analysis), Bowen wrote half, and then really too busy, that essay also sank in the draft list did not move.

I was originally a full-time. NET development, in the company responsible for the project is the internal use of the sales management system, because do not need to go out "head to face", so the company simply does not have any configuration (refers to the product, design, front end, etc., development equipment or some), so all the work is all inclusive. The original plan for itself is that the follow-up will slowly change the product side.

Later, also considered an opportunity, the company all mobile people basically left (IOS all gone, Android seems to only 2!!) Inside the company, there is not much to say), so the manager is going to let us go to the mobile development. NET and Java have always been "enemies" (their own understanding, do not spray), so I will not choose ANDROID,WP market is not enough, turned to their own competitiveness of the promotion is not big, so chose iOS development, and then this article ". NET code farming to IOS-primary exploration" ...

University period has a point C of the foundation, but to OC completely do not know, this belongs to starting from 0 (do not choose swift Start, actually is afraid it is not mature enough. Language this thing, in fact is the same, understand the basis of things, but also afraid of learning will not be other! )。

I belong to self-study, watch the video, check the information step-by-step walk slowly.

Http://wenku.baidu.com/course/view/1ce3571252d380eb62946d8c-C + OC explanation, comparative basis, can refer to (the lecturer's voice, I really can't stand, several times to listen to want to fall keyboard, but no money to buy new ... )

Http://edu.51cto.com/course/course_id-779.html-iOS the control of the explanation, but also the basis, you can refer to (in the middle for a few lecturers, overall is good)

IOS Real-combat Development (OASIS)-belongs to the actual combat type, very good (self-downloaded video, online do not know if there is no online link)

Learning really need to hit the keyboard, just look at it is not able to understand, at least I have not yet to see the extent of the ...

· I started from XCODE5, this time has been a lot less memory management code (basically do not write release), but do not need you to write, does not mean that you do not need to understand. So memory management needs to be looked at in detail.

· namespaces, there is no such concept in OC. Distinguish between two different classes, relying only on the class name. So it is usually preceded by a real class name, prefixed by a prefix, such as NSString (NS that begins with the core of MAC OS X, NeXTSTEP abbreviation), Cgpoint ... Many programmers use abbreviations of their own names to prefix classes.

· OC uses pointers in large quantities and requires explicit representation (NSString *str; STR is a pointer variable, preceded by a "*" explicit embodiment, indicating that it is a pointer to a "string" variable). There is also this concept in. NET, which simply does not require explicit indication ("*"), reference to. NET, class, string declarations.

· @ "", the notation of the string in OC, must precede with an "@" to indicate that the nsstring type;

· The NSLog () method, which is the Console.WriteLine method in. NET, supports the Format of the string, such as NSLog (@ "%@,%i,%f", @ "1", 1, 1.0); (@ "%@" is powerful, similar to. NET ToSt Ring () method).

· class declaration, create a generic class that contains an. h file and a. m file (for example, SLTest.h & SLTEST.M), which are paired,. h files are header files, generally used to make class declarations, similar to. NET abstract classes;. m files are implementation files that are used to implement the corresponding "Abstract class".

/** SLTest.h **///Importing header files using Import//Foundation-based framework//import indicates that the header file is included only once, regardless of how many times the command appears in the entire program#import<Foundation/Foundation.h>//declare a class with a interface//This class inherits from NSObject, similar to the base class object in. Net.@interfacesltest:nsobject{//declaring member variables}//declaring public methods@end/** SLTEST.M **///Importing header files using Import#import "SLTest.h"//implementation indicates the implementation of the class@implementationsltest//define and implement private methods//Implementing public methods@end

· The Declaration class in OC uses the interface keyword, which implements the class using the implementation keyword. In fact, OC also has a keyword "class", it is not "declaring the class" meaning, but "contains the class" meaning. The function is similar to import, but with import, the compilation will include the import file as a whole, and using class, the compile-time only tells it that it already has this class, but not the entire inclusion, more lightweight than import. It is used in places where you only need to know the class name, not the methods in the class (for example, variable declarations, etc.). Method of use: @class sltest;. The biggest benefits, such as having two classes: A, B,a has a variable B b;,b in a variable A; If you use import, then compile is "I Have you in me", each other contains, and finally caused the containment of the dead loop.

· The call to methods in OC is to use "[]", such as [AAA AAA], which is represented as AAA in. Net. AAA ();. method calls with parameters such as [AAA Bbb:1 Ccc:2] are represented as AAA in. Net. BBB:CCC: (1, 2);. Note that OC ":" is also the method name, how many ":" indicates how many parameters, and the parameter passed in is nested in the method name (how to define how to use, for example, the method has just parameters, defined as-(void) BBB: (Nsinteger) I CCC: ( Nsinteger), which differs greatly from. Net.

· Instantiate an object, due to memory management issues, in OC is basically the Alloc + Initxxx method (there is also an individual use of other Factory mode methods, not included here), Alloc represents the allocation of memory, INITXXX represents initialization. Basic usage: [[NSString alloc] initwithformat:@ "This is a string."). What this means is to instantiate a NSString object that points to "this is a string." Memory Block (Initwithformat: () is NSString own method, other types also have similar initxxx () methods, and some only init () method). Of course OC also has a new () method, but it is not recommended. or. NET new () Easy to use!! There are no overloads in OC and can only be distinguished by method names. For example, the Initwithformat () method in NSString and Initwithcoder (). or. NET new () Easy to use!!

· Get/set method, in. NET we use {get; set;} Let the compiler automatically add to us, OC also has similar:

// declaring with the property keyword // Specify the form of the property in parentheses: // Nonatomic indicates that the thread is unsafe, and in the case of a single thread that does not take into account threading security, the use of nonatomic is possible, and the corresponding atomic // General basic type with assign,nsstring with copy, the other with strong (retain), of course, there are exceptions to everything, the specific self-gu brother // In addition there are ReadOnly, getter and so on, self-gu brother bar @property (nonatomic, assign) BOOL Balabalabala;

Only this sentence, the compiler will automatically generate a private member variable and corresponding Get/set method, of course, you can also override the Get/set method, in the. m file to implement.

· Method before, "-" means the instance method, which is called by the instance, and "+" means the static method of the class method, which is the class in. Net.

· OC ID type, weak type, like the Var in JS, hard to follow. NET hooks, very much like dynamic, but it seems to be different from the dynamic, please forgive my lame expression ability ...

· The Self keyword, the this keyword in. NET, or the Super keyword, the base keyword in. net.

· block, the anonymous function in. NET, is defined in the following order: The return type, the "^" keyword, the method name (if the declaration position is a method parameter, can be omitted), and a parameter list, for example:

//return type is empty//method is named TEST1//parameter list is emptyvoid(^TEST1) (void) = ^{NSLog (@"TEST1");}; TEST1 ();//The return type is NSString *//method is named TEST2//need to pass in a parameter of type NsintegerNSString * (^TEST2) (nsinteger) = ^(Nsinteger i) {NSLog (@"TEST2 parameter:%i", i); return @"test2";}; NSString*result = TEST2 (Ten); NSLog (@"%@", result);//The TEST3 method defines a block parameter that has no return value and needs to pass in a parameter of type NSString- (void) TEST3: (void(^) (NSString *parameter)) block{NSLog (@"TEST3"); //call block and pass in the parameterBlock@"TEST3 parameter");}//call TEST3, pass in the block[Self test3:^ (NSString *parameter) {NSLog (@"parameter:%@", parameter);}];

Usage is the same as. NET, except the syntax is different.

· category, extension, which is a class extension in. NET, such as public static bool Isvalidemailaddress (this string str);. In OC, only extension methods are allowed, writing:

/** Nsstring+category.h file naming method, OC recommendation is the original class name + extension **///when declaring, the original class name is followed by a parenthesis, with the extension in parentheses, indicating that this is an extension@interfacensstring (Category)//extend a method to determine if the string is an email address-(BOOL) isvalidemailaddress;@end/** NSSTRING+CATEGORY.M **/@implementationnsstring (Category)//Implementation Method//Please ignore the specific method, here only to do demo-(BOOL) isvalidemailaddress{return[Self length]%2==0;}@end//when used, the. h file is introduced and can be used just like a normal class methodNSString *STR1 =@"1"; NSString*STR2 =@" One"; NSLog (@"%i", [str1 isvalidemailaddress]); NSLog (@"%i", [str2 isvalidemailaddress]);

· delegate, protocol, note that the delegate in Delegate,.net in. NET should be more similar to block in OC. The delegate here is more like an interface in. Net. In my own understanding, it is that I sometimes trigger an event, and if you need to know when I triggered the event, then there must be a "contract agreement" between us that notifies you when I trigger an event. And you receive my notice, what to do, that is your freedom.

The "agreed agreement", the delegate in OC, is described here. I would like to inform you that the method in delegate is used. You only need to implement this method, I can notify you. This is explained in more detail in the next article.

Some of the basics of OC are almost there, followed by the development of the interface, in the form of WinForm development of. NET, using the MVC framework in IOS, so it's easier to read if you're. Net.

To do a decent App, need a variety of positions of colleagues to help, from demand, to design, coding, testing, on-line, indeed test a team's ability to cooperate.

Today is very tired, wash ready to sleep ...

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.