versions-kit 1.8.0

versions-kit 1.8.0

Astemir Eleev 维护。



  • Astemir Eleev

versions-kit Awesome

Platforms Language CocoaPod Build Status Coverage License

最后更新:2019年5月18日。

如果您喜欢该项目,请给它点一个星⭐,这将显示您对创作者的感激之情,并帮助其他人发现该仓库。

✍️关于

📦收集用于各种用例的 Swift 扩展(+自定义类型)。套件包含 200 个扩展和 24 个自定义类型。

🏗安装

CocoaPods

versions-kit 通过 CocoaPods 提供

pod 'extensions-kit', '~> 1.8.0' 

手动

您始终可以使用 复制粘贴 源代码的方法😄或者,您可以编译框架并将其包含到项目中。

✏️注释

在打开任何新问题或“燃烧”此仓库之前,请阅读以下注释🔥😅:

  • 在技术上,您可以直接重用大多数针对macOS、watchOS和tvOS的扩展,即使这些操作系统没有直接支持。
  • 请注意,这个框架最初是为专有项目开发的,后来决定开源。虽然它尚未完成,但它确实提供了一些价值。那些被单元测试覆盖的部分,实际上已经在实际项目中得到了广泛使用。
  • 许多展示的扩展都是实验性的。它们代表了开发当时的观点。它们可能不符合您自己的做事方式,或者可能存在一些问题。请保持礼貌和专业,如果发现问题,请通过创建新问题或搜索现有问题来描述您的问题。
  • 最好的帮助方式是通过实现修复/功能/附加功能和打开池请求来贡献。

