Saystack 1.2.3

Saystack 1.2.3

测试已测试
Lang语言 SwiftSwift
许可 MIT
发布最后发布2020年9月
SPM支持 SPM

Dal Rupnik 维护。



Saystack 1.2.3

  • 作者:
  • Dal Rupnik

Saystack

Issues on Waffle Swift Code Build Status Carthage compatible Pod Version Pod Platform Pod License

Saystack 是一组类和扩展,用于Swift项目中最常用的功能(主要针对iOS)。它是已被弃用的 Haystack 的Swift版本。

Saystack 为原生的 Swift API 增加了许多便利方法。扩展了多个 iOS 和 macOS 框架,包括 UIKit 和 Foundation。目前同时支持 macOS 和 iOS,但主要针对 iOS,因为 macOS 不支持 UIKit。

Foundation

  • 简单的电子邮件验证
let email1 = "[email protected]".isValidEmail // true
let email2 = "some@example".isValidEmail // false
let email3 = "1231241231".isValidEmail // false
let email3 = "@example.com".isValidEmail // false
  • 伪随机数生成
// Random Integer between 0 and 1000
let rand1 = Int.random(0, upper: 1000)
// Random Integer between -1000 and 1000
let rand2 = Int.random(-1000, upper: 1000)

// Single Precision random between 0.00 and 1.00
let rand2 = Float.random()
// Double Precision random between 0.00 and 1.00
let rand3 = Double.random()
  • 数组工具
//
// Shuffling
//
var array = [ 1, 2, 3, 4, 5 ]
array.shuffle()

// Prints [ 5, 2, 3, 1, 4 ]
print(array)
let shuffled = [ 1, 2, 3, 4, 5 ].shuffled()

//
// Unique elements
//
let uniqueArray = [ 1, 2, 1, 2, 4, 5 ].unique()
// Prints [ 1, 2, 4, 5 ]
print(uniqueArray)

struct Person {
    var name : String
}

let people = [ Person(name: "John"), Person(name: "John"), Person(name: "Mark"), Person(name: "John") ]
let distinctArrayByProperty = people.distinct({ $0.name })
// Prints [ Person("John"), Person("Mark") ]
print(distinctArrayByProperty)

UIKit

Saystack 提供了多个常见的 UIKit 扩展(在 macOS 上不可用)。

  • 环境检测
let environment = UIApplication.environment

if environment == .testFlight {
    ...
}
  • UIImage 调整大小
let image = UIImage(named: "test-image.png")!
let resized = image.resize (CGSize(width: 100, height: 100))
  • UIView 中搜索父视图类型
@IBAction func tableCellButtonTap(sender: UIButton) {
    guard let cell = sender.parentTableViewCell() else { return }
    
    let indexPath = self.tableView.indexPathForCell(cell)
    
    // Use IndexPath
}
  • 设备信息
let device = UIDevice.current.modelName

// Will use AdSupport.framework if available at runtime, otherwise vendorId.
let identifier = UIDevice.current.deviceIdentifier

联系方式

Dal Rupnik

许可证

Saystack 最高许可协议为 MIT。更多信息请见 LICENSE 文件。