UtilitiesInSwift 1.4.5

UtilitiesInSwift 1.4.5

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Released上次发布2018年11月
SPM支持 SPM

SteveAxelrod007 维护。



  • steveaxelrod007

UtilitiesInSwift

CI Status Version License Platform

示例

多年以来创建的 Swift 工具函数。其中一些是从其他语言转换而来的。
这些工具根据类型分类划分(我觉得这样做可以)。

队列 --> 我主要创建这些,以便在 Swift 发生变化时,我可以轻松调整函数体,而不是改写整个代码库,此外,我还可能 want添加后续功能。

NumbersToWords --> 将数字字符串 "$1,234.56" 转换为 "one thousand two hundred thirty four dollars and 56/100"。

 let words = NumbersToWords.convert(amount: "1.31") 
 print(words)
 One Dollar and 31/100
  
 let words = NumbersToWords.convert(amount: "9,304.67") 
 print(words)
 nine thousand three hundred four dollars and 67/100
  
 amount can be 0.01 ... 999,999.99  nine hundred ninety nine thousand nine hundred ninety nine dollars and 99/100

FileSystem --> 清除临时文件,确定设备上可用的空间

CancelableClosure --> 我用它来等待键盘敲击0.5秒后调用某些查找函数

 var cc = CancelableClosure()       // axe maintain the var
   
 cc.cancelled = true                // axe stop current one from running
        
 let newCc = CancelableClosure()    // axe create new one inside your acceptance of keystrokes func 
 newCc.closure =
   {// [weak self] in
   // axe this is where you would make a server call to fetch a new search lookup based on keystrokes or something
   }

 cc = newCc                         // axe set to global var 
 cc.runAfterDelayOf(delayTime: 0.5) // axe if nothing happens (i.e. user stops typing) then closure is called

UIColor 扩展 --> 以整数形式保存颜色值的方式,然后从数据库中提取并轻松转换回 UIColor

 let color = UIColor.init(red: 10, green: 20, blue: 30)   // axe easy way to create a color
 let colorInt = UIColor.hexFromColor(color: color)        // axe converts to an Int value for easy saving
 UIColor.colorWithHex(hex: colorInt)                      // axe convert saved Int back to a color
 // axe it is called hex as lots of folks express colors as hex values 0xFF1020 as an example
 // colorWithHex  takes an Int that can be a hex value as well, in the end it's all 0 and 1's

Int 扩展 --> 将 Int 转换为 String 距离,格式化包含逗号的 Int,转换为千(k)和百万(m)

 intVal = 123
 intVal.distance()     --> 123ft
 intVal.fullNotation() --> 123
 intVal.kmNotation()   --> 123

 intVal = 4567
 intVal.distance()     --> 0.86mi
 intVal.fullNotation() --> 4,567
 intVal.kmNotation()   --> 4.6k

 intVal = 5280000
 intVal.distance()     --> 1,000mi
 intVal.fullNotation() --> 5,280,000
 intVal.kmNotation()   --> 5.28m

AutoFillTextField --> 如果触发字符在输入文本字段时匹配,则会显示弹出选择列表。从表格中选择项目的一种好方法。

 var autoComplete:AutoFillTextField?

 
 let listOfNames = [
                   AutoFillTextFieldData(name: <This is displayed and returned>, imageUrl: <link to image if availble>),
                   ]

 autoComplete = AutoFillTextField(triggers: "@+", textF: textF, view: view, list: listOfNames, backColor: UIColor.brown, textColor: UIColor.red, callBack:
   {
   })

 AutoFillTextField
   (
   triggers: <characters that activate the table view popup>, 
   textF: UITextField,                                              // axe weak referenced 
   view: <the view the textfield is in>,                            // axe weak referenced 
   list: <AutoFillTextFieldData array of items to display>,
   tableView: <optional or pass in your own table that I use>, 
   backColor: <optional background color of table>, 
   textColor: <optional color of text>,
   callBack: <optional method you can have called in between keystrokes to load more data matching text of textfield> 
   ) 

 
 autoComplete.updateList(list: <new list of names>)  // axe update displayed list on the fly or from callback                    

需求

安装

UtilitiesInSwift可以通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中

pod "UtilitiesInSwift"

作者

steveaxelrod007,[email protected]

许可协议

UtilitiesInSwift受MIT许可协议保护。有关更多信息,请参阅LICENSE文件。