Start Developing iOS Apps (Swift) 关键词摘录

Start Developing iOS Apps (Swift) 关键词摘录

摘抄自苹果开发者网站Start Developing iOS Apps (Swift)。把概念集中在一起,方便日后查阅。

Build a basic UI

  1. App delegate: An object in your app (specifically, an instance of the AppDelegate class) that creates the window where your app’s content is drawn and that provides a place to respond to state transitions within the app.
    Unless you are doing something highly unusual, you should use this class provided by Xcode to initialize your app and respond to app-level events.
  2. Entry point: Where control enters a program or piece of code.
  3. Run loop: An event processing loop that you use to schedule workand coordinate the receipt of incoming events in your app.
  4. Application object: An object in your app that’s responsible for managing the life cycle of the app, communicating with its delegate, the app delegate, during state transitions within the app.
  5. Delegate: An object that acts on behalf of, or in coordination with, another object.
  6. Subclass: A class that’s a child of another class.
  7. Storyboard: A file that contains a visual representation of the app’s UI (user interface), showing screens of content and the transitions between them, that you work on in Interface Builder.
  8. Canvas: The background of a storyboard where you add and arrange user interface (UI) elements.
  9. Scene: A storyboard representation of a screen of content in your app.
  10. Adaptive interface: A user interface (UI) that automatically adjusts so that it looks good in the context of the available screen space.
  11. View: An object that’s used to construct your user interface (UI) and display content to the user. Views have a variety of useful built-in behaviors, including displaying themselves onscreen and reacting to user input. All view objects in iOS are of type UIView or one of its subclasses.
    Views not only display themselves onscreen and react to user input, they can serve as containers for other views.
  12. Auto Layout: Auto Layout is a powerful layout engine that helps you design adaptive layouts that dynamically respond to any changes to the scene’s size.
  13. Stack View: Auto Layout is a powerful layout engine that helps you design adaptive layouts that dynamically respond to any changes to the scene’s size.
  14. Constrain to margin ?

    I was having the same problem and recently resolved the issue by turning off the safe area. Safe Area Layout is enabled by default. To disable Safe Area Layout in Xcode 9, choose View > Utilities > Show File Inspector and deselect the checkbox for Use Safe Area Layout Guides. This should correct the issue. Good luck, hope it helps.



Connect the UI to code

  1. Identity inspector: An inspector that you use to edit properties of an object in a storyboard related to that object’s identity, such as what class the object belongs to.
  2. Outlet: A reference to an object in a storyboard from a source code file. Outlets let you refer to your interface elements in code.
  3. Implicitly unwrapped optional: An optional that can also be used like a nonoptional value, without the need to unwrap the optional value each time it is accessed, because it’s assumed to always have a value after that value is initially set. When you access an implicitly unwrapped optional, the system assumes it has a valid value and automatically unwraps it for you. Note that this causes the app to terminate if the variable’s value has not yet been set.
  4. Action: A piece of code that’s linked to an event that can occur in your app.
  5. Delegate: An object that acts on behalf of, or in coordination with, another object.
    The delegating object keeps a reference to the other object—the delegate—and at the appropriate time, the delegating object sends a message to the delegate. The message tells the delegate about an event that the delegating object is about to handle or has just handled.
    Any object can serve as a delegate for another object as long as it conforms to the appropriate protocol. You adopt a protocol by listing it as part of the class declaration line.
  6. First responder: An object that is first to receive many kinds of app events, including key events, motion events, and action messages, among others.


