Whether these are proficient in IOS-(1)

Source: Internet
Author: User

Disclaimer: This blog post is the author's original work. Reference 1 Reference 2 reference 3 Reference 4 reference 5 Reference 6

About the online some about the iOS material, oneself through the study to do some sort of, here only as notes, facilitates oneself the coding process to constrain the norm, deepens the understanding.

1. What is Handoff? Reference

Handoff before use to ensure that the phone and computer under the same LAN (connect the same WiFi), first to the computer (ICloud) and mobile phone to login your Apple ID, and then open the phone on the Handoff in the computer's Dock will see a message from ***iphone, So you connect your phone to your computer, why do you do it? Perhaps Apple has taken into account that the iphone screen is too small for users of Apple computers to be able to use this connection to operate smaller screen devices on large screens.

What technologies and services are included in 2.iCloud? Reference

Apple is a cloud-based technology, users can free trial 5G of storage space, can be used to store photos, contacts, text messages, documents and other content, when needed to wireless push them to the device, users can from any computer, Access to icloud on any device is readily accessible applications include office productivity, development tools, media, widgets, and more.

What is the 3.iOS extension? To cite some common examples?

Extension is for some of the visible source class or the Invisible source class to add some programmer to use the method, we in a certain framework to add a method for a class, we can add an extension method for the class, so that we do not need to write a subclass for the class to inherit, improve efficiency. You add a method interface to a class without giving it a subclass, but be aware that you can only add methods and not add instance variables.

4.OC is how to manage memory, where is the difference between arc and MRC memory management?

OC uses the method of reference counting to manage memory.

5. Agreement and category?

A protocol is a declaration of a set of methods that does not need to be implemented and can be implemented by any class, but the class must follow the protocol, which can be said that the protocol is a set of interfaces that are implemented by other classes. To implement an interface's class, you must adhere to the protocol that declares the interface.

A category is an extension of a class that is visible source code, invisible source code, but cannot add a private attribute field to it, only the method can be expanded, and the instance variable cannot be expanded. When we add a method to an already existing class, it is convenient to add a subclass.

6. What is the role of (delegated) agent? How does an agent implement a simple code example?

A delegate is an object to achieve something to be implemented by another object, the principal to formulate a series of agreements, the executor to follow these protocols to achieve the requirements of the entrusted party, the agent needs to follow the agreement, and the client to carry out the task when the order.

Suppose there are two classes a, B.

A develop an agreement and declare the properties of a protocol in Class A,id<adelegate>delegate;

Declaring instance Object A * a = [[A alloc] init]; b * b = [[B alloc] init]; Set proxy Object a.delegate = b;

Class B to follow the agreement, B<adelegate> b in B to implement the method in the Protocol;

Class A at the appropriate time to let B to perform the task, a command let B to do things;

7. describe an example of a retain cycle?

The properties of the proxy are defined in the class, the semantic attribute of the attribute is retain, the attribute is also defined in the Proxy object class to store the object of that class, and the semantic attribute is retain, which causes a circular reference.

When the object definition of Class A is defined as an object of the Retain,b class, the semantic attribute is also retain, and the Class B object is used in Class A, and the Class A object in class B causes a circular reference.

8. What is the difference between #import and #include and @class when used?

9. What is the difference between adding Self.name = @ "Object" and _name = @ "Object" in the method of an object?

Self.name = @ "Object" is a setter method called property generation, when walking the setter method, will first determine whether the object is consistent with the previous _name, if not the same, the original _name, release, and then the object Retain, the reference count plus 1, obtains ownership of the object.

The latter is simply an assignment to the object, storing the memory address, and the reference count of the instance variable does not add 1.

What is the difference between self.name = nil and [_name release]?

The former is called a property setter method, now its own release reference count minus 1, and then the value of the object is then empty, and then access the instance variable will not have any memory problems.

The latter simply reduced the reference count of the object by 1, and did not set the value of the object's memory to null, so that the object's memory address is still present in the pointer variable, and when the system reclaims the object's memory, the object is accessed and a wild pointer exception occurs.

11. Define a standard macro definition, this macro definition input two parameters, return a small number?

Implement a macro definition, enter two parameters, return a smaller parameter

/* Method 1*/

#define Minsimple (A) (A) <= (b) ( A):(B))

/* Method 2*/

#define Kmin (b) ({__typeof__ (A) a=a;__typeof__ (b) b = B;a < B? A:b})

/* Method 3*/

#define __NSX__PASTE__ (A, b) a# #B

