Summarize the 20 common questions and answers in the swift language, and summarize the 20 common questions in the swift language.
1. if I am an entry-level iOS developer, should I select swift for learning, objective-c for learning, or both?
This can be decided based on two situations: 1. I want to enter the company's position for iOS development 2. I just want to be an independent developer and develop an app for publishing.
In the first case, you must learn objective-c. Currently, most apps on the market are developed with oc. The transition from oc to swift takes a long time.
Of course, swift should also learn at the same time.
Case 2: If you do not consider compatibility (iOS 7 or earlier versions will be mentioned later), you can simply learn swift. However, objective-c third-party open source libraries are rich. If you have time, you 'd better learn about oc.
Over time, it must have switched to swift.
2. I have many years of iOS Objective-C development experience. Are I new to swift?
In my opinion, you are not a newbie. Because you are familiar with Xcode and Cocoa/Cocoa Touch APIs. It takes longer to familiarize yourself with and learn these APIs and tools than to learn Swift.
Take some time to familiarize yourself with the Swift syntax,
You can use swift quickly in the project.
3. Do iOS 8 and OS X Yosemite applications only use the Swift language? No. Swift can interact smoothly with Objective-C, and vice versa. Apple has not completely converted Objective-C APIs into Swift, but you can still use these APIs in Swift code. Time will prove that the iOS and OS X stores will continue to rely on Objective-C language while adopting the Swift language in many years.
4. is Swift applicable to other iOS versions and OS X systems?
Yes! Xcode 6 can compile Swift code for iOS 7 and later versions and OS X10.9 and later versions. In fact, the WWDC App you downloaded from the app Store is written by Apple in Swift.
However, Apple does not allow applications created using Xcode Beta to be submitted to the App Store. Therefore, you must wait until the official version of Xcode 6 is released to upload the Swift application to the App Store.
5. Does the Swift language replace Objective-C, or is it just a supplement to Objective-C?
By referencing Apple's official statement, "Objective-C will not disappear. Swift and Objective-C can be used for both Cocoa and cococoatouch development ." Therefore, you can continue to use Objective-C. However, apple seems to encourage you to use Swift for new development, rather than wanting you to rewrite all Objective-C code. We guess Apple will gradually reduce the use of Objective-C language in the future framework and API development, or even discard Objective-C one day, so be prepared early!
6. What is playground?
Playground is just a file. You can write code and immediately see the running effect. It is really useful for learning Swift or new APIs, prototype code, or algorithms!
Refer to 11 articles to learn how to create and run playground.
7. How to Learn Swift?
Official Apple tutorial Swift Programming book
Http://numbbbbb.gitbooks.io/-the-swift-programming-language -/ ()
This is the fastest translation tutorial I have ever seen! Translation is fast and good.
Swift video of WWDC 2014
8. Is there anything that can be implemented in Swift but not in Objective-C? Or, in other words.
Yes. Swift is a modern language that introduces a lot of content not supported by Objective-C. For example, namespace (namspacing), optional type (optionals), tuples, generic, type inference, and others. Of course, Objective-C also has some features not available in Swift, such as messaging nil.
For more details, please read the official document: Using Swift with Cocoa and Objective-C Guide
You can also see the Chinese version
9. Is there any API that Swift cannot use? I have not found this article.
10. Where is the result of println () in Playground? If you open playground and still cannot see the result, perform the following operations:
Open the Assistant Editor to view the console output. Step: View> Assistant Editor> Show Assistant Editor,
Alternatively, use the shortcut key: Option + Command + Return.
11. How can I open Playgrounds and view those graphics with cool values?
You can open Playgrounds in either of the following ways: Create a Playgrounds project or create a file in an existing project, and select the playgrounds file.
Let's look at a simple code, a for loop,
for x in 1..10 { x }
The following is the corresponding playgrounds
12. How do you run REPL?
Run the following command on the terminal to tell it to use the command line tool of Xcode 6.
Sudo xcode-select-s/apps/Xcode6-Beta.app/Contents/Developer/
Run the following code to start Swift REPL.
Xcrun swift
If you are about to exit, enter exit or quit. You can also use the CTRL + D shortcut.
12. Can you use Swift to call your own Objective-C code or third-party libraries? If yes, what should I do?
Yes! When you add the first. swift file to the Xcode project, the system will prompt you to ask Xcode to create a bridge header file (bridging header file ). You can import the Objective-C header file that you want to see in Swift code in this header file. Then, all classes can be used by Swift without being imported. You can use the same Swift syntax as the system class to use custom Objective-C code.
13. Can arrays be of different types?
In Swift, it is strongly recommended to use a strongly-typed array containing only one type, for example:
Var goodArray: String [] = ["foo", "bar"]
Technically, you can create an array containing multiple types of objects. But you 'd better ask yourself why. Multi-type array:
Var brokenArray: AnyObject [] = ["foo", 1, 12.23, true]
14. Is the dictionary the same as the original one? Is the dictionary strongly typed?
Yes, but you can still use AnyObject. For a dictionary, it also makes sense that all values in it are not of the same type. The following is a JSON response returned from the server in the dictionary:
Let's look at an example of the server's JSON response, which is represented in a dictionary:
Var employee: Dictionary <String, AnyObject> = ["FirstName": "Larry", "LastName": "Rodgers", "Salary": 65_000.00]
This dictionary has two String-type keys and one Double-type key. It is also possible to directly use a dictionary, but you 'd better create a level-1 model object to represent the data, rather than relying on the dictionary.
15. How does Swift work with Grand Central Dispatch?
In the same way, you can use the c api as in Objective-C. You can also use Apple's advanced NSOperationQueue when dealing with concurrency.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {println( "test" )});
16. What about the internationalized macro commands in Objective-C?
Similar to NSLocalizedString in Objective-C,
You can use NSLocalizedString (key: tableName: bundle: value: comment :) In Swift to prepare for internationalization.
. TableName, bundle, and value arguments all have default values. Therefore, if you are using NSLocalizedString, you can write the following code:
NSLocalizedString("Hello", comment: "standard greeting")
17. Do I need to consider circular references for swift?
Of course you need to consider it! When two objects are strongly referenced to each other, a retain cycle can still be created. You can use the same method in Objective-C to break the retain cycle. There are three keywords used to declare the reference type. The details are as follows. Weak references and no primary references will solve your reference lifecycle problem.
When can I use strong references, weak references, and no primary references?
Strong references: strong references will make the ARC reserve instances until they are no longer needed. When all strong references are removed, the referenced instance is released. Note that strong references are implicit by default, so you do not need to explicitly declare them.
Weak references: You should use weak references between objects with independent lifecycles. When you set a weak reference for an object, if the object is released due to memory pressure, you don't mind this. The weak reference value must be a variable defined by var and must be used? Optional type of the operator. Weak references are optional, so you cannot end with a reference to an invalid instance that does not exist. When the referenced instance is released, ARC automatically sets the reference to nil.
No primary reference: You should use no primary reference for objects with the same lifecycle. For example, when an object points to itself, and you want to avoid a retain cycle. No primary reference can be used whenever there is a reference value, but when you need to tell ARC not to set it to nil. The act of no primary reference is similar to the unsafe_unretained of Objective-C. Make sure that you do not access the reference after the referenced object is released, which will cause your app to crash. No primary reference is optional and cannot be set to nil. No primary reference is also implicitly parsed.
18. How to Use semicolons
Semicolons are optional in Swift, but for the sake of ease of use, Apple recommends that you do not use semicolons any more. However, you may still use semicolons in Swift, for example, in loop statements.
for var index = 0; index < 3; ++index { ... }
19. How will swift develop?
Currently, swift is only the first version. Apple has a very clear purpose and they will update the language iteratively. Therefore, you can report swift bugs to Apple or ask for new features.
There is still much room for improvement before the official release of this version.
20. How does CocoaPods apply to swift projects?
The Swift project is still an Xcode project and supports multiple targets, but it has potential space to Improve the Ability of creating modules and custom frameworks. CocoaPods may be rewritten to adapt to this new feature.
Someone is using CocoaPods to assist Swift project work: the issue is already being discussed: here: https://github.com/CocoaPods/CocoaPods/issues/2218.
Note:
This article is mainly reference: http://www.raywenderlich.com/74138/swift-language-faq
However, I will not translate words by words. I have added my own ideas based on the reference of the original article, and briefly wrote down the questions and answers.
The answer formula for Chinese reading is as follows: Answer language (SET)
Classification of Modern Reading Solutions
I. Expression Methods: narrative, descriptive, lyrical, descriptive, and discussion
2. Techniques of expression: symbolic, comparative, contextual, suspense setting, forward and backward echo, desire to advance and suppress, toy things, express, Lenovo, imagination, and foil (positive and reverse)
Iii. rhetorical techniques: metaphor, anthropomorphic, exaggerated, ratio-specific, dual, quote, questioning, questioning, repetition, text-to-text, comparison, borrow, and slang
Iv. Six Elements of Narrative: Time, place, character, cause, process, and result
V. Narrative sequence: downstream, reverse, and intercept
Vi. Description: positive description and side description
7. Methods of describing characters: language, action, demeanor, psychology, and appearance
8. View: visual, auditory, taste, and touch
9. Methods for describing scenes: Combination of dynamic and static content (static content), combination of generalization and details, from far to near (or from near to far)
10. descriptive (or lyrical) Methods: positive (or direct) and reverse (or indirect)
11. description method: General description and detailed description
12. Order Description: Chronological, spatial, and logical order
XIII. Description: examples, numbers, analogy, comparison, definition, classification, interpretation, profiling, and reference
Iv. novel plot: Beginning, development, climax, and ending
15. Three elements of the novel: character image, story, and specific environment
16. Environment Description: natural environment and social environment
17. Three elements of argumentative papers: arguments, arguments, and arguments
18. arguments are classified into fact arguments and rational arguments
19. Demonstration Methods: Demonstration of examples (or facts), reasoning (sometimes referred to as arguments), comparison (or positive and negative comparison), and metaphor
20. Argument mode: argument and argument (arguments, arguments, and arguments can be refuted)
21. Structure of the essay: total score, total score, and total score; points are often parallel and progressive.
22. The role of quotation marks: referencing, emphasizing, specific titles; negative, ironic, and colloquial
23. usage of the break number: prompt, comment, summary, progressive, topic conversion, and insertion.
24. Miscellaneous: (1) Role of a sentence in the text:
1. The beginning of the article: The opening part of the question; rendering the atmosphere (narrative and novel), laying the foreshadowing (narrative and novel), setting suspense (novel), and assisting the following;
2. The text is as follows;
3. End of the article: The dot-ming Center (narrative and novel); deepening the topic (narrative and novel); taking care of the beginning (argumentative, narrative, and novel)
The beginning should be appealing (open-minded, straightforward; create suspense, fascinating; ask questions, attract attention; Explain the situation, explain the background), and end with a strong (eye-catching, thought-provoking; Summarize the full text, take care of the beginning; the narration ends, ending naturally; expressing emotions and arousing resonance)
(2) Role of rhetoric:
(1) its own role; (2) it combines sentence context.
1. metaphor and anthropomorphic: vivid image;
Q & A format: The + Object + feature is vividly written.
2. Comparison: momentum, enhanced tone, and in-one breath;
Answer format: emphasizes + objects + features
3. Question: attract the attention and consideration of readers;
Q & A format: attracts the attention and consideration of the + Object + feature.
4. counterquestion: emphasize and strengthen the tone;
5. Comparison: emphasized ...... Highlighted ......
6. Repetition: I emphasized ...... Enhanced tone
7. exaggeration: highlighted ...... Essential Features
8. Dual: the sentence structure is neat and rhythmic.
(3)
Sentence Meaning:
There is often a word or phrase in a sentence that uses a metaphor, comparison, borrowing, or symbolic expression. When answering questions, reveal the objects they refer to and clear sentences.
(4) can a word in a sentence be replaced by another line? Why?
Verb: No. Because the word is accurately and vividly written ......
Adjective: No. Because the word vividly describes ......
Adverbs (such as both, mostly, and so on): No. Because the word accurately describes ...... (Table level, table restriction, table time, table range, etc.). After changing, it becomes ......, It is inconsistent with the facts.
(5) Can I change the order of two or three words in a sentence? Why?
No. Because (1) it is inconsistent with the laws of people who know things (from simple to deep, from table to internal, from symptom to essence) (2) the word corresponds to the above (3) these words ...... remaining full text>
Summarize the problems and shortcomings in learning our national language.
Due to regional differences and educational factors, some people speak with a local accent more or less. Some schools still use local languages for teaching, which has some impact on students in Mandarin. In addition, there are often inverted strokes in writing.
We should strictly abide by the law of language, absorb foreign words, create new words, and make the language and words of the nation more standardized, accurate, vivid, and beautiful!