Those so-called filter out the iOS rookie face test

Source: Internet
Author: User

The difference between a struct and a class is what type of array is in <swfit, and whether there is a performance problem with a large number of copies. >

Class is a reference type and struct is a value type

Class can inherit classes, interfaces, and be inherited, STRYCT can only inherit interfaces, cannot be inherited

Class has a default parameterless constructor, there is a destructor, struct does not have a default parameterless constructor, can only declare a parameter constructor, no destructor

Class can use abstract and sealed, there are protected modifiers, structs can not be used abstract and sealed, there is no protected modifier;

Class must be initialized with new, and the struct can be initialized without new;

Class instances are garbage-collected to ensure that the memory is recycled, and the struct variables are automatically deallocated immediately after they are used;

From a functional point of view, class behaves as a behavior, and structs are often used to store data;

When passed as a parameter, the class variable is passed as an address, and the struct variable is passed as a value.

Now that we've introduced so much, how do we choose structure or class?

1). Stack space is limited, for a large number of logical objects, creating a class is better than creating a structure
2). Structures represent lightweight objects such as points, rectangles, and colors, for example, if you declare an array that contains 1000 point objects, additional memory is allocated for each object that is referenced. In this case, the cost of the structure is lower
3). Classes are the best choice when performing abstract and multilevel object hierarchies
4). Most of the time the type is just some data, the structure is the best choice

Add:

C language, the difference between struct and class:

Structs are simply defined as a complex data type and cannot be used for object-oriented programming.

In C + +, the difference between struct and class:

For member access and inheritance, the default in class is private, and the struct is public. Class can also be used to represent template types, but not for structs.

What is the type of array in the Swfit, and is there a performance problem with a large number of copies?

Array is implemented in Swift with a struct. Apple rewrites an array once, and then copy is a deep copy. If multiple copies are not modified, all arrays point to the same physical address, but the pointer moves, so the performance is good. Of course, if the change, the array will be copied a copy, this time the cost is a bit big.

Second, introduce the observer pattern

Maybe some people already think that the design pattern is a bit outdated, not the whole book read. Even if it's a few design patterns that are commonly used in iOS, I think it's always something to know.

If you say nsnotificationcenter how to use the direct pass.

This answer should consist of three parts: first of all, the design pattern to solve what problems, followed by what solution, and finally is the current system of concrete implementation of the plan.

Answer:

Observer pattern (Observer pattern): Defines a one-to-many dependency between objects, so that whenever an object state changes, its dependent objects are notified and automatically updated.

Typical push model implementations in iOS are Nsnotificationcenter and KVO.

Nsnotificationcenter

    • The Observer, Observer, is interested in registering a type of notification through the Nsnotificationcenter AddObserver:selector:name:object interface. When registering, it is important to note that Nsnotificationcenter does not perform a reference count of +1 to the observer, and when we release the Observer in the program, we must write it off from the center.

    • Notification hubs Nsnotificationcenter, notification hubs.

    • Observed objects, via PostNotificationName:object:userInfo: Send a notification of a type, broadcast change.

    • Notifies the object nsnotification that when a notification comes in, center invokes an interface registered by the observer to broadcast the notification while passing the Nsnotification object that stores the change.

KVO

The full name of KVO is Key-value Observer, which is the key value observation. is a way of realizing the observer pattern without a central hub. A Subject object manages the Observer object that is dependent on it and proactively notifies the observer object when its state changes.

    • Registered Observer

[Object Addobserver:self forkeypath:property options:nskeyvalueobservingoptionnew context:].

    • Changes the value of the Subject object property, which is the notification that the change is sent.

    • In the developed callback function, process the notification of the change received.

    • Unregister Observer [Object Removeobserver:self Forkeypath:property].

Third, in an HTTPS connected Web site, enter the account password click Login, to the server before returning this request, what happened in the middle

This problem is seen in other, originally the topic is to login to Gmail, but perhaps some people in the country do not know that Google is very early full station HTTPS, so here is particularly pointed out that the connection is HTTPS.

There are a lot of things to talk about here, and there are very many protocols under TCP/IP. There is no need to speak clearly, but the understanding of the entire network connectivity model can be seen in basic skills.

Answer:

HTTPS encryption process

  • The client packs a request, including the URL, port, your account password, and so on. Account password login should use the Post method, so the relevant user information will be loaded into the body inside. This request should contain three aspects: Network address, Protocol, resource path. Note that this is HTTPS, HTTP + SSL/TLS, and a layer of encryption information is added to the HTTP (equivalent to a lock).

  • The DNS server is typically requested first. The DNS server is responsible for resolving your network address to an IP address, which corresponds to a single machine on the web. This may occur with the hosts hijack and ISP failure issues.

  • Protocol is the way to obtain resources HTTP,FTP,UDP, different protocols have different formats, some are process-to-process, some are host-to-host.

  • The client establishes a socket connection to the server's port, and the socket generally resolves the request in the form of file descriptor.

  • The server side receives the request. The server will have a set of digital certificates (equivalent to a key) that will be returned to the client first. The client resolves the certificate, which is equivalent to locking the lock (the content) with the key (the certificate) and then transmitting the encrypted information.

  • After the server receives the encrypted information (private key), it decrypts and returns the data to the client with symmetric encryption. If the path is not correct, a 404 error will occur.

  • A proxy may be accessed before the general access server. This thing is a proxy, sometimes when the firewall is used, sometimes when the cache makes. If the background is a reverse-proxy structure, then there are actually multiple Web servers hidden in the proxy after the request processing, and you access is always proxy, this can solve the overload problem.

  • Sometimes after visiting the Web server to access the file server, mainly to request some information in the database.

  • The server will be packaged accordingly and returned to the client directly or through proxy (most of the time). The client decrypts the private key that was just generated and displays the content on the browser.

  • HTTPS encryption process details please go to HTTPS principle: Certificate delivery, validation and data encryption, decryption process resolution

There is a button in the middle of an app, after you touch the screen click, to this button to receive click events, what happened in the middle

Unloop and response chains need to be said clearly.

Sometimes you can also ask Uiresponder, Uicontrol, UIView relations.

Answer:

There are several steps in the response chain:

    • The device packs the touch-Uitouch and Uievent objects into the event queue of the currently active application

    • The uiapplication of the Singleton takes the touch event out of the event queue and passes it to the singleton UIWindow

    • UIWindow using the Hittest:withevent: method to find the view in which the touch operation is located

Runloop this way I'll talk about:

    • The runloop of the main thread is awakened

    • Notifies observer, handles timer and source 0

    • Springboard to app process after receiving touch event

    • Runloop processing of the source 1,source1 triggers a callback and calls _uiapplicationhandleeventqueue () for distribution within the app.

    • Runloop processed to sleep before releasing the old autorelease pool and creating a new autorelease pool

Those so-called filter out the iOS rookie face test

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.