Swift developer's SDK

In Xcode 6.3 in,We worked Objective-C adds new Null tag Language features。This feature gives a Objective-C language and the same expression Swift empty and non-empty kind of API Interface。Xcode 7 Through the introduction to Objective-C lightweight generic module allows Objective-C communications more natural and Swift。Generics allow two languages ​​secure communication and sharing to save the collection of specific types of elements。

These features are useful for any writing[……]

Click link to continue reading...

Generics

Generics are another important object-oriented concepts in,In addition to multi-state,It further increases the range of reuse code,For Swift language,,Generics throughout its always。

From Print() Speaking

We start from the first day of class in the use of this global function,It allows us to show the statement on the screen,Very simple to use,It can pass a string。

Incoming string displayed string,Incoming shaping on the digital display ......

and many more! As a function,How can it receives two different parameters!

ok we use[……]

Click link to continue reading...

Always given:Exception Handling

This lesson we get to know about the Swift error handling

In calling the method and the time to write a wheel,There will always be wrong sorts of weird,Normal is already compiled software,Some unexpected errors also occur。but,Among these errors,There are some that can be identified and captured - they can be expected。

Predictable error

Why do we say that there are some errors that can be expected to get it? For example, reading a file when the file does not exist、Save a document when the directory is not writable、Download the file when no network connection、transmit a parameter[……]

Click link to continue reading...

Static methods and static properties

Not all of the dynamic

we all know,The method is put in the running instance。That is the result of the implementation of the method is based on the instance property came,The property is an example of the current state of change - we call it "dynamic"。

But really all it is dynamic? In fact, not,Some methods give results which will directly and according to your call,It does not need to change according to the change of the instance attribute-that is to say, it will produce a definite result anyway,We call such methods static methods,It is static。