🗺路线图

  • 添加对TravisCI的支持
  • 添加对Codecov的支持
  • 移除非iOS扩展(AppKit
  • 添加文档生成支持
  • 添加单元测试覆盖率并保持高水平
  • 为框架添加文档和示例代码

🍱分类

分类列表,方便导航。数字代表每个类别的扩展总数+自定义类型。每个扩展文件可以包含多个扩展,按类别分组。

📚扩展列表

所有扩展都分为单独的,每组代表一个单独的SDK框架

AppKit

NSBezierPath

NSBezierPath+cgPath

添加了缺少的cgPath属性,该属性可以将self(从iOS中移植类似功能)转换为路径。

let path = bezierPath.cgPath
// path is of type CGPath and can be used in a shared code with iOS, tvOS or watchOS targets

AVFoundation

AVCaptureDevice+ToggleFlash

添加了轻松管理手电筒的支持

AVCaptureDevice.toggleFlashlight(with: .max)

Core Animation

CAAnimation

CAAnimation+PatternReplicator

为指定图像、层大小和其他属性创建基于图案的波浪动画

CAAnimation.patternReplocator(with: UIImage("image"), size: CGSize(width: 600, height: 600), targetLayer: drawerView.layer)

Core Graphics

CGSize

CGSize+Operators

为了方便使用,提供了各种数学运算符,如 +-*/

CGSize(width: 10, height: 20) + CGSize(width: 25.4, height: 23.6)
CGSize(width: 10, height: 20) - CGSize(width: 25.4, height: 23.6)
CGSize(width: 10, height: 20) * CGSize(width: 25.4, height: 23.6)
CGSize(width: 10, height: 20) / CGSize(width: 25.4, height: 23.6)

CGPoint

CGPoint+Operators

提供了诸如 +-*/lerp 等各种数学运算符。

var origin: CGPoint = .zero
let addPoint = origin + CGPoint(x: 10, y: 3)
origin += CGPoint(x: 12, y: 5)
let subPoint = origin - CGPoint(x: 12, y: 5)
        
let interpolatedPoint = CGPoint.lerp(start: pointOne, end: pointTwo, t: 2)

CGPoint+Utils

缺少数学实用程序,如 normalizedlengthdistanceToangle

let point = CGPoint(x: 3, y: 5)
let _ = point.length()
let _ = point.angle
let _ = point.normalized()
let distanceBetweenTwoPoints = point.distanceTo(anotherPoint)
let _ = point.lengthSquared()

CGRect

CGRect+Scale

self 缩放至指定大小。

let rect = CGRect(origin: .zero, size: CGSize(width: 100, height:
            200))
let newSize = rect.scaled(to: targetSize)

CGRect+Corners

添加了 topLeft(左上角)、topRight(右上角)、bottomLeft(左下角)和 bottomRight(右下角)的点属性

let rect = CGRect(origin: .zero, size: CGSize(width: 100, height:
            200))
rect.topLeft
rect.topRight
rect.bottomLeft
rect.bottomRight

CGRect+Mid

selfmid 点添加了属性

let rect = CGRect(origin: .zero, size: CGSize(width: 100, height:
            200))
rect.mid

CGRect+AspectFit

添加了 aspectFit(inRect: CGRect) -> CGRect 方法,该方法将 self 缩放到指定的 CGRect

let rect = CGRect(origin: .zero, size: CGSize(width: 100, height:
            200))
rect.aspectFit(inRect: targetRect)

CGFloat

CGFloat+Rounded

self 四舍五入到指定的小数位

let val: CGFloat = 4.32
let roundedVal = val.rounded(toPlaces: 1) // roundedVal holds `4.3`

CoreImage

新滤镜

高亮过滤器

该过滤器最初是为突出显示3D对象而设计的,但也可以用于将此效果添加到图像和精灵上。

CIImage

CIImage+Inverted

反转self的颜色

let invertedImage = ciImage.inverted
// invertedImage holds the same image data but with inverted colors

CIImage+QRImage

从输入的text生成QR图像,并带有可选的scale参数,该参数指定输出CIImage的仿射变换

let helloWorldQRImage = CIImage.qrImage(from: "Hello World!")
// helloWorldQRImage holds image data that represents QR code for `Hello World!` message

CIImage+Tinted

将指定的color应用于渐变色

let redQRImage = qrImage.tinted(by: .red)
// redQRImage holds the same QR image data as before but tinted by red color

CIImage+Transparent

一系列扩展,通过应用alpha遮罩过滤器,将目标CIImage实例转换为透明版本

let transparentImage = ciImage.transparent
let blackTransparentImage = anotherImage.blackTransparent

基础

NSObject协议

NSObjectProtocol+KVO+KVC

轻松观察和绑定观察者

// Binding is as easy as writing just a single line of code:
viewModel.bind(\.progressSlider, to: progressSlider, at: \.value)

// Observing for changes is thinner than the `Swifts 4.0` updated `KVO`:
viewModel.observe(\.buttonTitle) { [button] in
        button!.setTitle($0, for: .normal)
}

自定义协议

Identifiable

该协议适用于需要标识的类型,如UITableViewCell、UITableViewHeaderFooterView、UICollectionReusableView等。

class FeedTableViewCell: UITableViewCell, Identifiable {
       // ... 
       // Implementation details
       // ... 
}

// Somewhere in `UITableViewControllerDelegate`:
let cell = dequeueReusableCell(withIdetifier: cell. reuseIdentifier)

Then

对象配置协议

var imageView = UIImageView().then {
        $0.layer.cornerRadius = 10
        $0.contentMode = .scaleAspectFill
        $0.clipsToBounds = true
}

自定义类型

Variable

轻量级的可绑定数据类型,允许在值更新时接收通知。可以与MVVM或任何其他设计模式一起使用,以取代对第三方、重量级绑定框架的需求

let stringVariable = Variable("Initial Value")
let newValue = "New Value"
stringVariable.value = newValue

stringVariable.onUpdate = {
        let isEqual = $0 == newValue
        XCTAssert(isEqual)
}

Debouncer

允许在延迟后执行动作

let debouncer = Debouncer(delay: 2.0)
debouncer.schedule {
        value = "Changed Value"            
}
// After 2.0 seconds the value will be changed to "Changed Value"

ObservableArray

同步、线程安全的可观察数组类型

let array: ObservableArray = [1,2,3,4,5]
array += 6
array += [7,8]

array.allChanges = { change in
        // Both changes will, for addition of `6` and `[7,8]` will be reflected in `change` property and the appropriate callbacks will be made
}

array.removeFirst()
array.removeLast()
array.remove(at: 4)

自定义文本输出流

FileOutputStream

将输出流打印到指定的文件,给定 URL编码

let url = URL(fileURLWithPath: "/somePath/subpath/file.rtf")
let fileHandle = try FileHandle(forWritingTo: url)
var textOutputStream = TextOutputStream(fileHandle)

print("\(outputString)", &textOutputStream)
// The print statement will write the output stream to the specified FileHandle at the specified URL. This stream mimics Java's SDK File Output Stream. 

使用以下方案打印所有 Unicode 字符

var unicodeOutputStream = UnicodeOutputStream()
print("👨‍👩‍👧‍👧", to: &unicodeOutputStream)

// Will print all the unicode indices + characters + names

函数

函数组合

实现函数组合概念的多个函数,允许将多个函数组合起来并链接使用,以转换数据。考虑以下结构:(doubleNumbers ->> squareNumbers ->> convertToStringArray)(array),它通过线性组合函数(而不是嵌套函数调用)返回经过处理的数据。另外,扩展还包括按相反顺序组合函数的 reversed 操作符。

func double<T: Numeric>(array: [T]) -> [T] {
        return array.map { $0 * 2 }
}
        
func square<T: Numeric>(array: [T]) -> [T] {
        return array.map { $0 * $0 }
}
        
func toStringArray<T: Numeric>(array: [T]) -> [String] {
        return array.map { "\($0)" }
}

let data = [1,2,3,4,5]
let newData = (double ->> square ->> toStringArray)(data)        
// newData now equals to ["4", "16", "36", "64", "100"]

数据结构

Builder协议

使用Keypath特性允许扩展AnyObject以具有链式初始化方法。请注意,此扩展仅从Swift 4.0开始工作。

// 1. Add conformance to BuilderProtocol
extension Song: BuilderProtocol { /* empty implementation */ }

// 2. Then you can use Key-Path builder approach:
let song = Song()
        .init(\.author,         with: author)
        .init(\.name,           with: name)
        .init(\.genre,          with: genre)
        .init(\.duration,       with: duration)
        .init(\.releaseDate,    with: releaseDate)

透镜

透镜是函数透镜概念的一种实现,允许安全地修改不可变的structs,并提供处理复杂数据结构的工具(见UnitTests)。

extension Actor {
    struct Lenses {
        static let name = Lens<Actor, String>(
            get: {$0.name},
            set: {(me, value) in Actor(name: value, surname: me.surname) }
        )
        static let surname = Lens<Actor, String>(
            get: {$0.surname},
            set: {(me, value) in Actor(name: me.name, surname: value) }
        )
    }
}

extension Movie {
    struct Lenses {
        static let mainActor = Lens<Movie, Actor?>(get: { movie in
            let actor: Actor? = movie.actors.first
            return actor
        }, set: { me, actor -> Movie in
            guard let actor = actor else { return me }
            
            return Movie(name: me.name, year: me.year, actors: [actor] + me.actors)
        })
    }
}

对象池

对象池设计模式的线程安全实现

let objectPool = ObjectPool(objects: [resource, anotherResource, thirdResource])
let reusedResource = objectPool.dequeue()
objectPool.enqueue(object: reusedResource)
objectPool.eraseAll()

观察者

线程安全的 Observer 设计模式实现(不要与 NotificationCenter 混淆——它是 发布-订阅 模式的实现)

let observerOne = ObserverOne()
var observerTwo: ObserverTwo? = ObserverTwo()
let observerThree = ObserverThree()

let subject = Subject()
subject += [observerOne, observerTwo!, observerThree]

subject ~> EmailNotification(message: "Hello Observers, this messag was sent from the Subject!")

// Will produce the following output:
// 
// Observer One:  data: Optional("Hello Observers, this messag was sent from the Subject!")
// Observer Two:  data: Optional("Hello Observers, this messag was sent from the Subject!")
// Observer Three:  data: Optional("Hello Observers, this messag was sent from the Subject!")

多播委托

非线程安全的 MulticastDelegation 设计模式实现

// Create the view controllers that will be delegates
let containerViewController = ContainerViewController()
let profileViewController = ProfileViewController()

let profileModel = ProfileModel()

// Attach the delegates
profileModel.delegates.add(delegate: containerViewController)
profileModel.delegates.add(delegate: profileViewController)

// Change the model
profileModel.name = "John"

// After changing `name` property we got the following in console:
// ContainerViewControllers:  didUpdate(name:)  value:  John
// ProfileViewController:  didUpdate(name:)  value:  John

// Assume that we needed to remove one of the delegates:
profileModel.delegates.remove(delegate: profileViewController)

// And again update the model:
profileModel.city = "New York"
// This time the console outputs is the following:
// ContainerViewControllers:  didUpdate(city:)  value:  New York

// We again attach ProfileViewController
profileModel.delegates.add(delegate: profileViewController)

// Custom closure that is called outside of the model layer, for cases when something custom is required without the need to touch the original code-base. For instance we may implement this function in our view-model layer when using MVVM architecture
profileModel.delegates.update { modelDelegate in
    modelDelegate.didSave()
}

Stack 数据结构的实现

var stack: Stack = [1,2,3,4,5,6,7,8,1]
let lastElement = stack.pop()
stack.push(element: 10)

队列

Queue 数据结构的实现

var queue: Queue = [1,2,3,4,5,6,7,8,1]
queue.enqueue(element: 9)
let dequeuedElement = queue.dequeue()

优先队列

基于 Heap 数据结构的 Priority Queue 数据结构实现

var queue = PriorityQueue<Int>(elements: [2, 1, 4, 3, 5], order: >)
queue.enqueue(9)

双端队列

Dequeue 数据结构的实现

var dequeue = Dequeue([1,2,34,5,6,7])
let back = dequeue.dequeueBack()
let front = dequeue.dequeueFront()

dequeue.enqueue(front: 99)
dequeue.enqueue(back: 99)

LinkedList

是数据结构 链表 的实现

var list: LinkedList = [1,2,4,5]
list.pop()

var newList = LinkedList<Int>(sequence: list)
newList.pop()

DoublyLinkedList

是数据结构 双链表 的实现

var list: DoublyLinkedList = [1,2,4,5,6,7]
list.head
list.tail

list.removeHead()
list.removeTail()

list.push(newHead: 99)
list.push(newTail: 101)

Heap

是数据结构 的实现

var maxHeap = Heap<Int>(order: >)
maxHeap.insert(node: 1)
maxHeap.insert(node: 5)
maxHeap.insert(node: 2)
maxHeap.insert(node: 7)
maxHeap.insert(node: 9)

maxHeap.index(of: 3)
let sortedHeapmaxHeap.sorted()

Extensions

Array

Array+Filtering

包含一系列以 函数式风格 进行过滤的方法,有 skipallany 过滤器

let result = [1,2,3,4,5,6,7,8,9,10].skip(5)
// result array contains all the elements except the first 5 e.g. [6,7,8,9,10]

let result = [1,2,3,4,5,6,7,8,9,10].all { $0 < 20 }
// result will be true since all the elements are less than 20

let result = [1,2,3,4,5,6,7,8,9,10].any { $0 < 5 }
// result will be true since there are a number of elements that are less than 5

Array+Contains

检查是否包含指定的元素

let result = [1,2,4,5,6,7,8,9,10].contains(elements: 1,2,4,5)
// result will be true since the target array contains all the specified elements

let result = [1,2,4,5,6,7,8,9,10].contains(elements: 9,10,11,12)
// result will be false since the target array does not contain 11 and 12

Array+Difference

计算self与输入数组之间的差异

let testA = [1,2,3,4,5]
let testB = [4,5,7,8,9]

let result = testA.difference(elements: testB)
// result will be [1,2,3]

let result = testB.difference(elements: testA)
// result will be [7,8,9]

Array+Intersection

计算self与输入值之间的交集

let testA = [1,2,3,4,5]
let testB = [4,5,6,7]

let result = testA.intersection(values: testB)
// result will be [4,5]

Array+Union

合并self和输入数组

let result = [1,2,4,5,6,7,8].union(value: [8,9,10])
// result will be [1, 2, 4, 5, 6, 7, 8, 9, 10]

Array+Remove

一组通过修改来移除Element的方法

var test = [1,2,3,4,5,6,7,8]

test.remove(object: 8)
// test contains the following elements [1,2,3,4,5,6,7]

test.remove(objects: [1,2,4])
// test contains the following elements [3,5,6,7]

test.remove(objects: 5,6)
// test contains the following elements [3,7]

Array+InsertionSort

支持插入排序算法

Array+MergeSort

支持归并排序算法

Array+QuickSortHoareScheme

添加了对使用 Hoare 分区方案的 Quick Sort 算法的支持

Array+QuickSortLomutoScheme

添加了对使用 Lomuto 分区方案的 Quick Sort 算法的支持

Array+BubbleSort

添加了对 Bubble Sort 算法的支持

Array+ShellSort

添加了对 Shell Sort 算法的支持

Array+RadixSort

添加了对 Radix Sort 算法的支持

Bool

Bool+Int

添加一个属性,返回 self 的 Int 表示形式

Bool+Random

添加 self 的随机属性

ClosedRange

ClosedRange+Random

添加一个属性,根据 self 生成随机 Int

Collection

Collection+ParallelIteration

添加 parallelForEach 方法

Collection+RandomItem

增加一个属性,用于从self返回一个随机元素

Collection+Sum&Average

增加两个属性sumaverage及其对应功能

Collection+SafeSubscript

安全检查集合是否能够根据给定索引检索元素,否则返回nil

RandomAccessCollection

RandomAccessCollection+BinarySearch

二分查找算法实现

Decodable

Decodable+DecodeFromFile

将文件解码为类型

// User is a .json file containing the following data:
// {
//    "name":"Willy",
//    "age":30
// }

let decodedUser = try? User.decodeFromFile(named: "User")
// decodedUser will be a Decodable struct named User with two properties for name and age

Dictionary

Dictionary+GetOrAddValue

将self解析为JSON到Data或String

Dictionary+JSON

检查给定键的值或如果未找到则创建新键值对

Dictionary+ConvenienceWrappers

为如has(key: )->Booleach(: (Key, Value)->())的常见操作添加包装器

Dictionary+Difference

计算self与输入字典之间的差异

Dictionary+Intersection

计算自身与输入字典的交集

Dictionary+Map

自定义映射函数

Dictionary+Union

将自身与输入字典合并

Double

Double+Rounded

self四舍五入到小数位

Double+CurrencyShortcuts

将常见的货币快捷方式作为属性添加

日期

Date+FirstLast

添加多个属性,允许快速访问:一周的第一天一天的开始一天的结束以及一个月的天数

Date+PreviousNext

添加属性,允许访问前天后天

Float

Float+Rounded

self四舍五入到小数位

Int

Int+Clamp

将 self 范围限制在可以使用 ClosedRange 或两个独立属性描述的范围内

Int+Digits

添加了一个名为 digitCount 的属性,该属性包含 self 的数字位数

Int+EvenOdd

检查 self 是偶数还是奇数

Int+Factorial

计算 self 的阶乘

Int+Power

执行指数运算的操作符,其中左边的数字是底数,右边的数字是指数

Int+Random

生成一个范围可在 ClosedRange 或两个独立的 Int 属性中指定的伪随机数

Int+Roman

self 转换为 罗马数字(作为 String

Int+DecimalToBinary

允许将十进制数转换为二进制格式以及相反操作

OptionSet

OptionSet+Operations

支持就地 insertremove 操作

MutableCollection

MutableCollection+Shuffle 就地对 self 进行列表打乱

Sequence

Sequence+Shuffle

随机打乱 self 的元素

Sequence+Count

计算一个逻辑表达式出现的次数

Sequence+DuplicatesRemoved

移除重复元素,如果存在重复则返回不带重复的新 Sequence

String

String+Subscript

CoutableClosedRangeCountableRangePartialRangeThroughPartialRangeFrom 协议添加符合性,支持以索引的形式进行操作

String+Digits

将十进制数字合并为单个 String 属性

String+FormattedDate

从指定的格式根据self创建一个Date实例

String+IndexOf

查找给定的第一个出现位置

String+Base64

将self编码/解码为Base64编码

String+Validation

包含一系列基于以下条件的String验证扩展:isAlphanumerichasLettershasNumbersisEmailisAlphabetic

NSObject

NSObject+ClassName

允许获取确切的类名

let className = Foo.nameOfclass
// className property holds `Foo`

Notification Center

Notification Center+PostUtils

各种实用扩展,帮助减少样板代码

NotificationCenter.post(notification: .userHasUpdated)

Operation Queue

Operation Queue+MainUtils

.main操作队列提供的实用扩展

OperationQueue.isMain // if current operation queue is the main the result will be true, otherwise false
OperationQueue.onMain {
        // This closure will be executed on the main operation queue
}

URL

URL+QRImage

URLabsoluteString创建QR图像

let customUrlQRImage = url.qrImage()
// customUrlQRImage holds image data for QR image that represents the given URL address

UIKit

徽章

Badge

一个自定义类型,包装徽章应用程序图标 API,简化开发

UIScreen

UIScreen+InterfaceOrientation

当前 UIScreen 的界面方向

UIApplication

UIApplication+SafeAreas

包含扩展,允许获取 topbottom 安全区域的数值表示

NSLayoutConstraint

NSLayoutConstraint+Animation

animated 标志设置为 true(默认为 false)时,允许约束进行动画处理

NSLayoutConstraint+Activation

设置激活 布局优先级添加便捷方法

UIView

UIView+CACorners

用于设置和获取圆角的便捷扩展

UIView+BezierRoundedCorners

另一种用于圆角的扩展

UIView+HuggingPriority

简化 setContentHuggingPrioritysetContentCompressionResistancePriority 方法接口的便捷包装器

UIView+Screenshot

允许获取自身的截图

UIView+Constraints

添加方便的自动布局方法,允许通过代码 pinadd、获取高度宽度以及获取特定UIView的所有约束。

UIView+LayoutAnimation

添加操作布局约束的动画扩展

UIView+Masking

通过指定的UIRectCorner数组和圆角将视图进行遮罩

let view = UIView()
view.mask(corners: .allCorners, with: 10)

UIColor

UIColor+ColorComponents

添加了对缺失的颜色分量属性(如 rgbahsbagrayscale)的支持

UIColor+Blend

通过混合RGBA组件将两种颜色混合

let blendedColor = red.blend(with: blue, intensity: 0.5)

UIColor+Brightness

改变颜色的亮度

let brighterRed = red.increaseBrightness(0.25)

UICollectionView

UICollectionView+CustomCellRegistration

UICollectionView实例注册自定义的UICollectionViewCell。需要将UICollectionViewCell定位到当前 Bundle

UICollectionView+ScrollingUtils

添加能够允许程序性滚动到表格视图的顶部、底部或指定索引路径的方法

UICollectionView+Safety

添加验证工具

UICollectionView+Operations

为项目索引集合提供方便的 reloaddeleteinsert 操作

UITableView

UITableView+FooterHeaderUtils

扩展添加了用于处理 FooterHeader 视图的方便助手

UITableView+ScrollingUtils

添加能够允许程序性滚动到表格视图的顶部、底部或指定索引路径的方法

UITableView+Safety

添加验证工具

UIImage

UIImage+Downsample

将输入图像下采样到指定的尺寸和比例因子。可用于展示缩略图,支持缓存

let downsampledImage = UIImage.downsample(imageAt: url, to: targetSize)
// downsampledImage stores a `UIImage` instance that was cached and downsized to the `targetSize`

UIImage+ImageFromUIView

UIView渲染为UIImage

UIImage+LandscapeCameraOrientationFix

修正使用横向界面方向通过AVFoundation捕获图像时的图像方向

UIImage+RawOrientation

原始图像方向(从UIImageOrientationInt32

UIImage+Resize

类级别扩展,允许根据期望的图像宽度或/和高度调整输入图像的大小

UIImage+SolidColor

从颜色数据和尺寸创建UIImage

UIImage+Inverted

添加了一个属性,返回self的倒影副本

UIImageView

UIAlertController

UIAlertController+Presentation

显示一个带有给定标题、消息、tintColor和警报操作的UIAlertController

UIAlertController.present(with: "Warning!", and: "The item will be deleted", from: targetViewController) { () -> [UIAlertAction] in
        let deleteAction = UIAlertAction(title: "Delete",
                                         style: .destructive,
                                         handler: { (action) in
                // Callback handling
        })
            
        let cancelAction = UIAlertAction(title: "Cancel",
                                         style: .cancel,
                                         handler: { (action) in
                // Callback handling
        })
            
        return [deleteAction, cancelAction]
}

UIViewController

UIViewController+ContainerController

加载、添加和移除容器视图控制器作为子控制器

UIViewController+ChildViewControllers

添加了添加和移除子视图控制器的便捷方法

UIViewController+Storyboard

使用视图控制器的名称作为Storyboards的引用名称,从Storyboard中实例化一个UIViewController实例。用于实现CoordinatorFlow设计模式的情况。

// Instantiation of a view controller by explicitly setting the storyboard and identifier
let loginViewController = UIViewController.instantiateController(from: mainStoryboard, identifier: "LoginViewController")

// An another way to instantiate a UIViewController instnace: here the identifier will be the class name
let viewController = UIViewController.instantiateController(from: mainStoryboard)

UIWindow

UIWindow+Instantiate

简化了UIWindow实例化的语法

window = UIWindow.create(with: coordinator.rootViewController, option: .keyAndVisible)

os

OSLog

OSLog+LogLevels

增加了一些方便的日志级别和一个简化日志的全球函数

os_log("Received .json data from the remove", log: .network)
os_log("Attempting to sync with the main UI thread", log: .ui)

SpriteKit

SKTimingFunction

增加了36个不同的计时函数

SKEmitterNode

SKEmitterNode+AdvanceSimulation

安全地向前推进给定 TimeInterval 的粒子仿真

SKSpriteNode

SKSpriteNode+GIF

支持从本地文件上传和播放 GIF 图片

SKScene

SKScene+SerialSpriteLoading

上传一组具有特定模式的图节点,当场景中包含大量节点,但只需要处理或访问特定子集时非常有用

SKScene+ReferenceNodeFix

一个小修复,解决了从不同的 .sks 文件引用的节点默认行为的问题。问题在于它们默认不会启动它们的动画,所以这个小 hack 解决了这个问题

SKTexture

SKTexture+LinearGradient

添加了一个便利的初始化器,用于生成指定 大小开始结束 颜色的 渐变纹理

SKTextureAtlas

SKTextureAtlas+FramesLoader

从纹理图集中上传动画序列,并返回一个可以被进一步使用的纹理数组

SceneKit

SCNVector3+Operators

SCNVector3 类型添加了各种数学运算符的支持

SCNAction+MoveAlong

扩展添加了一个新的动作方法,允许节点沿一个 UIBezierPath 移动

let flyoverAction = SCNAction.moveAlong(path: flyoverPath, z: 10, speed: plane.speed)
plane.run(flyoverAction)

WebKit

WKWebView

WKWebView+Load

支持使用 String 导航到请求的 URL

PhotoKit

PHAsset

PHAsset+URL

提供获取图像和视频媒体类型的 URL 的可能性

🙋‍♀🙋‍♂️贡献者

  • 对于贡献者只有一个主要规则 - 请将您的扩展包含在单独的文件中。这很重要,因为这样的扩展可以更容易地引用和重用。
  • 另一个 规则是 - 请将 单元测试 包含在您的扩展中。

👨‍💻作者

Astemir Eleev

🔖许可

该项目受 MIT 许可许可。