Skip to content

Commit

Permalink
Merge branch 'release/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuamaodeyu committed Oct 4, 2019
2 parents 0246e12 + 3d06a65 commit bd63e4b
Show file tree
Hide file tree
Showing 31 changed files with 539 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output
Example/out/doc
1 change: 1 addition & 0 deletions .swift_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0
97 changes: 97 additions & 0 deletions Example/.jazzy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

clean:

module: TKFoundationModule
module_version: 0.1.2
root_url: https://github.com/zhuamaodeyu
author: 抓猫的鱼
author_url: https://github.com/zhuamaodeyu/knowledge
github_url: https://github.com/zhuamaodeyu/TKFoundationModule.git

title: TKComponentization/TKFoundationModule
readme: ../README.md


theme: apple
output: out/doc


copyright: '© 2018 [抓猫的鱼](https://github.com/zhuamaodeyu/knowledge) under
[open source license](https://github.com/zhuamaodeyu/TKFoundationModule/blob/master/LICENSE).'


# xcodebuild arguments
# xcodebuild_arguments: ["-workspace","TKAuthorityModule.xcworkspace",
# "-scheme","TKAuthorityModule","-sdk","iphonesimulator"]

xcodebuild_arguments:
- -workspace
- TKFoundationModule.xcworkspace
- -scheme
- TKFoundationModule
- -sdk
- iphonesimulator


hide_documentation_coverage: true
documentation: ../*.md # 都可
skip_undocumented: true


# docset
# docset-icon: xxxx/xxx
# docset-path: xxx/xxx


swift_version: 5.0.1
min_acl: public # public open, fileprivate, intxxx

# exclude:
# - "xxxxx.swift"
# - "xxxx.swift"


custom_categories:
- name: Namespace
children:
- NamespaceWrappable
- TypeWrapperProtocol
- NamespaceWrapper
- name: Array
children:
- ArrayProxy
- name: Dictionary
children:
- DictionaryProxy
- name: List
children:
- DoubleLinkedList
- DoubleLinkedListNode
- name: data structure
children:
- Stack
- StackProtocol
- Queue
- QueueProtocol
- DelayQueue
- name: Method Swizzing
children:
- SwizzingProtocol
- SwizzingMethod
- name: Foundtion Extenions
children:
- FunctionProtocol
- Float
- Double


# - name: Manager
# children:
# - AuthorityManager

# - name: Enum
# children:
# - TouchIDAuthority
# - LocaltionType


12 changes: 6 additions & 6 deletions Example/TKFoundationModule_Tests/Date+Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ class DateTests: XCTestCase {
func test_isYear() {
dateFormatter.dateFormat = "YYYY/mm/DD"
let date = dateFormatter.date(from: "2019/03/20")
XCTAssertTrue(date?.ns.isYear() ?? false)
// XCTAssertTrue(date?.ns.year() ?? false)
}

func test_tomorrow() {
// 时区问题 所有多一天
let date = dateFormatter.date(from: "2019-04-30")
XCTAssertTrue(date?.ns.isTomorrow() ?? false)
XCTAssertTrue(date?.ns.tomorrow() ?? false)
}

func test_yesterday() {
let date = dateFormatter.date(from: "2019-04-27")
XCTAssertTrue(date?.ns.isYesterday() ?? false)
XCTAssertTrue(date?.ns.yesterday() ?? false)
}

func test_today() {
let date = Date.init()
XCTAssertTrue(date.ns.isToday())
XCTAssertTrue(date.ns.today())
}

func test_week() {
let date = dateFormatter.date(from: "2019-04-25")
XCTAssertTrue(date?.ns.isWeek() ?? false )
// XCTAssertTrue(date?.ns.weekDay() ?? false )
}

func test_month() {
let date = dateFormatter.date(from: "2019-04-21")
XCTAssertTrue(date?.ns.isMonth() ?? false )
// XCTAssertTrue(date?.ns.month() ?? false )
}

func test_weekDay() {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pod 'TKFoundationModule'

## Author

zhuamaodeyu, 1021491936@qq.com
zhuamaodeyu, playtomandjerry@gmail.com

## License

Expand Down
2 changes: 1 addition & 1 deletion TKFoundationModule.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'TKFoundationModule'
s.version = '0.1.0'
s.version = '0.1.2'
s.summary = 'A short description of TKFoundationModule.'

# This description is used to generate tags and improve search results.
Expand Down
2 changes: 1 addition & 1 deletion TKFoundationModule/Classes/Array+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Array: NamespaceWrappable{
}
}


/// Array Extension
extension Array {

/// 解决数组越界问题
Expand Down
7 changes: 6 additions & 1 deletion TKFoundationModule/Classes/Bundle+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import Foundation

/// Bundle
extension TypeWrapperProtocol where WrappedType == Bundle {

/// 系统所有的framework
/// 分类所有 framework
///
/// - Returns: 元祖 (system, other)
public static func frameworks() -> (system:[Bundle], other: [Bundle]) {
Expand Down Expand Up @@ -38,6 +39,10 @@ extension TypeWrapperProtocol where WrappedType == Bundle {
return url
}

/// 根据指定类获取 bundle
///
/// - Parameter bundleClass: 类
/// - Returns: bundle
public static func bundleResure(of bundleClass: AnyClass) -> Bundle? {
let bundle = Bundle(for: bundleClass)
guard let bundleName = bundle.infoDictionary?[kCFBundleNameKey as String] as? String,
Expand Down
5 changes: 4 additions & 1 deletion TKFoundationModule/Classes/Data+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import Foundation

extension Data:NamespaceWrappable{}

/// Data

extension TypeWrapperProtocol where WrappedType == Data {

/// 获取json 字符串
Expand All @@ -32,7 +35,7 @@ extension TypeWrapperProtocol where WrappedType == Data {

extension TypeWrapperProtocol where WrappedType == NSData {

/// 获取image 类型
/// 获取 image 类型
///
/// - Returns: 类型
public func imageType() -> String? {
Expand Down
15 changes: 9 additions & 6 deletions TKFoundationModule/Classes/Date+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import Foundation

extension Date: NamespaceWrappable {}

/// Date

extension TypeWrapperProtocol where WrappedType == Date {
/// 是否是当年
///
/// - Returns: true 是 false 不是
public func isYear() -> Bool {
public func isCurrentYear() -> Bool {
let calendar = Calendar.current
let selfYear = calendar.component(.year, from: self.wrappedValue)
let newYear = calendar.component(.year, from: Date())
Expand All @@ -22,7 +25,7 @@ extension TypeWrapperProtocol where WrappedType == Date {
/// 明天
///
/// - Returns: true 是 false 不是
public func isTomorrow() -> Bool {
public func tomorrow() -> Bool {
// let fmt = DateFormatter()
// fmt.dateFormat = "yyyy-MM-dd"
// let string = fmt.string(from: self.wrappedValue)
Expand Down Expand Up @@ -50,7 +53,7 @@ extension TypeWrapperProtocol where WrappedType == Date {
/// 是否是昨天
///
/// - Returns: true 是 false 不是
public func isYesterday() -> Bool {
public func yesterday() -> Bool {
// 转换为相同格式
let fmt = DateFormatter()
fmt.dateFormat = "yyyy-MM-dd"
Expand Down Expand Up @@ -78,7 +81,7 @@ extension TypeWrapperProtocol where WrappedType == Date {
/// 是否是今天
///
/// - Returns: true 是 false 否
public func isToday() -> Bool {
public func today() -> Bool {
let calendar = Calendar.current
let unit = Set(arrayLiteral: Calendar.Component.year , Calendar.Component.month, Calendar.Component.day)
let cmps = calendar.dateComponents(unit, from: self.wrappedValue )
Expand All @@ -90,7 +93,7 @@ extension TypeWrapperProtocol where WrappedType == Date {
/// 是否是同一周
///
/// - Returns: true 是 false 不是
public func isWeek(date: Date = Date()) -> Bool {
public func currentWeek(date: Date = Date()) -> Bool {
let calendar = Calendar.current
let unit = Set(arrayLiteral: Calendar.Component.year , Calendar.Component.month, Calendar.Component.day)
let cmps = calendar.dateComponents(unit, from: self.wrappedValue , to: Date())
Expand All @@ -100,7 +103,7 @@ extension TypeWrapperProtocol where WrappedType == Date {
/// 是否是当月
///
/// - Returns: true 是 false 不是
public func isMonth() -> Bool {
public func currentMonth() -> Bool {
let calendar = Calendar.current
let unit = Set(arrayLiteral: Calendar.Component.year , Calendar.Component.month)
let cmps = calendar.dateComponents(unit, from: self.wrappedValue )
Expand Down
9 changes: 9 additions & 0 deletions TKFoundationModule/Classes/Dcitionary+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public struct DictionaryProxy<Key:Hashable, Value>{
}
}


/// MARK: - 下标扩展
extension Dictionary {

/// 下标通过 key 获取value
///
/// - Parameter key: key
/// - Note:
/// 本操作允许空值存在
public subscript (safe key: Key) -> Value? {
return self.keys.contains(key) ? self[key] : nil
}
Expand All @@ -30,6 +38,7 @@ extension Dictionary: NamespaceWrappable{
}


/// MARK: - 数据类型转换 带有默认值
extension DictionaryProxy {
/// sting
///
Expand Down
11 changes: 11 additions & 0 deletions TKFoundationModule/Classes/DelayQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
import Foundation

public typealias QueueBlock = () -> Void

/// 延迟队列
/// - Note:
/// 监听runloop ,当主线程空闲时执行某些操作
public class DelayQueue {

/// shared
/// - Note:
/// 单利
public static let shared = DelayQueue()
private var queue = Queue<QueueBlock>()

/// 队列最大容量
public var queueMaxCount:Int = 20

private init() {
Expand Down Expand Up @@ -47,6 +56,8 @@ extension DelayQueue {
/// 添加
///
/// - Parameter block: block
/// - Note:
/// 如果当前队列中未处理任务大于最大队列数, 那么将移除前置的任务,以添加新的任务
public func add(block:@escaping QueueBlock) {
if self.queue.size > queueMaxCount {
_ = self.queue.leave()
Expand Down
6 changes: 4 additions & 2 deletions TKFoundationModule/Classes/DispatchQueue+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ private let mainQueueKey = DispatchSpecificKey<String>.init()
private let mainQueueValue = "mainQueue"


// MARK: - DispatchQueue
extension TypeWrapperProtocol where WrappedType == DispatchQueue {

/// 判断是否在主线程执行推荐通过此方式来实现
///
/// - Returns: 当前是否在主队列
static public func isMainQueue() -> Bool {
public static func isMainQueue() -> Bool {
DispatchQueue.main.setSpecific(key: mainQueueKey, value: mainQueueValue)
return DispatchQueue.getSpecific(key: mainQueueKey) == mainQueueValue
}


}


extension DispatchQueue {
/// main
///
Expand Down Expand Up @@ -61,7 +63,7 @@ extension DispatchQueue {
/// - closure: closure block
/// - Returns: return value description
/// - Throws: throws value description
func synchronized<T>(_ lock: AnyObject, _ closure: () throws -> T) rethrows -> T {
public func synchronized<T>(_ lock: AnyObject, _ closure: () throws -> T) rethrows -> T {
objc_sync_enter(lock)
defer { objc_sync_exit(lock) }
return try closure()
Expand Down
Loading

0 comments on commit bd63e4b

Please sign in to comment.