Let's take a look:
[crayo[……]

Click link to continue reading...

Lifetime:Automatic Reference Counting

In front of so many bedding,Now finally we want to address this thing the garbage collector。

ARC

This is not the Ark ...... This is automatic reference counting (Automatic Reference Counting),This thing is used to manage Apple memory。

Its function is that the garbage collector on the garbage heap。It would not have been able to ensure that all heap objects that reside in the running to be released in the heap。It ensures that memory will be reallocated to other objects to be used。

What is released

Speaking of the object will not be taken away to the garbage collector,Then it depends on the citation meeting[……]

Click link to continue reading...

Initializer

At the end of the previous lesson,We finally made clear the process of creating an object,Then,Speaking create an object looks like is to call a method,This method may in the end what is it?

Initializer

Not wrong,When we initialize a class object when,We did call a method - initializer。

Initializer method is actually a special provision of the,It is possible for the class to initialize。

Let's imagine,If no initializer,So we call the class will certainly be stereotyped,Every time they have to create an object,Then modify its properties?[……]

Click link to continue reading...

"Stack":In the end what happened "heap",What is a "stack"?

It's time to look at the living space objects and methods - and want to learn object-oriented,I do not know where to put the methods and objects is a very embarrassing thing - after all, we still have to face the garbage collector,Want to make the garbage collector to help you do more,We have to understand its working mechanism to some extent,Learn how and where to store objects,if not,You have to write a program to the vulnerable!

We have already mentioned the basic concept of the heap in front of the course which,Yes,Objects (instances) is placed on the heap - I put it vividly described as "garbage"。

Be piled[……]

Click link to continue reading...

"Fatal square":Multiple inheritance and protocols

Last time we mentioned agreement,But we talk about it the way an application,This lesson we take a deeper look at this class and used up almost exactly what profound esoteric protocol。

Now,We again review the shameful inheritance tree once:

Here we wrote a weapon ...... is used for attack and defense。Then,As a game,Model weapons can not just only in one place,Otherwise development costs will be too high - we want to drain as much as possible the value of the code。

Communicate with the designers of our future,designers want[……]

Click link to continue reading...

protocol:Allowed instantiated class and method must be rewritten

Rewriting said method,We come back to look at the inheritance tree:

This should look okay,We can create an instance of the sword,Create an instance of a pistol ......

But if I have to write it?

So the question is:excavator……

Do not,Our problem is "weapon" in the end is what?

We say "animal",Man is an animal,Birds are animals,dog、Cats are animals,That there is no animal animals?

The answer is no[……]

Click link to continue reading...

customize:override!

Said so many times rewriting,This time we have to rewrite treat seriously what method。

contract

We say,Inheritance is the equivalent of signing a contract,We inherited out of the subclass must comply with this contract,So even if you want to do something where no contract,Must comply with contract specifications,so,You override methods,It must also comply with the type of process。

We talked about the type of approach,It ()->() This represented。so,Overridden method must also comply with this type of argument that is receiving the return parameter type to be the same as the name of the same ...... Need I say more?[……]

Click link to continue reading...

Polypeptide? Polymorphic!

We finished the last lesson inheritance,That this lesson we will continue in-depth,What to look at inheritance tree is big move。

You and I could talk about this polymorphic pronunciation,Your first thought should be a high school biology talked of "polypeptide";Ok,The only possibility is to pronounce the same between the two。

Inherited significance

We say that to achieve the extraordinary significance of inherited,It greatly reduces the number of redundant lines in our code,Reducing the difficulty of maintaining the code ......

In fact,I did not mention the inherited another sense - Contract。

A lesson we did a Demo,On behalf of the subclass inherits the parent class to get[……]

Click link to continue reading...

In the end how to do:"A" and "a"

Last time we specifically about the inheritance mechanism,And also designed an inheritance tree,So the question is:I'm not going to ask Excavator strong Which? I want to ask how to determine whether a class is a subclass of another class do? How do we design a class instead of a class of attributes?

"A" and "a"

Here we will use such a method to examine the relationship between the two of them:

we say,Pistol firearms --OK,no problem,So pistol This class is a subclass of firearms。

There is a sword sword,It is a cold steel - no problem,So that[……]

Click link to continue reading...

Recalling once again:Inheritance

This time we take a look at a few lessons in succession before mentioned,We had初见 OPEN In a development with a mobile phone (system) to describe inherited this thing chestnuts,I believe we have the impression。

Inheritance

So this lesson we will learn to understand the depth of the concept of inheritance。

This is actually not difficult to understand,You see,When your parents died,Then they will be up to you to inherit wealth - Well,This is not a very happy thing worth,But this is the fact that。[……]

Click link to continue reading...

It's not what you think:A program website

This lesson we try to develop a simple command-line games,To complete the experience a so-called "development process"。

This game is set:

This is a board game,We guess the location of enemy ships,As long as the number of hits you can send them to sink。

We give these ships the label affixed to point it ...... such a variety of sites?so,This has become a site of attack Behind his program ......。

Goal of the game

We want to attack the player with the least number of sites,It crushed。Then we scored based on the number of players guessing。

Roughly design

We draw a 7 * 7[……]

Click link to continue reading...

Computed properties and packaging

Before we in class,Take a look at the previously mentioned "SoC" concept,We say this is called "Separation of Concerns",I translate it as separation of duties - the different sections that focus on their part。Or a target to achieve a goal。

The goal not only to make the code more modular and easier to maintain,Also let the system run more efficiently。So,We want the communication between objects becomes more standardized job。

Data Hiding

You go and see you writing framework code that, when used,Which gives you direct show[……]

Click link to continue reading...

Stored value and reference

Declare a variable

We use var to declare a variable,Congguizili like a tube placed in the experimental stage;

We give a specified variable type,Just like in the test tube labeled the;

Then put reagents must be marked on the label - otherwise could cause an explosion or poisoning。

Same,If we try to give a reservoir into a wrong data type,Then the compiler will complain - yes there is always a way to be able to fool the compiler - anyway, I will not teach you this method,That would cause it to crash。[……]

Click link to continue reading...

Guess the number game:An object of the class difference

A lesson on our first taste OOP Style,Ambiguous classes and objects in exactly what is it? This lesson we use a simple little chestnut to introduce to you。

Trying to explain

We say that the relationship between classes and objects and the relationship between the design of products,Take Our house is,Certainly there will be a corresponding building design,But the design will not only correspond to a building,At least one cell must be met with a set of drawings is not it? Our "Class" is the "design"。We use this design designed object's properties、Function and so a series of content,Then instantiating yield[……]

Click link to continue reading...

Our test environment and has shown signs of OOP

Some students did not take into account the iPhone,Swift language learning but at least we will have OS X operating system,Our code shows will be completed in OS X,Using the CLI interface。So although it looks old and was,But believe me take the GUI make you worry a lot - because that is another matter。

So now,Let's say hello and OOP

We take a look,Developing with OOP in the end is what it looks like?

We are not taking into account the high level of development,So we put all the functions of real[……]

Click link to continue reading...

How Swift 2.0 Declare an abstract class?

We all know that in Java declare an abstract class or method you want to use the abstract keyword,But unfortunately familiar things always gone,In Swift has no label。

Then,How should we declare an abstract class it?

Private constructor (initializer) Act

It actually makes a very familiar, right? Bar private constructor of that class certainly can not be initialized,Nature can not create an object instance ...... but ...... but how can there be so many,Anyway, it can be used on the line!
[crayon-6903a[……]

Click link to continue reading...