iOS Development Series Course Preview

Source: Internet
Author: User

Recently developed on Mac and iOS, think that you should write something to share with interested children's shoes. Before this. There have been a lot of people complaining about the complexity and difficulty of Apple objective-c, and there are a lot of illusions about the Swift launch this year (2014).

First in the current stage or even five years, I personally feel that the development of Mac and iOS can still be inseparable from objective-c, even if the application level (non-system level) development, recruitment iOS program ape certainly see there is no solid objective-c Foundation. While Apple wants Swift to replace objective-c, it must be a long-term goal.

At Swift's announcement, Mr. Cook said Swift would be a language to change everything. Only two months later, the list of programming languages published in Tiobe. Java and C + + have a record low (of course my favorite C language still occupies the top spot, although its rating also dropped by 0.25%), and Swift as a newborn directly preempted the throne of 18th place (about 100 of the program apes have a use of swift), People's expectations of the language can be said to be unusually high. However, what I want to say is that. Objective-c is not as difficult as it is imagined. Swift, however, is not a pleasure to play, and Swift has embraced two programming concepts or paradigms (paradigm) at the same time. Object-oriented programming and functional programming, before this. The debate over the merits of object-oriented programming and functional programming has not stopped for a long time. In fact, a program that really understands the two programming paradigms does not arbitrarily say that these are the best of both worlds, because there is no magic bullet in any programming language to make its users an excellent program ape. And as the ox-man King said. "No matter what, it is harmful when you go to extremes." When extreme. Object-oriented programming and functional programming are all trying to fit the world into its own model, but the world does not depend on the thinking of our brains.

Suppose you have a hammer. It is clearly not true that all things are treated as nails. Only by recognizing our real world. Talent out of the bondage of faith to us. "Let your model adapt to the world, instead of adapting the world to your model." "Although I do not like the people of Wang Yin, but this passage I still very much agree with." Dr. Lin Rui also said, "A good program ape does not claim allegiance to a language." They always choose the most appropriate tool to do what they want to do.

In fact, even if you are a Java program ape, suppose you have used the caller mode, command mode. Assuming you've used an interface callback, you've actually used the idea of functional programming. Similarly, you can write the object-oriented style code in C language.

Swift can be said to be a hodgepodge of more than JavaScript. You don't seem to be able to see Objective-c's shadow from it, but there are JavaScript, C #, Java, and other dynamic language/functional languages (such as Ruby, Python, Haskell) that I don't understand, and that's just what it's destined for. " Never easy. " In fact, Apple appointed Chris Lattern as early as 2010 to develop the next-generation programming language for iOS. It took 4 years to create Swift. To put it simply, Swift is a language that supports both object-oriented and functional programming paradigms, and it seeks a balance between dynamic and static languages. Both the characteristics of static language and the verve of dynamic language in detail. It is also a type-safe language at the same time and supports very high-level language features. Include closures, generics, and so on. Swift can be very convenient and c/c++/objective-c mixed programming, using the Unicode character set. Along with Swift is the playground in Xcode, a thing that, despite the fact that some of the program apes think it's amazing, actually IBM had something like this ten years ago, just not as flashy as playground. Recently saw the announcement of Apple IPhone6. Suddenly think of Apple's future pessimistic attitude, without the amid lord, Apple can also cattle how long, no one knows.

Anyway, as a program ape or developer, whether you choose to use Objective-c or swift, there will be a long way to go, through a variety of cultivation. In fact objective-c that Declaration and implementation of separation is not in the practice of the object-oriented principle of the interface and implementation of separation. The concept of interface-oriented programming. So in my heart that is very elegant.

The Protocol (protocol) in Swift is not so, just protocol the word easy is misleading, it may be called Interface (interface) or contract will be better.

Here are some links to help interested children to read the relevant materials, the same time with a piece of code written in Objective-c. Do is a computer to play with their own guessing the number of small games.

Functional programming in object-oriented programming languages: http://blog.csdn.net/shendl/article/details/2064218

Wang Yin: What is the problem with object-oriented and functional programming? http://geek.csdn.net/news/detail/3603

TIOBE September 2014 programming language leaderboard: http://www.csdn.net/article/2014-09-09/2821587-tiobe-programming

Shows the new features of Xcode 6 playground:


Guess the number game written with Objective-c (the computer itself is a 1-100 random number.) And guess the answer yourself.)

#import <Foundation/Foundation.h> @interface game:nsobject {@private int correctanswer; NSString *hint;} -(game *) init;-(int) judge: (int) thyanswer;-(NSString *) gethint; @end @implementation game-(game *) init {self = [s]    Uper Init];    Correctanswer = arc4random ()% 100; return self;} -(int) judge: (int) Thyanswer {if (thyanswer = = correctanswer) {hint = @ "Congratulations, you're right."    ";            } else {if (Thyanswer < correctanswer) {hint = @ "larger";        return 1;            } else {hint = @ "smaller";        return-1; }} return 0;} -(NSString *) Gethint {return hint;}    @endint Main () {Game *g = [game new];    int lower = 0, upper = 100;    int result = 0;        do {int myanswer = (lower + upper)/2;        NSLog (@ "I guess the answer is:%d", myanswer);        result = [g judge:myanswer];        NSLog (@ "%@", [G gethint]);   Switch (Result) {case-1: upper = Myanswer;         Case 1:lower = Myanswer;        Break    }} while (Result! = 0);    NSLog (@ "Game over!");    [g release]; return 0;}

Because the Mac system is a UNIX-based operating system. So open the terminal program to compile and execute the above code by typing the command, such as the following:

Cc-framework Foundation file name. m (CC is the C compiler of the C-compiler,unix system, can also compile objective-c and generate target code)

Of course. The above code should not be placed in the same file, @interface part in the header file (a file with the suffix. h), and the @implementation part in the source file (a file with the suffix. m). A definition interface. A definition implementation, so that the interface with the implementation of separation, in the future can be implemented through the replacement of the file to provide new or different functions. To do this, you should use Xcode directly to build a project, such as what you see:



iOS Development Series Course Preview

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.