Recently learning iOS, I have been using C # to develop, Java, C, C + + also have a certain understanding. Recently started an air, trying to learn iOS development.
If you're not in C # and the Java camp, if you're not interested in swift, you don't have to look down, really!
At first my goal is very clear, that is to learn OC, should be the language after many years of extensive application, online source code a lot, and the problems encountered in Baidu and Google can also easily find information, so I started with OC to go, but a few days of video look down, found that OC syntax can only be used Wonderful two words to describe, perhaps I used to use C # and Java syntax, perhaps my personal problem, anyway I hate OC grammar rules.
Then I tried to look at the swift language and found that swift and OC syntax are very different, but the root of C #, Java syntax is very similar, it is just too much like. This is not like the style of Apple Ah, hehe.
I am learning swift, while writing this article, I think of what to write, the article structure will be messy, but should not have too much impact on reading.
The purpose of writing the article is to make it possible for friends interested in iOS development from C # and Java camp to look at what is different and similar to Swift in terms of C # and Java so that everyone can learn better and faster swift!
First, let's look at the prospects for Swift.
1, Apple will be released in 2016 in the IOS10 and OS X system applications, fully developed in the Swift language
2. Swift Language Reference C, JavaScript, Python, Java, C # (easy to use, efficient, flexible)
3. Swift version iterations are accelerating
4. End of 15 open source
The result: OC will one day exit the historical stage, like abandoned children, I think a lot of OC developers should have realized. But the OC developers completely turn to learn Swift will be very good at its syntax, but C #, Java Developers can quickly get started!!!!
After the crap is over, let me list some similarities and differences between the SWIFT syntax and C # syntax (Java and C # are similar, I use C # as a reference), I will update this article irregularly, and will write the time node clearly.
----------------------------------------------2015-7-11----------------------------------------------
Statement End symbol (;)
The end of the statement in Swift syntax can be omitted (;) number, but you add this (;) will not be wrong, personal habits, or write it, I have obsessive-compulsive disorder.
// Swift can do so, at the end of the semicolon without the error, and JavaScript like it does not like? var0var0; // in C #, the first line error tells you that the semicolon is missing. int 0 int 1;
Definition of a variable
The parameter type in Swift is automatically recognized by value, if you need to manually define the variable type (unassigned initial value) in the format: variable name: type
//-------The situation in Swift (description: var variable, let constant)//automatic recognition of the situationvari =1 //Auto-recognition i is integer intvarK =3.1415 //automatically recognize K as doublevarm ="Hello world!" //automatically identify m as String//Case of manual Declaration typevarP:string//declare p to be a string (remember to initialize later)varQ:int =1 //q is an integral type//-------The case in C #stringp;intQ =1;//that is, a colon, and then a variable name and type position.
Tuples in Swift, this is a good thing
What is a tuple, what it can do, what is convenient (maybe I put the tuple here is inappropriate, but since I think about it, let it Go)
1. The presence of tuples allows me to return multiple variables at the end of a method without having to define a struct or a new object to return
2, tuples can be defined as a separate structure
Now let's look at how to define tuples
//-----A tuple definition in swiftvarA = ("Hello, Steve .", -,true,3.1415926)//The structure of a value should be like this (string,int,bool,double)//So how are we going to untie it? Two methods//The first kind of "a. Subscript", subscriptis the order of the values in brackets starting from 0, PASS OC Development in this called point grammar, I laughed, OC is a hodgepodge
varA1 = A.0 //A1 is automatically recognized as a string and the value is "Hello Jobs"
varA2 = A.1 //A2 automatic recognition int 2015
//The second method of
var(K1,K2,K3,K4) = a//So K1 = a0, k2 = A1 See .
When we talk about the function (method), we will discuss the tuple
Logical statements in Swift
// The If Else statement can be written in Swift if 1= =1{ statement block 1}else{ statement block 2}//C # And are Java developers feeling less? Yes, brackets ()// then we have parentheses right? No problem. If(1= =1) { statement fast}
For Loop statement, and C # no difference
// ---------The For statement in Swift (which is also spoken for after) // no parentheses for var 0;i<; i++{ println (i);} // with parentheses for (var k=0;k<; k++) { println (k)}
for in
//-----Traversal in SwiftvarARR2 = [];//define an empty array, which is explained herevararr = [1,2,3,4,5,6,7,8,9,0];//array definition, type is auto-recognized, int array forMinchArr//variable m automatically recognizes the type each time, so there's no need for Var here.{println (M); //Print}//The following is the same as for loop--for var k = 0;k<1000;k++ forMinch 0... +{println (m)}//-----foreach in C # I'm not here to give you an example.
Strongly typed conversions
//in-----SwiftvarAge = Int (" +");//-----in C #
intAge =int. Parse (" +");
//or
intAge = (int)" +";
Write it here today, a little late ~ ~ Next time to add
1
Learn notes from C # to Swift,swift