【周报】2020.03.16-2020.03.22

262 阅读4分钟

class

  1. NSPersistentStore

Core Data provides four store types—SQLite, Binary, XML, and In-Memory (the XML store is not available on iOS); these are described in Persistent Store Features. Core Data also provides subclasses of NSPersistentStore that you can use to define your own store types: NSAtomicStore and NSIncrementalStore. The Binary and XML stores are examples of atomic stores that inherit functionality from NSAtomicStore.

  1. AVAssetExportSession

对象转码以及输出,对一个AVAsset对象进行操作,用来做视频处理输出。

  1. UINavigationBarAppearance

An object for customizing the appearance of a navigation bar.

protocol

  1. OptionSet

如何创建你自己的选项集合类型呢?仅有的要求是,一个类型为整型的原始值(rawValue)和一个初始化构造器。

struct Sports: OptionSet {
    let rawValue: Int

    static let running = Sports(rawValue: 1)
    static let cycling = Sports(rawValue: 2)
    static let swimming = Sports(rawValue: 4)
    static let fencing = Sports(rawValue: 8)
    static let shooting = Sports(rawValue: 32)
    static let horseJumping = Sports(rawValue: 512)
}

现在,你可以创建选项集合了,就像这样:

let triathlon: Sports = [.swimming, .cycling, .running]
triathlon.contains(.swimming)  // → true
triathlon.contains(.fencing)   // → false

遵从 OptionSet 并不意味着遵从 Sequence 和 Collection 协议,所以你无法使用 count 来确定集合中有几个元素,也无法使用 for 循环来遍历选择的选项。从根本上说,一个选项集合仅仅是简单的整数值。

  1. UITraitEnvironment

A set of methods that makes the iOS interface environment available to your app.

iOS接口环境包括诸如横向和纵向尺寸、显示比例和用户界面习惯用法等。要访问遵守此协议的对象的trait环境,请使用traitCollection属性。该协议还提供了一种当接口环境发生变化时被系统调用的可覆盖方法。实现此方法作为创建自适应iOS应用程序的一部分。

  1. UIViewControllerTransitioningDelegate

A set of methods that vend objects used to manage a fixed-length or interactive transition between view controllers.

通过设置代理,实现代理方法,可以自定义转场动画。

  1. CustomStringConvertible

在调试的时候总会发现在输出自定义的类与结构体时,会打印很多不想输出的变量,这就有了 CustomStringConvertible,CustomDebugStringConvertible 这两个协议的用处。

struct Person:CustomStringConvertible,CustomDebugStringConvertible {
    var age: Int
    var name: String
    var job: String
    
    var description: String {
        return "\(age) \(name) \(job)"
    }
    
    var debugDescription: String {
        return "\(name) \(age) \(job)"
    }
}

let meetings = Person(age: 24, name: "haha", job: "iOSDeveloper")
print(meetings)
/**
 *  "24 haha iOSDeveloper\n"
 */
debugPrint(meetings)
/**
 *  "haha 24 iOSDeveloper\n"
 */
  1. Equatable

可以使用等于运算符(==)比较符合Equatable协议的类型是否相等,或者使用等于运算符(!=)比较不相等的类型。 Swift标准库中的大多数基本类型都符合Equatable。

extension StreetAddress: Equatable {
    static func == (lhs: StreetAddress, rhs: StreetAddress) -> Bool {
        return
            lhs.number == rhs.number &&
            lhs.street == rhs.street &&
            lhs.unit == rhs.unit
    }
}

object

  1. childForStatusBarStyle

Called when the system needs the view controller to use for determining status bar style.

  1. modalPresentationCapturesStatusBarAppearance

指定非全屏显示的视图控制器是否从显示的视图控制器接管状态栏外观的控制。

当你present一个VC的时候,被present的VC的 preferredStatusBarStyle 不会工作(尽管它会是 visibleViewController )。你必须在present前设置:

vc.modalPresentationCapturesStatusBarAppearance = true
  1. setAutocorrectionType

The autocorrection style for the text object.

  1. barTintColor

The tint color to apply to the navigation bar background.

  1. isTranslucent

如果设置为 true,那么导航栏会是半透明的,view 的 y 值也会从 0 开始而不思从 navigation bar 的底部开始

function

  1. configureWithTransparentBackground()

Configures the bar appearance object with a transparent background and no shadow.

keywords

  1. @inline(__always)

在编程中,函数内联 是一种编译器优化技术,它通过使用方法的内容替换直接调用该方法,就相当于假装该方法并不存在一样,这种做法在很大程度上优化了性能。

  1. @dynamicMemberLookup

这个特性中文可以叫动态查找成员。在使用 @dynamicMemberLookup 标记了对象后(对象、结构体、枚举、protocol),实现了 subscript(dynamicMember member: String) 方法后我们就可以访问到对象不存在的属性。如果访问到的属性不存在,就会调用到实现的 subscript(dynamicMember member: String) 方法,key 作为 member 传入这个方法。

link

Swift 中的选项集合

NSPersistentStore

UITraitEnvironment Protocol

WWDC 2014 Session笔记 - iOS界面开发的大一统

WWDC 2013 Session笔记 - iOS7中的ViewController切换

Swift标准库协议--CustomStringConvertible协议

为 Swift 的协议实现 Equatable

让preferredStatusBarStyle真的工作(iOS 10以后)

Kingfisher源码解析之ImageCache

Color Assets (.xcassets) in Xcode.

iOS 导航栏对控制器view的影响

Swift 里的强制 @inline 注解

细说 Swift 4.2 新特性:Dynamic Member Lookup