[iOS]Start Developing iOS Apps (Swift)- 学习笔记

  • 官方入门教程
    已经看完一遍了。学习耗时大概在5~6小时

Main Topic


XCode工具描述

9F5C183E8CB48EE3E24E03C854F3D003.png
  • Navigator area(导航区域)
    此区域包含代码目录结构、类结构、搜索代码、build信息、debug断点等
  • Toolbar(工具栏)
    一些模拟器信息现在在这个区域
  • Editor area(编辑区域)
    代码、ui编辑区域
  • Utility area(属性工具区域)
    不同文件会有不同属性

核心文件基本说明

  • AppDelegate
    • 创建App window详细描述见下面
      It defines your AppDelegate class. The app delegate creates the window where your app’s content is drawn and provides a place to respond to state transitions within the app.
    • App入口类,提供一个run loop监控用户输入
      It creates the entry point to your app and a run loop that delivers input events to your app. This work is done by the UIApplicationMain attribute (@UIApplicationMain), which appears toward the top of the file.
  • ViewController
    从UIViewController继承下来的class,主要定义UI行为。
    • lifecycle后续补充
  • Storyboard(场景)
    这个文件类型,定义UI页面(类似android的xml定义ui展示,不过功能更加强大)
    • Canvas(幕布)
      场景(页面)可以定义在这里面
    • Scene
      理解成一个页面或场景。可以在里面添加各种UI组件,Navi行为等
      • 添加方法(choose View > Utilities > Show Object Library,选择一个control,拖拽到canvas空白区域就可以创建一个Scene)
      • 一个Scene对应一个Control源码(这是iOS VM设计模式),可以自己选择相应的ViewControl代码


        DCA07A47F7C009028A56027CA117E4B7.png

        FA74153B49DC0E3627EBCCC12136D0A6.png
      • Outlets
        将Scene与source code关联起来
      • Action
        将Scene里面的组件的行为和代码关联起来
      • Navi
        定义页面跳转行为
      • Delegate
        处理用户输入。通过代理类方式例如:UITextFieldDelegate
  • Assets.xcassets
    • 定义图片资源
      link
  • Info.plist
    • 定义权限,项目配置等
  • ViewController
    基类是UIViewController,基本上所有ViewController都是从它继承而来,在里面初始一个Scene的基本展示流程。
8DBD58D7B830402462D9708ACBBFD01D.png
* viewDidLoad()—Called when the view controller’s content view (the top of its view hierarchy) is created and loaded from a storyboard. 
* viewWillAppear()—Called just before the view controller’s content view is added to the app’s view hierarchy. 
* viewDidAppear()—Called just after the view controller’s content view has been added to the app’s view hierarchy.
* viewWillDisappear()—Called just before the view controller’s content view is removed from the app’s view hierarchy.
* viewDidDisappear()—Called just after the view controller’s content view has been removed from the app’s view hierarchy.

基本内容

  • Custom Control
    link
    • 定义View代码文件,基类UIView
      重写一些核心方法,一些logic处理
    • CustomView显示UI
      • storyboard里面定义view
      • 绑定viewcode,在Identity inspector里面关联相应的View代码。
D2022E2A02ED8D08148035A37F8A1643.png
  • Navigation
    页面跳转
    • Navigation Controller
      • 添加 Choose Editor > Embed In > Navigation Controller.
      • 修改Navigation Bar
        可以修改名字,导航button等
    • Segue
      • 页面跳转模式(Push\Modal\Custom)
      • 处理segue的方法
        override func prepare(for segue: UIStoryboardSegue, sender: Any?)处理Segue事件
        segue.destination可以找到目标对象Viewcontrol进行数据传输
  • Persist Data(数据持久化)
    • NSCoding方案
      • 建立PropertyKey
      • 持久化路径
        static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
        static let ArchiveURL = DocumentsDirectory.appendingPathComponent("meals")
      • 编解码
        encode(with aCoder: NSCoder)/init?(coder aDecoder: NSCoder)
      • 保存NSKeyedArchiver.archiveRootObject(meals, toFile: Meal.ArchiveURL.path)
      • 读取NSKeyedUnarchiver.unarchiveObject(withFile: Meal.ArchiveURL.path) as? [Meal]

你可能感兴趣的:([iOS]Start Developing iOS Apps (Swift)- 学习笔记)