Work with view controllers

  1. View controllers: An object of the UIViewController class (and its subclasses) comes with a set of methods that manage its view hierarchy. iOS automatically calls these methods at appropriate times when a view controller transitions between states.
  2. Model-View-Controller (MVC): A pattern of app design in which view controllers serve as the communication pipeline between views and the data model.
  3. Data model: The representation or structure of data within an app.
    In this pattern, models keep track of your app’s data, views display your user interface and make up the content of an app, and controllers manage your views. By responding to user actions and populating views with content from the data model, controllers serve as a gateway for communication between the model and views.
  4. Intrinsic content size: The minimum size needed to display all the content in a view without clipping or distorting that content.
    An empty image view doesn’t have an intrinsic content size. As soon as you add an image to a view, its intrinsic content size is set to the image’s size.
    Providing a placeholder size gives the image a temporary intrinsic content size that you can use while designing your user interface.This value is only used while designing your interface in Interface Builder; at runtime, the layout engine uses the view’s actual intrinsic content size instead.
  5. Asset catalog: The asset catalog is a place to store and organize your image assets for an app. 2x is the display resolution for the iPhone 7 Simulator that you’re using in these lessons, so the image will look best at this resolution.
  6. Views & Controls: There’s a nuanced distinction between views and controls, which are specialized versions of views that respond to user actions in a specific way. A view displays content, whereas a control is used to modify the content in some way. A control (UIControl) is a subclass of UIView. In fact, you’ve already worked with both views (labels, image views) and controls (text fields, buttons) in your interface.
  7. Gesture recognizers: An object that you attach to a view that allows the view to respond to actions the way a control does.
    Gesture recognizers interpret touches to determine whether they correspond to a specific gesture, such as a swipe, pinch, or rotation.
  8. Enumeration: The type of imagePickerController.sourceType is known to be UIImagePickerControllerSourceType, which is an enumeration. This means you can write its value as the abbreviated form .photoLibrary instead of UIImagePickerControllerSourceType.photoLibrary. You can use the abbreviated form anytime the enumeration value’s type is already known.
  9. Completion handler: A closure that’s passed as a parameter to a method that calls the closure when it finishes executing.
  10. iOS calls the UIViewController methods as follows:
    1. viewDidLoad()—Called when the view controller’s content view (the top of its view hierarchy) is created and loaded from a storyboard. The view controller’s outlets are guaranteed to have valid values by the time this method is called. Use this method to perform any additional setup required by your view controller.
      Typically, iOS calls viewDidLoad() only once, when its content view is first created; however, the content view is not necessarily created when the controller is first instantiated. Instead, it is lazily created the first time the system or any code accesses the controller’s view property.
    2. viewWillAppear()—Called just before the view controller’s content view is added to the app’s view hierarchy. Use this method to trigger any operations that need to occur before the content view is presented onscreen. Despite the name, just because the system calls this method, it does not guarantee that the content view will become visible. The view may be obscured by other views or hidden. This method simply indicates that the content view is about to be added to the app’s view hierarchy.
    3. viewDidAppear()—Called just after the view controller’s content view has been added to the app’s view hierarchy. Use this method to trigger any operations that need to occur as soon as the view is presented onscreen, such as fetching data or showing an animation. Despite the name, just because the system calls this method, it does not guarantee that the content view is visible. The view may be obscured by other views or hidden. This method simply indicates that the content view has been added to the app’s view hierarchy.
    4. viewWillDisappear()—Called just before the view controller’s content view is removed from the app’s view hierarchy. Use this method to perform cleanup tasks like committing changes or resigning the first responder status. Despite the name, the system does not call this method just because the content view will be hidden or obscured. This method is only called when the content view is about to be removed from the app’s view hierarchy.
    5. viewDidDisappear()—Called just after the view controller’s content view has been removed from the app’s view hierarchy. Use this method to perform additional teardown activities. Despite the name, the system does not call this method just because the content view has become hidden or obscured. This method is only called when the content view has been removed from the app’s view hierarchy.


Implement a custom control

  1. Private methods: Private methods can only be called by code within the declaring class. This lets you encapsulate and protect methods, ensuring that they are not unexpectedly or accidentally called from the outside.
  2. Property observer: A piece of code that’s called every time the value of a property is set. Use property observers to observe and respond to changes in the property’s value.
  3. Accessibility support: When the user runs your app with VoiceOver enabled, when they touch one of the buttons, VoiceOver reads the button’s label, followed by the word button. Then it reads the accessibility value. Finally, it reads the accessibility hint (if any). This lets the user know both the control’s current value and the result of tapping the currently selected button.
    1. Initializer: A method that handles the process of preparing an instance of a class, structure, or enumeration for use, which involves setting an initial value for its properties and performing any other required setup.

      Swift handles initializers differently than other methods. If you don’t provide any initializers, Swift classes automatically inherit all of their super class’s designated initializers. If you implement any initializers, you not longer inherit any of the superclasses initializers; however, the superclass can mark one or more of its initializers as required. The subclass must implement (or automatically inherit) all of the required initializers. Furthermore, the subclass must mark their initializers as required, indicating that their subclasses must also implement the initializers.



Define your data model

  1. Data model: The representation or structure of data within an app.
  2. Implicitly unwrapped optional: An optional that can also be used like a nonoptional value, without the need to unwrap the optional value each time it is accessed, because it’s assumed to always have a value after that value is initially set.
  3. Unit test: A piece of code written specifically to test a small, self-contained piece of behavior in your app to make sure it behaves correctly.


Create a Table view

  1. Mutable: A value that is able to be changed (or mutated) after it’s initialized, like a variable.
  2. Downcast: To attempt to cast an object to one of its subclass types.


Implement Navigation

  1. Segue: A transition from one scene to another in a storyboard.
  2. Navigation controller: A specialized view controller subclass that manages transitions backward and forward through a series of view controllers.
  3. Navigation stack: The set of view controllers managed by a particular navigation controller.
  4. Root view controller: The first item added to a the navigation stack of a navigation controller. The root view controller is never popped off (removed from) the stack.
  5. Unwind segue: A type of segue used to implement backward navigation.
  6. Source view controller: The view controller whose contents are displayed at the beginning of a segue.
  7. prepare(for:sender:): Whenever a segue gets triggered, it provides a place for you to add your own code that gets executed. This method is called prepare(for:sender:), and it gives you a chance to store data and do any necessary cleanup on the source view controller.
  8. Identity operator: An operator (===) that tests whether two object references both refer to the same object instance.
  9. NIl Coalescing Operator (??): An operator (??) placed between two values, a ?? b, that unwraps an optional a if it contains a value, or returns a default value b if a is nil.
  10. Destination View Controller:The view controller whose contents are displayed at the end of a segue.
  11. Optional Type Cast Operator: An operator (as?) that attempts a downcast and returns the result as an optional value.


Persist Data

  1. Base Class: A class that’s at the root of its class hierarchy, meaning that it has no superclass.
  2. Convenience: The convenience modifier means that this is a secondary initializer, and that it must call a designated initializer from the same class. As a convenience initializer, this initializer is required to call one of its class’s designated initializers before completing. As the initializer’s arguments, you pass in the values of the constants you created while archiving the saved data.

猜你喜欢

转载自blog.csdn.net/twllx/article/details/79266475
今日推荐