#define __NSMIN__IMPL__ (a,b,l) ({__typeof__ (a) __nsx_paste__ (__a,l) = (a); __typeof__ (b) __nsx_paste__ (__b,l) = (b);(__ nsx_paste__ (__a,l) <__nsx_paste__ (__b,l))? __nsx_paste__ (__a,l): __nsx_paste__ (__b,l);})

#define MIN (b) __nsmin_impl__ (a,b,__counter__)

What is the difference between 12.__typeof and typeof?

Now iOS7 suggests that we use typeof not recommend that we use the __typeof, the TypeOf keyword is a new extension of the C language, which is very useful in the Linux kernel, and typeof parameters can be in two forms: expression, type.

13. What is the difference between the next process and the thread?

A thread is a unit of execution within a process and a basic unit of execution, comparing his differences with the process in the following ways:

(1). From the address space: a thread is an execution unit within a process that has at least one thread that shares the address space of the process, and the process has its own independent address space.

(2). From the possession of a resource: a process is a resource that is allocated and owned by the same process as a thread that shares a process's resources.

(3). The thread is the basic unit of the operating system processing schedule, but the process is not.

14. Explain the sandbox mechanism of iOS?

The sandbox mechanism for iOS is a secure system that specifies that applications can only read files within the folders created for the app and not access content elsewhere. All non-code files are stored in this place, such as: sounds, images, attribute lists, text files, etc.

The sandbox mechanism adheres to the following principles:

(1). Each application is within its own sandbox.

(2). Each application is not able to cross its own sandbox to access other content within the sandbox that should be used.

(3). Applications that request data or accept data are authenticated with permission.

What are the digital objects in 15.OC, which describe their differences from the basic data types?

The number objects in OC have nsvalue nsnumber two kinds.

Nsvalue is a type of object in OC that enables the conversion of struct type Cgpoint and Nsrange to OC objects.

NSNumber is an object type in OC that can convert basic data types to OC objects, such as float, int, double.

What is the difference between 16.swift and OC, and what is the connection?

17. Summarize the programming code formatting considerations?

(1). Variable name to strictly follow the English, do see the name of the meaning, and should not follow the Hanyu Pinyin to achieve the name of understanding.

(2). Methods to be separated by a line of space, the method inside the white space should be isolated to separate the implementation of the function, generally separate functions are extracted as a method.

(3). For method alignment, block does not use a colon-aligned format, but in other cases it can be written in a colon-aligned format.

(4). When commenting, be concise when, as far as possible, do not block comments, it is recommended to use self-explanatory

(5). In the method signature, there should be a space after the method type (-/+ symbol).

(6). When defining the name of a class, try to add special prefixes (such as abbreviations for company names) in front of them, to prevent duplication of names with some third-party SDKs, and not to duplicate the names of the Xcode system's classes.

(7). When the interface is redesigned, the name of the interface should not be abbreviated, except for these commonly used abbreviations (alloc,init), which can be abbreviated when designing parameter names.

(8). Code naming conventions.

A. To be clear, concise, if not both the time to try to ensure clarity, is to avoid difficult to understand, ambiguous to name. Even a long name we have to go to the complete spelling method name. Don't think of yourself as being known for some abbreviations, because you may only know them, but you can write some of the long-known historical abbreviations. For API naming, avoid ambiguity.

B. In the case of doubts to query the current header file or reference document, when a class method used polymorphism, consistency is very important; in different classes, the same method name should be the same.

C. Naming to avoid self-referencing, such as for character type naming, NSString is correct, but Nsstringobject is not canonical. Note: Mask and Notification ignore this rule.

D. Prefixes are an important part of declaring APIs, and they differentiate between different functional areas of the software.

Prefixes can be very effective in preventing naming conflicts with Apple;

The prefix prevents naming conflicts with Apple internal;

The prefix must have a specified format, usually consisting of 2-3 uppercase letters, without underscores and sub-prefixes;

Prefixes are used when naming classes, protocols, functions, constants, and typedef structures;

The method name does not use a prefix, because it exists in a specific namespace, and the struct field does not use a prefix.

F. Writing conventions:

When defining an API, follow the camel's name rule, the first letter lowercase, the first letter of each word will be capitalized, and if the method name begins with a well-known capitalization abbreviation, the rule cannot be used. such as Tffrepresentation (Nsmage);

The function is prefixed with the constant name, using the same prefix as its associated class, and capitalized with the first letter. such as: nscelldisabled;

Punctuation: A name made up of multiple words, do not use punctuation as part of the name, and split symbols (underscores, dashes) are not used.

Instead of using underscores as a prefix for private methods, Apple retains the use of this method, and if you are forced to use it, it may cause conflicts with the system's methods, overwriting the system approach, which will result in incalculable catastrophic consequences. However, the underscore of an instance variable is allowed as its prefix.

When declaring a class, the class name contains a noun that indicates what the class is (or does) and has the appropriate prefix. such as NSString, NSDate and so on.

For unrelated classes and protocol: Most peotocol gather a bunch of related methods, not associated class, and can be distinguished from class using ING in protocol.

For the associated class and protocol: Some protocol gather a bunch of unrelated methods and try to associate with a class that is dominated by this class, such protocol with class, such as Persondelegate.

G. Note Specification for header files

Temporarily feel that its description is too much to draw, without understanding, and later add your own understanding. 《****》

H. Writing notes for methods

Start with a lowercase letter and capitalize the first letter of the next word.

Starting with a well-known abbreviation can be capitalized, such as: PDF.

A private method can add a prefix.

If the method represents an object with an accepted action, start with a verb.

Do not use an auxiliary verb of a kind that has little practical meaning, do or dose. Also do not use adverbs and adjectives before verbs.

If the method returns an accepted property, the recipient + Received property is named. Do not use the Get word unless you return multiple values. 《****》

Use the keyword before all parameters to indicate the type of the parameter.

When creating the Init method, describe the associated element, do not use and to connect the keyword as the recipient attribute, use with, or do not apply the join word, direct ": Parameter 1: Parameter 2". But when the method describes two separate operations, you can use and to connect to them.

If the verb is present in the attribute, do not use the verb's past participle form as an adjective, use the modal verb can, will, should but do not use do,dose, only use Get when the method returns multiple parameters in some cases.

In the proxy's method declaration, if the parameter has two or more two, then the parameter can omit the prefix of the class name and lowercase that argument, but not for-(BOOL) Applicationopenuntitledfile: (NSApplication *) sender; And- (void)windowDidChangeScreen:(NSNotification *)notification; 前者只有一个sender参数的方法,后者响应notification的方法(方法的唯一参数就是notification)。询问delegate是否可以执行某个行为时可以使用 did 或 will,不过 should 更完美。

For some methods in the collection, if the collection is unordered, it is better to return a nsset than Nsarray.

For the method parameter, avoid using 1-2 letters as the method name, do not use "pointer", "PTR" name, because the parameter type "*" indicates his type, but also to avoid the abbreviation of only a few letters.

If you inherit a large framework, make sure that the private method of the subclass is not the same as the method name of the parent class, or the method implementation of the parent class is overridden.

I. Specification of macro definitions

Do not use # define precompiled directives to create constants, integer constants using enumerations, and float constants using the const modifier;

For a # define pre-compilation directive, capitalize all letters, such as DEBUG judgment

Note that both the initial and the trailing letters of the macro command have double-dip lines. __minvalue__

Defines the NSString constant as the value of the notification and key.

J. Naming notes for functions

The function names a similar method, but note that the classes and constants used have the same prefix, and the first letter after the prefix is capitalized.

Many function names begin with the verbs that describe their effects.

Functions that query properties have further naming conventions: If the function returns the properties of the first parameter, omit the verb, or if the value is returned by reference, use "Get", or if the Boolean value is returned, the verb should be used flexibly.

K. Writing Specifications for notifications

       [Name of associated class] + [Did | Will] + [UniquePartOfName] + Notification

L. Specification for extended writing formats

              [Prefix] + [uniquepartofname] + Exception

M. instance variable naming conventions

You should not normally access instance variables directly

Internal exceptions for methods such as Init, dealloc, accessor methods, etc.

Instance variable the underscore "_" begins

Ensure that the instance variable describes the stored property @implementation MyClass{   BOOL _showsTitle; }

If you want to modify the instance variable name of the property, use the @synthesize statement@implementation MyClass  @synthesize showsTitle=_showsTitle;

When adding an instance variable to a class, there are a few things to note:

Avoid declaring public instance variables

Developers should be interested in object interfaces, not details of their data. You can avoid declaring instance variables by using property

If you need to declare an instance variable, specify the keyword @private or @protected If you let subclasses directly access an instance variable using @protected keyword

If an instance variable is a property accessible to a class, make sure that accessor methods is written, and if possible, use the attribute.

Whether these are proficient in IOS-(1)

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.