diff --git a/README.md b/README.md index 479183e..9600e69 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ ### Version 2.3.2: -更新至 Swift 5
+ #### 网络更新机制: -第一次更新会完全覆盖原hosts,然后生成“# My Hosts Start”、“# My Hosts End”标识
-需要添加的话,只要在“# My Hosts Start”、“# My Hosts End”范围内编辑, diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework.dSYM/Contents/Info.plist b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework.dSYM/Contents/Info.plist new file mode 100644 index 0000000..eae21b4 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.io.rx.RxAtomic + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 4.4.2 + CFBundleVersion + 1 + + diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic new file mode 100644 index 0000000..d7009d3 Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic differ diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Headers b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Modules b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Modules new file mode 120000 index 0000000..5736f31 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Modules @@ -0,0 +1 @@ +Versions/Current/Modules \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Resources b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/RxAtomic b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/RxAtomic new file mode 120000 index 0000000..c0fcd44 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/RxAtomic @@ -0,0 +1 @@ +Versions/Current/RxAtomic \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Headers/RxAtomic.h b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Headers/RxAtomic.h new file mode 100644 index 0000000..7c205d9 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Headers/RxAtomic.h @@ -0,0 +1,73 @@ +// +// RxAtomic.h +// RxAtomic +// +// Created by Krunoslav Zaher on 10/28/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +#ifndef RxAtomic_h +#define RxAtomic_h + +#include + +#define SWIFT_NAME(_name) __attribute__((swift_name(#_name))) + +#define Atomic(swift_type, llvm_type) \ + typedef struct { volatile atomic_##llvm_type atom; } Atomic##swift_type;\ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.initialize(_:_:)) \ + void Atomic##swift_type##_Initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.load(_:)) \ + llvm_type Atomic##swift_type##_Load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.fetchOr(_:_:)) \ + llvm_type Atomic##swift_type##_FetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.add(_:_:)) \ + llvm_type Atomic##swift_type##_Add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.sub(_:_:)) \ + llvm_type Atomic##swift_type##_Sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + void Atomic##swift_type##_initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_fetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + +Atomic(Int, int) + +#undef SWIFT_NAME + +#endif /* RxAtomic_h */ diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Modules/module.modulemap b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Modules/module.modulemap new file mode 100644 index 0000000..d8b4955 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module RxAtomic { + umbrella header "RxAtomic.h" + + export * + module * { export * } +} diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Resources/Info.plist b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..7e27c87 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,49 @@ + + + + + BuildMachineOSBuild + 18E226 + CFBundleDevelopmentRegion + English + CFBundleExecutable + RxAtomic + CFBundleIdentifier + io.rx.RxAtomic + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + RxAtomic + CFBundlePackageType + FMWK + CFBundleShortVersionString + 4.4.2 + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 1 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 10E125 + DTPlatformVersion + GM + DTSDKBuild + 18E219 + DTSDKName + macosx10.14 + DTXcode + 1020 + DTXcodeBuild + 10E125 + UIDeviceFamily + + 1 + 2 + 3 + 4 + + + diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/RxAtomic b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/RxAtomic new file mode 100755 index 0000000..0fda5cd Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/A/RxAtomic differ diff --git a/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/Current b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/Mac/RxAtomic.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/D780457F-DFD1-3FAF-9901-8C818FA716F1.bcsymbolmap b/Source Code/HostsToolForMac/Carthage/Build/iOS/D780457F-DFD1-3FAF-9901-8C818FA716F1.bcsymbolmap new file mode 100644 index 0000000..8d9e603 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/iOS/D780457F-DFD1-3FAF-9901-8C818FA716F1.bcsymbolmap @@ -0,0 +1,5 @@ +BCSymbolMap Version: 2.0 +Apple LLVM version 10.0.0 (clang-1000.11.45.5) +/Users/kruno/Projects/RxSwift/RxAtomic/RxAtomic.c +/Users/kruno/Projects/RxSwift +/Users/kruno/Library/Developer/Xcode/DerivedData/Rx-ccurivfaucpsstgtscvvrjppmvnu/Build/Intermediates.noindex/ArchiveIntermediates/RxAtomic/IntermediateBuildFilesPath/Rx.build/Release-iphoneos/RxAtomic.build/DerivedSources/RxAtomic_vers.c diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/E0774270-5CE2-3B0F-B936-D3A0AA635EF4.bcsymbolmap b/Source Code/HostsToolForMac/Carthage/Build/iOS/E0774270-5CE2-3B0F-B936-D3A0AA635EF4.bcsymbolmap new file mode 100644 index 0000000..8d9e603 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/iOS/E0774270-5CE2-3B0F-B936-D3A0AA635EF4.bcsymbolmap @@ -0,0 +1,5 @@ +BCSymbolMap Version: 2.0 +Apple LLVM version 10.0.0 (clang-1000.11.45.5) +/Users/kruno/Projects/RxSwift/RxAtomic/RxAtomic.c +/Users/kruno/Projects/RxSwift +/Users/kruno/Library/Developer/Xcode/DerivedData/Rx-ccurivfaucpsstgtscvvrjppmvnu/Build/Intermediates.noindex/ArchiveIntermediates/RxAtomic/IntermediateBuildFilesPath/Rx.build/Release-iphoneos/RxAtomic.build/DerivedSources/RxAtomic_vers.c diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework.dSYM/Contents/Info.plist b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework.dSYM/Contents/Info.plist new file mode 100644 index 0000000..eae21b4 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.io.rx.RxAtomic + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 4.4.2 + CFBundleVersion + 1 + + diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic new file mode 100644 index 0000000..7170caf Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic differ diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Headers/RxAtomic.h b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Headers/RxAtomic.h new file mode 100644 index 0000000..7c205d9 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Headers/RxAtomic.h @@ -0,0 +1,73 @@ +// +// RxAtomic.h +// RxAtomic +// +// Created by Krunoslav Zaher on 10/28/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +#ifndef RxAtomic_h +#define RxAtomic_h + +#include + +#define SWIFT_NAME(_name) __attribute__((swift_name(#_name))) + +#define Atomic(swift_type, llvm_type) \ + typedef struct { volatile atomic_##llvm_type atom; } Atomic##swift_type;\ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.initialize(_:_:)) \ + void Atomic##swift_type##_Initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.load(_:)) \ + llvm_type Atomic##swift_type##_Load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.fetchOr(_:_:)) \ + llvm_type Atomic##swift_type##_FetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.add(_:_:)) \ + llvm_type Atomic##swift_type##_Add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.sub(_:_:)) \ + llvm_type Atomic##swift_type##_Sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + void Atomic##swift_type##_initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_fetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + +Atomic(Int, int) + +#undef SWIFT_NAME + +#endif /* RxAtomic_h */ diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Info.plist b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Info.plist new file mode 100644 index 0000000..d8ecb4e Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Info.plist differ diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Modules/module.modulemap b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Modules/module.modulemap new file mode 100644 index 0000000..d8b4955 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module RxAtomic { + umbrella header "RxAtomic.h" + + export * + module * { export * } +} diff --git a/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/RxAtomic b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/RxAtomic new file mode 100755 index 0000000..3893aed Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/iOS/RxAtomic.framework/RxAtomic differ diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/47664D76-7B7F-39F9-A857-1A5C1E7F0B67.bcsymbolmap b/Source Code/HostsToolForMac/Carthage/Build/watchOS/47664D76-7B7F-39F9-A857-1A5C1E7F0B67.bcsymbolmap new file mode 100644 index 0000000..f46bbb2 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/watchOS/47664D76-7B7F-39F9-A857-1A5C1E7F0B67.bcsymbolmap @@ -0,0 +1,5 @@ +BCSymbolMap Version: 2.0 +Apple LLVM version 10.0.0 (clang-1000.11.45.5) +/Users/kruno/Projects/RxSwift/RxAtomic/RxAtomic.c +/Users/kruno/Projects/RxSwift +/Users/kruno/Library/Developer/Xcode/DerivedData/Rx-ccurivfaucpsstgtscvvrjppmvnu/Build/Intermediates.noindex/ArchiveIntermediates/RxAtomic/IntermediateBuildFilesPath/Rx.build/Release-watchos/RxAtomic.build/DerivedSources/RxAtomic_vers.c diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/8BA18AEE-69F4-37D7-9826-786A815A07DD.bcsymbolmap b/Source Code/HostsToolForMac/Carthage/Build/watchOS/8BA18AEE-69F4-37D7-9826-786A815A07DD.bcsymbolmap new file mode 100644 index 0000000..f46bbb2 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/watchOS/8BA18AEE-69F4-37D7-9826-786A815A07DD.bcsymbolmap @@ -0,0 +1,5 @@ +BCSymbolMap Version: 2.0 +Apple LLVM version 10.0.0 (clang-1000.11.45.5) +/Users/kruno/Projects/RxSwift/RxAtomic/RxAtomic.c +/Users/kruno/Projects/RxSwift +/Users/kruno/Library/Developer/Xcode/DerivedData/Rx-ccurivfaucpsstgtscvvrjppmvnu/Build/Intermediates.noindex/ArchiveIntermediates/RxAtomic/IntermediateBuildFilesPath/Rx.build/Release-watchos/RxAtomic.build/DerivedSources/RxAtomic_vers.c diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework.dSYM/Contents/Info.plist b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework.dSYM/Contents/Info.plist new file mode 100644 index 0000000..eae21b4 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.io.rx.RxAtomic + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 4.4.2 + CFBundleVersion + 1 + + diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic new file mode 100644 index 0000000..c70ba41 Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework.dSYM/Contents/Resources/DWARF/RxAtomic differ diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Headers/RxAtomic.h b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Headers/RxAtomic.h new file mode 100644 index 0000000..7c205d9 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Headers/RxAtomic.h @@ -0,0 +1,73 @@ +// +// RxAtomic.h +// RxAtomic +// +// Created by Krunoslav Zaher on 10/28/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +#ifndef RxAtomic_h +#define RxAtomic_h + +#include + +#define SWIFT_NAME(_name) __attribute__((swift_name(#_name))) + +#define Atomic(swift_type, llvm_type) \ + typedef struct { volatile atomic_##llvm_type atom; } Atomic##swift_type;\ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.initialize(_:_:)) \ + void Atomic##swift_type##_Initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.load(_:)) \ + llvm_type Atomic##swift_type##_Load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.fetchOr(_:_:)) \ + llvm_type Atomic##swift_type##_FetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.add(_:_:)) \ + llvm_type Atomic##swift_type##_Add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.sub(_:_:)) \ + llvm_type Atomic##swift_type##_Sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + void Atomic##swift_type##_initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_fetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + +Atomic(Int, int) + +#undef SWIFT_NAME + +#endif /* RxAtomic_h */ diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Info.plist b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Info.plist new file mode 100644 index 0000000..fbd694c Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Info.plist differ diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Modules/module.modulemap b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Modules/module.modulemap new file mode 100644 index 0000000..d8b4955 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module RxAtomic { + umbrella header "RxAtomic.h" + + export * + module * { export * } +} diff --git a/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/RxAtomic b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/RxAtomic new file mode 100755 index 0000000..e710553 Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Build/watchOS/RxAtomic.framework/RxAtomic differ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/.swiftlint.yml b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/.swiftlint.yml new file mode 100644 index 0000000..609bd5f --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/.swiftlint.yml @@ -0,0 +1,39 @@ +included: + - RxSwift + - RxCocoa + - RxTest + - RxBlocking +opt_in_rules: + - overridden_super_call + - private_outlet + - prohibited_super_call + - first_where + - closure_spacing + - unneeded_parentheses_in_closure_argument + - redundant_nil_coalescing + - pattern_matching_keywords + - explicit_init + - contains_over_first_not_nil +disabled_rules: + - line_length + - trailing_whitespace + - type_name + - identifier_name + - vertical_whitespace + - trailing_newline + - opening_brace + - large_tuple + - file_length + - comma + - colon + - private_over_fileprivate + - force_cast + - force_try + - function_parameter_count + - statement_position + - legacy_hashing + - todo + - operator_whitespace + - type_body_length + - function_body_length + - cyclomatic_complexity \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Platform/AtomicInt.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Platform/AtomicInt.swift new file mode 100644 index 0000000..45e6c9b --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Platform/AtomicInt.swift @@ -0,0 +1,58 @@ +// +// AtomicInt.swift +// Platform +// +// Created by Krunoslav Zaher on 10/28/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +import RxAtomic + +typealias AtomicInt = RxAtomic.AtomicInt + +extension AtomicInt { + public init(_ value: Int32) { + self.init() + AtomicInt_initialize(&self, value) + } +} + +@discardableResult +@inline(__always) +func add(_ this: UnsafeMutablePointer, _ value: Int32) -> Int32 { + return AtomicInt_add(this, value) +} + +@discardableResult +@inline(__always) +func sub(_ this: UnsafeMutablePointer, _ value: Int32) -> Int32 { + return AtomicInt_sub(this, value) +} + +@discardableResult +@inline(__always) +func fetchOr(_ this: UnsafeMutablePointer, _ mask: Int32) -> Int32 { + return AtomicInt_fetchOr(this, mask) +} + +@inline(__always) +func load(_ this: UnsafeMutablePointer) -> Int32 { + return AtomicInt_load(this) +} + +@discardableResult +@inline(__always) +func increment(_ this: UnsafeMutablePointer) -> Int32 { + return add(this, 1) +} + +@discardableResult +@inline(__always) +func decrement(_ this: UnsafeMutablePointer) -> Int32 { + return sub(this, 1) +} + +@inline(__always) +func isFlagSet(_ this: UnsafeMutablePointer, _ mask: Int32) -> Bool { + return (load(this) & mask) != 0 +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-watchOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-iOS.xcscheme similarity index 57% rename from Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-watchOS.xcscheme rename to Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-iOS.xcscheme index 2428780..7be3690 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-watchOS.xcscheme +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-iOS.xcscheme @@ -1,33 +1,31 @@ - - - - - - + + + + @@ -42,15 +40,6 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - - - - @@ -60,15 +49,6 @@ savedToolIdentifier = "" useCustomWorkingDirectory = "NO" debugDocumentVersioning = "YES"> - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-macOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-macOS.xcscheme new file mode 100644 index 0000000..dcf3bca --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-macOS.xcscheme @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-tvOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-tvOS.xcscheme new file mode 100644 index 0000000..92b26eb --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/AllTests-tvOS.xcscheme @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-tvOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxAtomic.xcscheme similarity index 82% rename from Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-tvOS.xcscheme rename to Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxAtomic.xcscheme index cf47e8b..3968b30 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-tvOS.xcscheme +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxAtomic.xcscheme @@ -1,6 +1,6 @@ @@ -45,9 +45,9 @@ @@ -63,9 +63,9 @@ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-macOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-macOS.xcscheme deleted file mode 100644 index 2614dd2..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-macOS.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-tvOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-tvOS.xcscheme deleted file mode 100644 index e728da1..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-tvOS.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-watchOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-watchOS.xcscheme deleted file mode 100644 index dee4e6b..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-watchOS.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-iOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking.xcscheme similarity index 94% rename from Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-iOS.xcscheme rename to Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking.xcscheme index a8f9feb..242ce8b 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking-iOS.xcscheme +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxBlocking.xcscheme @@ -1,6 +1,6 @@ @@ -47,7 +47,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "C8093B4B1B8A71F00088E94D" BuildableName = "RxBlocking.framework" - BlueprintName = "RxBlocking-iOS" + BlueprintName = "RxBlocking" ReferencedContainer = "container:Rx.xcodeproj"> @@ -65,7 +65,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "C8093B4B1B8A71F00088E94D" BuildableName = "RxBlocking.framework" - BlueprintName = "RxBlocking-iOS" + BlueprintName = "RxBlocking" ReferencedContainer = "container:Rx.xcodeproj"> diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-iOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa.xcscheme similarity index 94% rename from Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-iOS.xcscheme rename to Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa.xcscheme index a1c6b76..e3c32e4 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-iOS.xcscheme +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa.xcscheme @@ -1,6 +1,6 @@ @@ -47,7 +47,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "C80938F51B8A71760088E94D" BuildableName = "RxCocoa.framework" - BlueprintName = "RxCocoa-iOS" + BlueprintName = "RxCocoa" ReferencedContainer = "container:Rx.xcodeproj"> @@ -65,7 +65,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "C80938F51B8A71760088E94D" BuildableName = "RxCocoa.framework" - BlueprintName = "RxCocoa-iOS" + BlueprintName = "RxCocoa" ReferencedContainer = "container:Rx.xcodeproj"> diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-macOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-macOS.xcscheme deleted file mode 100644 index 27d6774..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-macOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-tvOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-tvOS.xcscheme deleted file mode 100644 index 9facb86..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-tvOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-watchOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-watchOS.xcscheme deleted file mode 100644 index d78de8e..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-watchOS.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-iOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift.xcscheme similarity index 80% rename from Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-iOS.xcscheme rename to Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift.xcscheme index e941cb2..5c4eea6 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift-iOS.xcscheme +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxSwift.xcscheme @@ -1,6 +1,6 @@ - - - - @@ -59,7 +49,6 @@ useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" - stopOnEveryThreadSanitizerIssue = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> @@ -67,7 +56,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "C8A56AD61AD7424700B4673B" BuildableName = "RxSwift.framework" - BlueprintName = "RxSwift-iOS" + BlueprintName = "RxSwift" ReferencedContainer = "container:Rx.xcodeproj"> @@ -85,7 +74,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "C8A56AD61AD7424700B4673B" BuildableName = "RxSwift.framework" - BlueprintName = "RxSwift-iOS" + BlueprintName = "RxSwift" ReferencedContainer = "container:Rx.xcodeproj"> diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-macOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTest.xcscheme similarity index 82% rename from Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-macOS.xcscheme rename to Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTest.xcscheme index b940bb0..2e455a5 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxCocoa-macOS.xcscheme +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTest.xcscheme @@ -1,6 +1,6 @@ @@ -45,9 +45,9 @@ @@ -63,9 +63,9 @@ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-iOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-iOS.xcscheme deleted file mode 100644 index 914e0e8..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-iOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-macOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-macOS.xcscheme deleted file mode 100644 index 1d264d3..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-macOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-tvOS.xcscheme b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-tvOS.xcscheme deleted file mode 100644 index 75e767c..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Rx.xcodeproj/xcshareddata/xcschemes/RxTests-tvOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic.podspec b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic.podspec new file mode 100644 index 0000000..9b1ddf8 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic.podspec @@ -0,0 +1,23 @@ +Pod::Spec.new do |s| + s.name = "RxAtomic" + s.version = "4.4.2" + s.summary = "Atomic primitives for RxSwift" + s.description = <<-DESC +Atomic primitives for RxSwift. + DESC + s.homepage = "https://github.com/ReactiveX/RxSwift" + s.license = 'MIT' + s.author = { "Krunoslav Zaher" => "krunoslav.zaher@gmail.com" } + s.source = { :git => "https://github.com/ReactiveX/RxSwift.git", :tag => s.version.to_s } + + s.requires_arc = true + + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + + s.ios.deployment_target = '8.0' + s.osx.deployment_target = '10.9' + s.watchos.deployment_target = '3.0' + s.tvos.deployment_target = '9.0' + + s.source_files = 'RxAtomic/**/*.{c,h}' +end diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/Info.plist b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/Info.plist new file mode 100644 index 0000000..63e1e13 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 4.4.2 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + + diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/RxAtomic.c b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/RxAtomic.c new file mode 100644 index 0000000..5ec86f5 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/RxAtomic.c @@ -0,0 +1,7 @@ +// +// RxAtomic.c +// RxAtomic +// +// Created by Krunoslav Zaher on 10/28/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/include/RxAtomic.h b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/include/RxAtomic.h new file mode 100644 index 0000000..7c205d9 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxAtomic/include/RxAtomic.h @@ -0,0 +1,73 @@ +// +// RxAtomic.h +// RxAtomic +// +// Created by Krunoslav Zaher on 10/28/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +#ifndef RxAtomic_h +#define RxAtomic_h + +#include + +#define SWIFT_NAME(_name) __attribute__((swift_name(#_name))) + +#define Atomic(swift_type, llvm_type) \ + typedef struct { volatile atomic_##llvm_type atom; } Atomic##swift_type;\ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.initialize(_:_:)) \ + void Atomic##swift_type##_Initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.load(_:)) \ + llvm_type Atomic##swift_type##_Load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.fetchOr(_:_:)) \ + llvm_type Atomic##swift_type##_FetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.add(_:_:)) \ + llvm_type Atomic##swift_type##_Add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.sub(_:_:)) \ + llvm_type Atomic##swift_type##_Sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + void Atomic##swift_type##_initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_fetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + +Atomic(Int, int) + +#undef SWIFT_NAME + +#endif /* RxAtomic_h */ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxBlocking/Platform/AtomicInt.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxBlocking/Platform/AtomicInt.swift new file mode 120000 index 0000000..737940e --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxBlocking/Platform/AtomicInt.swift @@ -0,0 +1 @@ +../../Platform/AtomicInt.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxCocoa/macOS/NSTextView+Rx.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxCocoa/macOS/NSTextView+Rx.swift new file mode 100644 index 0000000..85e8f6f --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxCocoa/macOS/NSTextView+Rx.swift @@ -0,0 +1,85 @@ +// +// NSTextView+Rx.swift +// RxCocoa +// +// Created by Cee on 8/5/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +#if os(macOS) + +import Cocoa +import RxSwift + +/// Delegate proxy for `NSTextView`. +/// +/// For more information take a look at `DelegateProxyType`. +open class RxTextViewDelegateProxy: DelegateProxy, DelegateProxyType, NSTextViewDelegate { + + /// Typed parent object. + public weak private(set) var textView: NSTextView? + + /// Initializes `RxTextViewDelegateProxy` + /// + /// - parameter textView: Parent object for delegate proxy. + init(textView: NSTextView) { + self.textView = textView + super.init(parentObject: textView, delegateProxy: RxTextViewDelegateProxy.self) + } + + public static func registerKnownImplementations() { + self.register { RxTextViewDelegateProxy(textView: $0) } + } + + fileprivate let textSubject = PublishSubject() + + // MARK: Delegate methods + + open func textDidChange(_ notification: Notification) { + let textView: NSTextView = castOrFatalError(notification.object) + let nextValue = textView.string + self.textSubject.on(.next(nextValue)) + self._forwardToDelegate?.textDidChange?(notification) + } + + // MARK: Delegate proxy methods + + /// For more information take a look at `DelegateProxyType`. + open class func currentDelegate(for object: ParentObject) -> NSTextViewDelegate? { + return object.delegate + } + + /// For more information take a look at `DelegateProxyType`. + open class func setCurrentDelegate(_ delegate: NSTextViewDelegate?, to object: ParentObject) { + object.delegate = delegate + } + +} + +extension Reactive where Base: NSTextView { + + /// Reactive wrapper for `delegate`. + /// + /// For more information take a look at `DelegateProxyType` protocol documentation. + public var delegate: DelegateProxy { + return RxTextViewDelegateProxy.proxy(for: self.base) + } + + /// Reactive wrapper for `string` property. + public var string: ControlProperty { + let delegate = RxTextViewDelegateProxy.proxy(for: self.base) + + let source = Observable.deferred { [weak textView = self.base] in + delegate.textSubject.startWith(textView?.string ?? "") + }.takeUntil(self.deallocated) + + let observer = Binder(self.base) { control, value in + control.string = value + } + + return ControlProperty(values: source, valueSink: observer.asObserver()) + } + +} + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxSwift/Platform/AtomicInt.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxSwift/Platform/AtomicInt.swift new file mode 120000 index 0000000..737940e --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/RxSwift/Platform/AtomicInt.swift @@ -0,0 +1 @@ +../../Platform/AtomicInt.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/AtomicInt.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/AtomicInt.swift new file mode 120000 index 0000000..737940e --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/AtomicInt.swift @@ -0,0 +1 @@ +../../Platform/AtomicInt.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/AtomicTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/AtomicTests.swift new file mode 120000 index 0000000..11e917d --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/AtomicTests.swift @@ -0,0 +1 @@ +../../Tests/RxSwiftTests/AtomicTests.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/RxAtomic+Overrides.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/RxAtomic+Overrides.swift new file mode 120000 index 0000000..4d36f78 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/RxAtomic+Overrides.swift @@ -0,0 +1 @@ +../../Tests/RxSwiftTests/RxAtomic+Overrides.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/Synchronized.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/Synchronized.swift new file mode 120000 index 0000000..438f69d --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/AllTestz/Synchronized.swift @@ -0,0 +1 @@ +../../Tests/RxSwiftTests/Synchronized.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxAtomic/RxAtomic.c b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxAtomic/RxAtomic.c new file mode 120000 index 0000000..d96657c --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxAtomic/RxAtomic.c @@ -0,0 +1 @@ +../../RxAtomic/RxAtomic.c \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxAtomic/include/RxAtomic.h b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxAtomic/include/RxAtomic.h new file mode 100644 index 0000000..7c205d9 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxAtomic/include/RxAtomic.h @@ -0,0 +1,73 @@ +// +// RxAtomic.h +// RxAtomic +// +// Created by Krunoslav Zaher on 10/28/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +#ifndef RxAtomic_h +#define RxAtomic_h + +#include + +#define SWIFT_NAME(_name) __attribute__((swift_name(#_name))) + +#define Atomic(swift_type, llvm_type) \ + typedef struct { volatile atomic_##llvm_type atom; } Atomic##swift_type;\ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.initialize(_:_:)) \ + void Atomic##swift_type##_Initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.load(_:)) \ + llvm_type Atomic##swift_type##_Load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.fetchOr(_:_:)) \ + llvm_type Atomic##swift_type##_FetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.add(_:_:)) \ + llvm_type Atomic##swift_type##_Add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) SWIFT_NAME(Atomic##swift_type.sub(_:_:)) \ + llvm_type Atomic##swift_type##_Sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + void Atomic##swift_type##_initialize(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + atomic_init(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_load(Atomic##swift_type * _Nonnull self) { \ + return atomic_load(&self->atom);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_fetchOr(Atomic##swift_type * _Nonnull self, llvm_type mask) { \ + return atomic_fetch_or(&self->atom, mask);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_add(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_add(&self->atom, value);\ + }\ + \ + static __inline__ __attribute__((__always_inline__)) \ + llvm_type Atomic##swift_type##_sub(Atomic##swift_type * _Nonnull self, llvm_type value) { \ + return atomic_fetch_sub(&self->atom, value);\ + }\ + \ + +Atomic(Int, int) + +#undef SWIFT_NAME + +#endif /* RxAtomic_h */ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxBlocking/AtomicInt.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxBlocking/AtomicInt.swift new file mode 120000 index 0000000..7911c43 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxBlocking/AtomicInt.swift @@ -0,0 +1 @@ +../../RxBlocking/Platform/AtomicInt.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxCocoa/NSTextView+Rx.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxCocoa/NSTextView+Rx.swift new file mode 120000 index 0000000..f0dbd43 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxCocoa/NSTextView+Rx.swift @@ -0,0 +1 @@ +../../RxCocoa/macOS/NSTextView+Rx.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxSwift/AtomicInt.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxSwift/AtomicInt.swift new file mode 120000 index 0000000..325e9ec --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Sources/RxSwift/AtomicInt.swift @@ -0,0 +1 @@ +../../RxSwift/Platform/AtomicInt.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/Platform/AtomicInt.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/Platform/AtomicInt.swift new file mode 120000 index 0000000..737940e --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/Platform/AtomicInt.swift @@ -0,0 +1 @@ +../../Platform/AtomicInt.swift \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxCocoaTests/NSTextView+RxTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxCocoaTests/NSTextView+RxTests.swift new file mode 100644 index 0000000..cb919ee --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxCocoaTests/NSTextView+RxTests.swift @@ -0,0 +1,68 @@ +// +// NSTextView+RxTests.swift +// Tests +// +// Created by Cee on 8/5/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +import RxSwift +import RxCocoa +import AppKit +import XCTest + +final class NSTextViewTests: RxTest { + static let timeout: TimeInterval = 0.5 +} + +extension NSTextViewTests { + func testTextView_StringCompletesOnDealloc() { + let createView: () -> NSTextView = { NSTextView(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) } + ensurePropertyDeallocated(createView, "a") { (view: NSTextView) in view.rx.string } + } + + func testTextView_TextDidChange_ForwardsToDelegates() { + let completeExpectation = XCTestExpectation(description: "NSTextView completion") + let strings: [String] = ["T", "Te", "Tes", "Test"] + let assert: [String] = [""] + strings + var recorded: [String] = [] + + autoreleasepool { + let textView = NSTextView() + let delegate = TextViewDelegate() + textView.delegate = delegate + + _ = textView.rx.string + .subscribe(onNext: { value in + recorded.append(value) + }, onCompleted: { + completeExpectation.fulfill() + }) + + XCTAssertEqual(delegate.numberOfChanges, 0) + var numberOfChanges = 0 + for string in strings { + textView.string = string + let notification = Notification( + name: NSText.didChangeNotification, + object: textView, + userInfo: nil) + XCTAssertEqual(delegate.numberOfChanges, numberOfChanges) + (textView.delegate as NSTextDelegate?)?.textDidChange?(notification) + numberOfChanges += 1 + XCTAssertEqual(delegate.numberOfChanges, numberOfChanges) + } + } + + wait(for: [completeExpectation], timeout: NSTextViewTests.timeout) + XCTAssertEqual(assert, recorded) + } +} + +fileprivate final class TextViewDelegate: NSObject, NSTextViewDelegate { + var numberOfChanges = 0 + + func textDidChange(_ notification: Notification) { + numberOfChanges = numberOfChanges + 1 + } +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/AtomicTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/AtomicTests.swift new file mode 100644 index 0000000..fed6330 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/AtomicTests.swift @@ -0,0 +1,184 @@ +// +// AtomicTests.swift +// Tests +// +// Created by Krunoslav Zaher on 10/29/18. +// Copyright © 2018 Krunoslav Zaher. All rights reserved. +// + +import XCTest +import Dispatch + +#if true +import RxAtomic +typealias AtomicPrimitive = AtomicInt +#else +private struct AtomicIntSanityCheck { + var atom: Int32 = 0 + + init() { + } + + init(_ atom: Int32) { + self.atom = atom + } + + mutating func add(_ value: Int32) -> Int32 { + defer { self.atom += value } + return self.atom + } + + mutating func sub(_ value: Int32) -> Int32 { + defer { self.atom -= value } + return self.atom + } + + mutating func fetchOr(_ value: Int32) -> Int32 { + defer { self.atom |= value } + return self.atom + } + + func load() -> Int32 { + return self.atom + } +} +fileprivate typealias AtomicPrimitive = AtomicIntSanityCheck +#endif + +class AtomicTests: RxTest {} + +extension AtomicTests { + func testAtomicInitialValue() { + var atomic = AtomicPrimitive(4) + XCTAssertEqual(globalLoad(&atomic), 4) + } + + func testAtomicInitialDefaultValue() { + var atomic = AtomicPrimitive() + XCTAssertEqual(globalLoad(&atomic), 0) + } +} + +extension AtomicTests { + private static let repeatCount = 100 + private static let concurrency = 8 + + func testFetchOrSetsBits() { + var atomic = AtomicPrimitive() + XCTAssertEqual(fetchOr(&atomic, 0), 0) + XCTAssertEqual(fetchOr(&atomic, 4), 0) + XCTAssertEqual(fetchOr(&atomic, 8), 4) + XCTAssertEqual(fetchOr(&atomic, 0), 12) + } + + func testFetchOrConcurrent() { + let queue = DispatchQueue.global(qos: .default) + for _ in 0 ..< AtomicTests.repeatCount { + var atomic = AtomicPrimitive(0) + + var counter = AtomicPrimitive(0) + + var expectations = [XCTestExpectation]() + + for _ in 0 ..< AtomicTests.concurrency { + let expectation = self.expectation(description: "wait until operation completes") + queue.async { + while globalLoad(&atomic) == 0 {} + + if fetchOr(&atomic, -1) == 1 { + globalAdd(&counter, 1) + } + + expectation.fulfill() + } + expectations.append(expectation) + } + fetchOr(&atomic, 1) + + #if os(Linux) + self.waitForExpectations(timeout: 1.0) { _ in } + #else + XCTWaiter().wait(for: expectations, timeout: 1.0) + #endif + XCTAssertEqual(globalLoad(&counter), 1) + } + } + + func testAdd() { + var atomic = AtomicPrimitive(0) + XCTAssertEqual(globalAdd(&atomic, 4), 0) + XCTAssertEqual(globalAdd(&atomic, 3), 4) + XCTAssertEqual(globalAdd(&atomic, 10), 7) + } + + func testAddConcurrent() { + let queue = DispatchQueue.global(qos: .default) + for _ in 0 ..< AtomicTests.repeatCount { + var atomic = AtomicPrimitive(0) + + var counter = AtomicPrimitive(0) + + var expectations = [XCTestExpectation]() + + for _ in 0 ..< AtomicTests.concurrency { + let expectation = self.expectation(description: "wait until operation completes") + queue.async { + while globalLoad(&atomic) == 0 {} + + globalAdd(&counter, 1) + + expectation.fulfill() + } + expectations.append(expectation) + } + fetchOr(&atomic, 1) + + #if os(Linux) + waitForExpectations(timeout: 1.0) { _ in } + #else + XCTWaiter().wait(for: expectations, timeout: 1.0) + #endif + + XCTAssertEqual(globalLoad(&counter), 8) + } + } + + func testSub() { + var atomic = AtomicPrimitive(0) + XCTAssertEqual(sub(&atomic, -4), 0) + XCTAssertEqual(sub(&atomic, -3), 4) + XCTAssertEqual(sub(&atomic, -10), 7) + } + + func testSubConcurrent() { + let queue = DispatchQueue.global(qos: .default) + for _ in 0 ..< AtomicTests.repeatCount { + var atomic = AtomicPrimitive(0) + + var counter = AtomicPrimitive(0) + + var expectations = [XCTestExpectation]() + + for _ in 0 ..< AtomicTests.concurrency { + let expectation = self.expectation(description: "wait until operation completes") + queue.async { + while globalLoad(&atomic) == 0 {} + + sub(&counter, 1) + + expectation.fulfill() + } + expectations.append(expectation) + } + fetchOr(&atomic, 1) + + #if os(Linux) + waitForExpectations(timeout: 1.0) { _ in } + #else + XCTWaiter().wait(for: expectations, timeout: 1.0) + #endif + + XCTAssertEqual(globalLoad(&counter), -8) + } + } +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/RxAtomic+Overrides.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/RxAtomic+Overrides.swift new file mode 100644 index 0000000..378404b --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/RxAtomic+Overrides.swift @@ -0,0 +1,20 @@ +// +// RxAtomic+Overrides.swift +// Tests +// +// Created by Krunoslav Zaher on 1/29/19. +// Copyright © 2019 Krunoslav Zaher. All rights reserved. +// + +/// This is a workaround for the overloaded `load` symbol. +@inline(__always) +func globalLoad(_ this: UnsafeMutablePointer) -> Int32 { + return load(this) +} + +/// This is a workaround for the overloaded `add` symbol. +@inline(__always) +@discardableResult +func globalAdd(_ this: UnsafeMutablePointer, _ value: Int32) -> Int32 { + return add(this, value) +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/Synchronized.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/Synchronized.swift new file mode 100644 index 0000000..7ce5f07 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/RxSwift/Tests/RxSwiftTests/Synchronized.swift @@ -0,0 +1,28 @@ +// +// Synchronized.swift +// Tests +// +// Created by Krunoslav Zaher on 1/29/19. +// Copyright © 2019 Krunoslav Zaher. All rights reserved. +// + +import Foundation + +class Synchronized { + private let _lock = NSRecursiveLock() + private var _value: Value + + public init(_ value: Value) { + self._value = value + } + + public var value: Value { + self._lock.lock(); defer { self._lock.unlock() } + return _value + } + + public func mutate(_ mutate: (inout Value) -> R) -> R { + self._lock.lock(); defer { self._lock.unlock() } + return mutate(&_value) + } +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/.swift-version b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/.swift-version deleted file mode 100644 index bf77d54..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/.swift-version +++ /dev/null @@ -1 +0,0 @@ -4.2 diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.md b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.md deleted file mode 100644 index 346890c..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.md +++ /dev/null @@ -1,410 +0,0 @@ -# SwifterSwift Examples - -SwifterSwift is a library of **over 500 properties and methods**, designed to extend Swift's functionality and productivity, staying faithful to the original API design guidelines of Swift 3. - -Here are some examples: - -### Array Extensions: - -```swift -// Remove duplicates from an array -[1, 2, 3, 1, 3].removeDuplicates() -> [1, 2, 3] - -// Return all indices of specified item -["h", "e", "l", "l", "o"].indices(of: "l") -> [2, 3] - -// Shuffle an array -["h", "e", "l", "l", "o"].shuffled() -> ["e", "l", "o", "l", "h"] - -// Return random item from an array -[1, 2, 3, 4, 5].randomItem -> 3 - -// and many others! -``` -[Check All Array Extensions!](http://swifterswift.com/docs/Extensions/Array) - ---- - -### Date Extensions: - -```swift -// Get and set components from date with ease -date.hour = 14 - -// Check if date is in today -Date().isInToday -> true - -// Add 1 month to current date -Date().add(.month, value: 1) - -// Return date at the beginning of current day -Date().beginning(of: .day) - -// Return date at the end of current month -Date().end(of: .month) - -// Check if date is in current calendar unit -Date().isInCurrent(.month) -> true - -// Return iso8601 string for date -Date().iso8601String -> "2016-08-23T21:26:15.287Z" - -// Create date from iso8601 string -let date = Date(iso8601String: "2016-08-23T21:26:15.287Z") - -// Create date from DateComponents -let date = Date(year: 2016, month: 8, day: 15) // other components are set to current by default. -let date = Date(hour: 9, minute: 18, second: 1) // other components are set to current by default. - -// Represent date as a string with ease -Date().dateString(ofStyle: .medium) -> "Aug 26, 2016" -Date().timeString(ofStyle: .short) -> "12:55 AM" -Date().dateTimeString() -> "Aug 26, 2016, 12:55:24 AM" - -// Get day name or month name from a date -Date().dayName(ofStyle: .full) -> "Sunday" -Date().monthName(ofStyle: .threeLetters) -> "Dec" - -// and many others! -``` -[Check All Date Extensions!](http://swifterswift.com/docs/Extensions/Date) - ---- - -### String Extensions: - -```swift -// Return count of substring in string -"hello world".count(of "o", caseSensitive: false) -> 2 - -// Return an array of strings separated by given string -"hello world".split(by: " ") -> ["hello", "world"] - -// Return string with no spaces or new lines in beginning and end -"\n Hello ".trimmed -> "Hello" - -// Return most common character in string -"swifterSwift is making swift more swifty".mostCommonCharacter -> "i" - -// Returns CamelCase of string -"Some variable nAme".camelCased -> "someVariableName" - -// Check if string is in valid email format -"someone@somewebsite.com".isEmail -> true - -// Check if string contains at least one letter and one number -"123abc".isAlphaNumeric -> true - -// Reverse string -"123abc".reverse() -> "cba321" - -// Return latinized string -"Hèllö Wórld!".latinize() -> "Hello World!" - -// Create random string of length -String.random(ofLength: 10) -> "AhEju28kNl" - -// Check if string contains one or more instance of substring -"Hello World!".contain("o", caseSensitive: false) -> true - -// Check if string contains one or more emojis -"string👨‍with😍emojis✊🏿".containEmoji -> true - -// Subscript strings easily -"Hello"[2] -> "l" - -// Slice strings -let s = "Hello world" -s.slicing(from: 6, length: 5) -> "world" -s.slicing(from: 6, to: 11) -> "world" -s.slicing(at: 6) -> "world" - -// Convert string to numbers -"12.12".double -> 12.12 - -// Encode and decode URLs -"it's easy to encode strings".urlEncoded -> "it's%20easy%20to%20encode%20strings" -"it's%20easy%20to%20encode%20strings".urlDecoded -> "it's easy to encode strings" - -// Encode and decode base64 -"Hello World!".base64Encoded -> "SGVsbG8gV29ybGQh" -"SGVsbG8gV29ybGQh".base64Decoded = "Hello World!" - -// Truncate strings with a trailing -"This is a very long sentence".truncated(toLength: 14, trailing: = "...") -> "This is a very..." - -// Repeat a string n times -"s" * 5 -> "sssss" - -// NSString has never been easier -let boldString = "this is string".bold.colored(with: .red) - -// and many others! -``` -[Check All String Extensions!](http://swifterswift.com/docs/Extensions/String) - ---- - -### Dictionary Extensions: - -```swift -let dict = ["id": 1, "Product-Name": "SwifterSwift"] - -// Check if key exists in dictionary. -dict.has(key: "id") -> true - -// Lowercase all keys in dictionary. -dict.lowercaseAllKeys() -> ["id": 1, "product-name": "SwifterSwift"] - -// Create JSON Data and string from a dictionary -let json = dict.jsonString(prettify: true) - -// and many others! -``` -[Check All Dictionary Extensions!](http://swifterswift.com/docs/Extensions/Dictionary) - ---- - - -### Number Types Extensions: - -```swift -// Return square root of a number -√ 9 -> 3 - -// Return square power of a number -5 ** 2 -> 25 - -// Return a number plus or minus another number -5 ± 2 -> (3, 7) - -// Return random number in range -Int.randomBetween(min: 1, max: 10) -> 6 - -// Return roman numeral for a number -134.romanNumeral -> "CXXXIV" - -// and many others! -``` - -[Check All Extensions!](http://swifterswift.com/docs) - ---- - -### UIColor Extensions: - -```swift -// Create new UIColor for RGB values -let color = UIColor(red: 121, green: 220, blue: 164) - -// Create new UIColor for a hex string (including strings starting with #, 0x or in short css hex format) -let color = UIColor(hexString: "#00F") - -// Create new UIColor for a hexadecimal value -let color = UIColor(hex: 0x45C91B) - -// Blend two colors with ease -UIColor.blend(UIColor.red, intensity1: 0.5, with: UIColor.green, intensity2: 0.3) - -// Return hexadecimal value string -UIColor.red.hexString -> "#FF0000" - -// Use Google Material design colors with ease -let indigo = UIColor.material.indigo - -// Use CSS colors with ease: -let beige = UIColor.css.beige - -// Return brand colors from more than 30 social brands -let facebookColor = UIColor.social.facebook - -// and many others! -``` -[Check UIColor Extensions!](http://swifterswift.com/docs/Extensions/UIColor) - ---- - - -### UIView Extensions - -```swift - -// Set borderColor, borderWidth, cornerRadius, shadowColor, and many other properties from code or storyboard -view.cornerRadius = 30 - -// Set some or all corners radiuses of view. -view.roundCorners([.bottomLeft, .topRight], radius: 30) - - -// Add shadow to view -view.addShadow(ofColor .black, radius: 3, opacity: 0.5) - -// Animate view with completion -view.fadeIn(duration: 1, completion:((Bool) -> Void)?) -view.fadeOut(duration: 1, completion:((Bool) -> Void)?) -view.rotate(byAngle 90, ofType type: .degrees, animated: true, duration: 1, completion: { print("done") }) -view.rotate(toAngle -3, ofType type: .radians, animated: false, duration: 1, completion: nil) -view.scale(byOffset: 4, animated: true, duration:1) -view.shake(direction: .horizontal, duration: 1, animationType: .easeOut) - -// save screenshot of a view -let image = view.screenShot - -// and many others! -``` -[Check UIView Extensions!](http://swifterswift.com/docs/Extensions/UIView) - ---- - - -### UIAlertController Extensions - -```swift -// Create a new alert controller from string or Error -let alert = UIAlertController(title: "Couldn't sign in", message: "Invalid username or password!") -let alert = UIAlertController(title: "Error", error: Error) - -// show alert with ease -alert.show() - -// and many others! -``` -[Check UIAlertController Extensions!](http://swifterswift.com/docs/Extensions/UIAlertController) - ---- - -### UIButton Extensions - -```swift - -// Set title, title color and image for all states at once! -button.setTitleForAllStates("Login") -button.setTitleColorForAllStates(UIColor.blue) -button.setImageForAllStates(UIImage(named: "login")) - -// or set each of them from code or storyboard -button.titleForHighlighted = "Login" - -// and many others! -``` - -[Check UIButton Extensions!](http://swifterswift.com/docs/Extensions/UIButton) - ---- - - -### UIImage Extensions - -```swift -// Crop images -let croppedImage = image.cropped(to CGRect) - -// Create UIImage from color -let image = UIImage(color: UIColor, size: CGSize) - -// scale to fit width or height -let scaledImage = image.scaled(toHeight: CGFloat) -let scaledImage = image.scaled(toWidth: CGFloat) - -// Compress images -let compressedImage = image.compressd(quality: 0.3) - -// get image size -image.kilobytesSize -> 114 - -// and many others! -``` -[Check UIImage Extensions!](http://swifterswift.com/docs/Extensions/UIImage) - ---- - - -### UIImageView Extensions - -```swift -// Download an image from URL in background -imageView.download(from url, contentMode: .scaleAspectFit, placeHolder: UIImage?) - -// Blur image view -imageView.blur(withStyle: .light) - -// and many others! -``` -[Check UIImageView Extensions!](http://swifterswift.com/docs/Extensions/UIImageView) - ---- - -### UINavigationBar Extensions - -```swift -// Change navigation bar font and color -navbar.setTitleFont(UIFont.systemFont(ofSize: 10), with color: UIColor.black) - -// and many others! -``` -[Check UINavigationBar Extensions!](http://swifterswift.com/docs/Extensions/UINavigationBar) - ---- - - -### UINavigationController Extensions - -```swift -// Pop ViewController with completion handler. -navController.popViewController(completion: (()->Void)?) - -// Push ViewController with completion handler. -navController.pushViewController(UIViewController, completion: (()->Void)?) - -// and many others! -``` -[Check UINavigationController Extensions!](http://swifterswift.com/docs/Extensions/UINavigationController) - ---- - - -### UITableView Extensions - -```swift -// Return index path for last row in section. -tableView.indexPathForLastRow(in section: 2) - -// Scroll to bottom or top of TableView. -tableView.scrollToBottom(animated: true) -tableView.scrollToTop(animated: true) - -// and many others! -``` - ---- - -### CGPoint Extensions - -```swift -// Get distance from another CGPoint. -point1.distance(from: point2) -> 12.45 - -// Multiply a CGPoint with a scalar -result = 5 * point - -// and many others! -``` - ---- - -## Misc Extensions - -```swift -// Check if app is running in debugging mode -SwifterSwift.isInDebuggingMode - -// Check if app is running on simulator -SwifterSwift.isRunningOnSimulator - -// Detect screenshots -SwifterSwift.didTakeScreenShot { - print("User did take a screenshot!") -} - -// and many others! -``` diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/00-ToC.xcplaygroundpage/Contents.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/00-ToC.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..03447a4 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/00-ToC.xcplaygroundpage/Contents.swift @@ -0,0 +1,16 @@ +/*: + ## SwifterSwift Examples + + SwifterSwift is a library of **over 500 properties and methods**, designed to extend Swift's functionality and productivity, staying faithful to the original API design guidelines. + + You can find examples of some extenstions and try them out in this playground: + + * [SwiftStdlib extensions](01-SwiftStdlibExtensions) + * [Foundation extensions](02-FoundationExtensions) + * [UIKit extensions](03-UIKitExtensions) + * [CoreGraphics extensions](04-CoreGraphicsExtensions) + * [Try yourself](05-TryYourself) + + **Make sure you build the SwifterSwift project before trying to run the playgrounds.** + +*/ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/01-SwiftStdlibExtensions.xcplaygroundpage/Contents.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/01-SwiftStdlibExtensions.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..86208d1 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/01-SwiftStdlibExtensions.xcplaygroundpage/Contents.swift @@ -0,0 +1,111 @@ +//: [Table of Contents](00-ToC) + +//: [Previous](@previous) + +import SwifterSwift + +//: ## SwiftStdlib extensions + +//: ### Array extensions + +// Remove duplicates from an array +var array = ["h", "e", "l", "l", "o"] +array.removeDuplicates() + +//: ### Dictionary extensions + +var dict: [String: Any] = ["id": 1, "Product-Name": "SwifterSwift"] + +// Check if key exists in dictionary. +dict.has(key: "id") + +// Lowercase all keys in dictionary. +dict.lowercaseAllKeys() + +// Create JSON Data and string from a dictionary +let json = dict.jsonString(prettify: true) + +//: ### Int extensions + +// Return square root of a number +√9 + +// Return square power of a number +5 ** 2 + +// Return a number plus or minus another number +5 ± 2 + +// Return roman numeral for a number +134.romanNumeral + +//: ### Random Access Collection extensions + +// Return all indices of specified item +["h", "e", "l", "l", "o"].indices(of: "l") + +//: ### String extensions + +// Return count of substring in string +"hello world".count(of: "", caseSensitive: false) + +// Return string with no spaces or new lines in beginning and end +"\n Hello ".trimmed + +// Return most common character in string +"swifterSwift is making swift more swifty".mostCommonCharacter() + +// Returns CamelCase of string +"Some variable nAme".camelCased + +// Check if string is in valid email format +"someone@somewebsite.com".isEmail + +// Check if string contains at least one letter and one number +"123abc".isAlphaNumeric + +// Reverse string +var str1 = "123abc" +str1.reverse() + +// Return latinized string +var str2 = "Hèllö Wórld!" +str2.latinize() + +// Create random string of length +String.random(ofLength: 10) + +// Check if string contains one or more instance of substring +"Hello World!".contains("o", caseSensitive: false) + +// Check if string contains one or more emojis +"string👨‍with😍emojis✊🏿".containEmoji + +// Subscript strings easily +"Hello"[safe: 2] + +// Slice strings +let str = "Hello world" +str.slicing(from: 6, length: 5) + +// Convert string to numbers +"12.12".double + +// Encode and decode URLs +"it's easy to encode strings".urlEncoded +"it's%20easy%20to%20encode%20strings".urlDecoded + +// Encode and decode base64 +"Hello World!".base64Encoded +"SGVsbG8gV29ybGQh".base64Decoded + +// Truncate strings with a trailing +"This is a very long sentence".truncated(toLength: 14, trailing: "...") + +// Repeat a string n times +"s" * 5 + +// NSString has never been easier +let boldString = "this is string".bold.colored(with: .red) + +//: [Next](@next) diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/02-FoundationExtensions.xcplaygroundpage/Contents.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/02-FoundationExtensions.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..fcfebfd --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/02-FoundationExtensions.xcplaygroundpage/Contents.swift @@ -0,0 +1,46 @@ +//: [Table of Contents](00-ToC) + +//: [Previous](@previous) + +import SwifterSwift + +//: ## Foundation extensions + +//: ### Date extensions + +// Check if date is in today +Date().isInToday + +// Add 1 month to current date +var date = Date() +date.add(.month, value: 1) + +// Return date at the beginning of current day +Date().beginning(of: .day) + +// Return date at the end of current month +Date().end(of: .month) + +// Check if date is in current calendar unit +Date().isInCurrent(.month) + +// Return iso8601 string for date +Date().iso8601String + +// Create date from iso8601 string +let date1 = Date(iso8601String: "2016-08-23T21:26:15.287Z") + +// Create date from DateComponents +let date2 = Date(year: 2016, month: 8, day: 15) // other components are set to current by default. +let date3 = Date(hour: 9, minute: 18, second: 1) // other components are set to current by default. + +// Represent date as a string with ease +Date().dateString(ofStyle: .medium) +Date().timeString(ofStyle: .short) +Date().dateTimeString() + +// Get day name or month name from a date +Date().dayName(ofStyle: .full) +Date().monthName(ofStyle: .threeLetters) + +//: [Next](@next) diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Contents.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..558d3dd --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Contents.swift @@ -0,0 +1,105 @@ +//: [Table of Contents](00-ToC) + +//: [Previous](@previous) + +import SwifterSwift +import PlaygroundSupport + +//: ## UIKit extensions + +//: ### UIButton extensions + +let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 40)) + +// Set title, title color and image for all states at once! +button.setTitleForAllStates("Login") +button.setTitleColorForAllStates(UIColor.blue) +button.setImageForAllStates(UIImage(named: "login")!) + +//: ### UIColor extensions + +// Create new UIColor for RGB values +let color1 = UIColor(red: 121, green: 220, blue: 164) + +// Create new UIColor for a hex string (including strings starting with #, 0x or in short css hex format) +let color2 = UIColor(hexString: "#00F") + +// Create new UIColor for a hexadecimal value +let color3 = UIColor(hex: 0x45C91B) + +// Blend two colors with ease +UIColor.blend(UIColor.red, intensity1: 0.5, with: UIColor.green, intensity2: 0.3) + +// Return hexadecimal value string +UIColor.red.hexString + +// Use Google Material design colors with ease +let indigo = UIColor.Material.indigo + +// Use CSS colors with ease: +let beige = UIColor.CSS.beige + +// Return brand colors from more than 30 social brands +let facebookColor = UIColor.Social.facebook + +//: ### UIImage extensions + +let image1 = UIImage(named: "logo")! + +// Crop images +let croppedImage = image1.cropped(to: CGRect(x: 0, y: 0, width: 100, height: 100)) + +// scale to fit width or height +let scaledImage1 = image1.scaled(toHeight: 50) +let scaledImage2 = image1.scaled(toWidth: 50) + +// Compress images +let compressedImage = image1.compressed(quality: 0.3) + +// get image size +image1.kilobytesSize + +//: ### UIImageView extensions + +let imageView = UIImageView() + +// Download an image from URL in background +PlaygroundPage.current.needsIndefiniteExecution = true +imageView.download(from: URL(string: "https://developer.apple.com/swift/images/swift-og.png")!, + contentMode: .scaleAspectFit, + placeholder: image1, + completionHandler: { downloadedImage in + downloadedImage + PlaygroundPage.current.needsIndefiniteExecution = false + + imageView.sizeToFit() + + // Blur image view + imageView.blur(withStyle: .light) +}) + +//: ### UINavigationBar extensions + +let navbar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: 100, height: 60)) +let navItem = UINavigationItem(title: "Title") +navbar.pushItem(navItem, animated: false) + +// Change navigation bar font and color + +navbar.setTitleFont(UIFont.systemFont(ofSize: 10), color: UIColor.red) + +//: ### UIView extensions + +// Set borderColor, borderWidth, cornerRadius, shadowColor, and many other properties from code or storyboard + +var view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) +view.backgroundColor = UIColor.red + +// Set some or all corners radiuses of view. +view.roundCorners([.bottomLeft, .topRight], radius: 30) +view.cornerRadius = 30 + +// Add shadow to view +view.addShadow(ofColor: .black, radius: 3, opacity: 0.5) + +//: [Next](@next) diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Resources/login.png b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Resources/login.png new file mode 100644 index 0000000..467456c Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Resources/login.png differ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Resources/logo.png b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Resources/logo.png new file mode 100644 index 0000000..910a748 Binary files /dev/null and b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/03-UIKitExtensions.xcplaygroundpage/Resources/logo.png differ diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/04-CoreGraphicsExtensions.xcplaygroundpage/Contents.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/04-CoreGraphicsExtensions.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..113f469 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/04-CoreGraphicsExtensions.xcplaygroundpage/Contents.swift @@ -0,0 +1,22 @@ +//: [Table of Contents](00-ToC) + +//: [Previous](@previous) + +import SwifterSwift + +//: ## CoreGraphics Extensions + +//: ### CGPoint extensions + +let point1 = CGPoint(x: 10, y: 10) +let point2 = CGPoint(x: 30, y: 30) + +// Get distance from another CGPoint. +point1.distance(from: point2) + +let point = CGPoint(x: 10, y: 10) + +// Multiply a CGPoint with a scalar +5 * point + +//: [Next](@next) diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/05-TryYourself.xcplaygroundpage/Contents.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/05-TryYourself.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..2f0b46f --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/Pages/05-TryYourself.xcplaygroundpage/Contents.swift @@ -0,0 +1,10 @@ +//: [Table of Contents](00-ToC) + +//: [Previous](@previous) + +import SwifterSwift + +//: ## Try yourself +//: *Here you can try some extensions yourself* + +//: [Previous](@previous) diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/contents.xcplayground b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/contents.xcplayground new file mode 100644 index 0000000..436ad56 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Examples/Examples.playground/contents.xcplayground @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/Deprecated/CoreGraphicsDeprecated.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/Deprecated/CoreGraphicsDeprecated.swift deleted file mode 100644 index e0de5ea..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/Deprecated/CoreGraphicsDeprecated.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// CoreGraphicsDeprecated.swift -// SwifterSwift -// -// Created by Luciano Almeida on 9/18/18. -// Copyright © 2018 SwifterSwift -// -#if canImport(CoreGraphics) -import CoreGraphics - -// MARK: - Methods -public extension CGFloat { - - /// SwifterSwift: Random CGFloat between two CGFloat values. - /// - /// - Parameters: - /// - min: minimum number to start random from. - /// - max: maximum number random number end before. - /// - Returns: random CGFloat between two CGFloat values. - @available(*, deprecated: 4.5.0, message: "User CGFloat.random(in: min...max)") - public static func randomBetween(min: CGFloat, max: CGFloat) -> CGFloat { - return CGFloat.random(in: min...max) - } - -} -#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/Deprecated/SwiftStdlibDeprecated.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/Deprecated/SwiftStdlibDeprecated.swift deleted file mode 100644 index 824ee30..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/Deprecated/SwiftStdlibDeprecated.swift +++ /dev/null @@ -1,241 +0,0 @@ -// -// SwiftStdlibDeprecated.swift -// SwifterSwift -// -// Copyright © 2016 SwifterSwift -// - -extension Bool { - #if canImport(Foundation) - /// SwifterSwift: Returns a random boolean value. - /// - /// Bool.random -> true - /// Bool.random -> false - /// - @available(*, deprecated: 4.5.0, message: "Use random() instead") - public static var random: Bool { - return arc4random_uniform(2) == 1 - } - #endif -} - -extension String { - - #if canImport(Foundation) - /// SwifterSwift: Check if string is valid email format. - /// **Note that this property does not validate the email address against an email server. It merely attempts to determine whether its format is suitable for an email address.**. - /// - /// "john@doe.com".isEmail -> true - /// - @available(*, deprecated: 4.5.0, message: "Use isValidEmail instead", renamed: "isValidEmail") - public var isEmail: Bool { - // http://emailregex.com/ - let regex = "^(?:[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[\\p{L}0-9](?:[a-z0-9-]*[\\p{L}0-9])?\\.)+[\\p{L}0-9](?:[\\p{L}0-9-]*[\\p{L}0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[\\p{L}0-9-]*[\\p{L}0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$" - return range(of: regex, options: .regularExpression, range: nil, locale: nil) != nil - } - #endif - -} - -public extension Array { - - /// SwifterSwift: Element at the given index if it exists. - /// - /// [1, 2, 3, 4, 5].item(at: 2) -> 3 - /// [1.2, 2.3, 4.5, 3.4, 4.5].item(at: 3) -> 3.4 - /// ["h", "e", "l", "l", "o"].item(at: 10) -> nil - /// - /// - Parameter index: index of element. - /// - Returns: optional element (if exists). - @available(*, deprecated: 4.3, message: "Use subscript(safe:) instead", renamed: "subscript(safe:)") - public func item(at index: Int) -> Element? { - guard startIndex.. [ "evens" : [0, 2, 4], "odds" : [5, 7] ] - /// - /// - Parameter getKey: Clousure to define the key for each element. - /// - Returns: A dictionary with values grouped with keys. - @available(*, deprecated: 4.3, message: "Use 'Dictionary.init(grouping:by:)' instead.") - public func groupByKey(keyForValue: (_ element: Element) throws -> K) rethrows -> [K: [Element]] { - var group = [K: [Element]]() - for value in self { - let key = try keyForValue(value) - group[key] = (group[key] ?? []) + [value] - } - return group - } -} - -public extension Array where Element: Equatable { - - /// SwifterSwift: Return array with all duplicate elements removed. - /// - /// [1, 1, 2, 2, 3, 3, 3, 4, 5].duplicatesRemoved() -> [1, 2, 3, 4, 5]) - /// ["h", "e", "l", "l", "o"].duplicatesRemoved() -> ["h", "e", "l", "o"]) - /// - /// - Returns: an array of unique elements. - /// - @available(*, deprecated: 4.3, message: "Use withoutDuplicates() instead", renamed: "withoutDuplicates") - public func duplicatesRemoved() -> [Element] { - // Thanks to https://github.com/sairamkotha for improving the method - return reduce(into: [Element]()) { - if !$0.contains($1) { - $0.append($1) - } - } - } - - /// SwifterSwift: Remove last element from array and return it. - /// - /// [1, 2, 3, 4, 5].pop() // returns 5 and remove it from the array. - /// [].pop() // returns nil since the array is empty. - /// - /// - Returns: last element in array (if applicable). - @available(*, deprecated: 4.3, message: "Use popLast() instead") - @discardableResult public mutating func pop() -> Element? { - return popLast() - } - - /// SwifterSwift: Insert an element to the end of array. - /// - /// [1, 2, 3, 4].push(5) -> [1, 2, 3, 4, 5] - /// ["h", "e", "l", "l"].push("o") -> ["h", "e", "l", "l", "o"] - /// - /// - Parameter newElement: element to insert. - @available(*, deprecated: 4.3, message: "Use append() instead") - public mutating func push(_ newElement: Element) { - append(newElement) - } - - /// SwifterSwift: Swap values at index positions. - /// - /// [1, 2, 3, 4, 5].swap(from: 3, to: 0) -> [4, 2, 3, 1, 5] - /// ["h", "e", "l", "l", "o"].swap(from: 1, to: 0) -> ["e", "h", "l", "l", "o"] - /// - /// - Parameters: - /// - index: index of first element. - /// - otherIndex: index of other element. - @available(*, deprecated: 4.3, message: "Use swapAt() instead") - public mutating func swap(from index: Int, to otherIndex: Int) { - swapAt(index, otherIndex) - } - -} - -public extension Collection where Index == Int { - - #if canImport(Foundation) - /// SwifterSwift: Random item from array. - @available(*, deprecated: 4.5.0, message: "Use randomElement() instead") - public var randomItem: Element? { - guard !isEmpty else { return nil } - let index = Int(arc4random_uniform(UInt32(count))) - return self[index] - } - #endif -} - -// MARK: - Methods -public extension FloatingPoint { - - #if canImport(Foundation) - /// SwifterSwift: Random number between two number. - /// - /// - Parameters: - /// - min: minimum number to start random from. - /// - max: maximum number random number end before. - /// - Returns: random number between two numbers. - @available(*, deprecated: 4.5.0, message: "Double.random(in: ClosedRange)") - public static func random(between min: Self, and max: Self) -> Self { - let aMin = Self.minimum(min, max) - let aMax = Self.maximum(min, max) - let delta = aMax - aMin - return Self(arc4random()) / Self(UInt64(UINT32_MAX)) * delta + aMin - } - #endif - - #if canImport(Foundation) - /// SwifterSwift: Random number in a closed interval range. - /// - /// - Parameter range: closed interval range. - /// - Returns: random number in the given closed range. - @available(*, deprecated: 4.5.0, message: "Double.random(in: ClosedRange)") - public static func random(inRange range: ClosedRange) -> Self { - let delta = range.upperBound - range.lowerBound - return Self(arc4random()) / Self(UInt64(UINT32_MAX)) * delta + range.lowerBound - } - #endif - -} - -// MARK: - Initializers -public extension FloatingPoint { - - /// SwifterSwift: Created a random number between two numbers. - /// - /// - Parameters: - /// - min: minimum number to start random from. - /// - max: maximum number random number end before. - @available(*, deprecated: 4.5.0, message: "Double.random(in: ClosedRange)") - public init(randomBetween min: Self, and max: Self) { - let aMin = Self.minimum(min, max) - let aMax = Self.maximum(min, max) - let delta = aMax - aMin - self = Self(arc4random()) / Self(UInt64(UINT32_MAX)) * delta + aMin - } - - /// SwifterSwift: Create a random number in a closed interval range. - /// - /// - Parameter range: closed interval range. - @available(*, deprecated: 4.5.0, message: "Double.random(in: ClosedRange)") - public init(randomInRange range: ClosedRange) { - let delta = range.upperBound - range.lowerBound - self = Self(arc4random()) / Self(UInt64(UINT32_MAX)) * delta + range.lowerBound - } - -} - -public extension Int { - - /// SwifterSwift: Random integer between two integer values. - /// - /// - Parameters: - /// - min: minimum number to start random from. - /// - max: maximum number random number end before. - /// - Returns: random double between two double values. - @available(*, deprecated: 4.5.0, message: "Int.random(in: ClosedRange)") - public static func random(between min: Int, and max: Int) -> Int { - return random(in: min...max) - } - - /// SwifterSwift: Random integer in a closed interval range. - /// - /// - Parameter range: closed interval range. - /// - Returns: random double in the given closed range. - @available(*, deprecated: 4.5.0, message: "Int.random(in: ClosedRange)") - public static func random(inRange range: ClosedRange) -> Int { - return random(in: range) - } - - /// SwifterSwift: Created a random integer between two integer values. - /// - /// - Parameters: - /// - min: minimum number to start random from. - /// - max: maximum number random number end before. - @available(*, deprecated: 4.5.0, message: "Int.random(in: ClosedRange)") - public init(randomBetween min: Int, and max: Int) { - self = Int.random(in: min...max) - } - - /// SwifterSwift: Create a random integer in a closed interval range. - /// - /// - Parameter range: closed interval range. - @available(*, deprecated: 4.5.0, message: "Int.random(in: ClosedRange)") - public init(randomInRange range: ClosedRange) { - self = Int.random(in: range) - } -} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/StringProtocolExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/StringProtocolExtensions.swift deleted file mode 100644 index 9f7a556..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/StringProtocolExtensions.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// StringProtocolExtensions.swift -// SwifterSwift -// -// Created by Max Härtwig on 11/26/17. -// Copyright © 2017 SwifterSwift -// - -import Foundation - -public extension StringProtocol where Index == String.Index { - - /// SwifterSwift: The longest common suffix. - /// - /// "Hello world!".commonSuffix(with: "It's cold!") = "ld!" - /// - /// - Parameters: - /// - Parameter aString: The string with which to compare the receiver. - /// - Parameter options: Options for the comparison. - /// - Returns: The longest common suffix of the receiver and the given String - public func commonSuffix(with aString: T, options: String.CompareOptions = []) -> String { - let reversedSuffix = String(reversed()).commonPrefix(with: String(aString.reversed()), options: options) - return String(reversedSuffix.reversed()) - } - -} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwifterSwift.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwifterSwift.swift deleted file mode 100644 index 264cb17..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwifterSwift.swift +++ /dev/null @@ -1,328 +0,0 @@ -// -// SwifterSwift.swift -// SwifterSwift -// -// Created by Omar Albeik on 8/8/16. -// Copyright © 2016 SwifterSwift -// - -#if canImport(UIKit) -import UIKit -#endif - -#if canImport(WatchKit) -import WatchKit -#endif - -#if canImport(Cocoa) -import Cocoa -#endif - -#if !os(Linux) -// MARK: - Properties -/// SwifterSwift: Common usefull properties and methods. -public struct SwifterSwift { - - #if !os(macOS) - /// SwifterSwift: App's name (if applicable). - public static var appDisplayName: String? { - // http://stackoverflow.com/questions/28254377/get-app-name-in-swift - return Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String - } - #endif - - #if !os(macOS) - /// SwifterSwift: App's bundle ID (if applicable). - public static var appBundleID: String? { - return Bundle.main.bundleIdentifier - } - #endif - - #if os(iOS) - /// SwifterSwift: StatusBar height - public static var statusBarHeight: CGFloat { - return UIApplication.shared.statusBarFrame.height - } - #endif - - #if !os(macOS) - /// SwifterSwift: App current build number (if applicable). - public static var appBuild: String? { - return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String - } - #endif - - #if os(iOS) || os(tvOS) - /// SwifterSwift: Application icon badge current number. - public static var applicationIconBadgeNumber: Int { - get { - return UIApplication.shared.applicationIconBadgeNumber - } - set { - UIApplication.shared.applicationIconBadgeNumber = newValue - } - } - #endif - - #if !os(macOS) - /// SwifterSwift: App's current version (if applicable). - public static var appVersion: String? { - return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String - } - #endif - - #if os(iOS) - /// SwifterSwift: Current battery level. - public static var batteryLevel: Float { - return UIDevice.current.batteryLevel - } - #endif - - #if os(iOS) || os(tvOS) - /// SwifterSwift: Shared instance of current device. - public static var currentDevice: UIDevice { - return UIDevice.current - } - #elseif os(watchOS) - /// SwifterSwift: Shared instance of current device. - public static var currentDevice: WKInterfaceDevice { - return WKInterfaceDevice.current() - } - #endif - - #if !os(macOS) - /// SwifterSwift: Screen height. - public static var screenHeight: CGFloat { - #if os(iOS) || os(tvOS) - return UIScreen.main.bounds.height - #elseif os(watchOS) - return currentDevice.screenBounds.height - #endif - } - #endif - - #if !os(macOS) - /// SwifterSwift: Current device model. - public static var deviceModel: String { - return currentDevice.model - } - #endif - - #if !os(macOS) - /// SwifterSwift: Current device name. - public static var deviceName: String { - return currentDevice.name - } - #endif - - #if os(iOS) - /// SwifterSwift: Current orientation of device. - public static var deviceOrientation: UIDeviceOrientation { - return currentDevice.orientation - } - #endif - - #if !os(macOS) - /// SwifterSwift: Screen width. - public static var screenWidth: CGFloat { - #if os(iOS) || os(tvOS) - return UIScreen.main.bounds.width - #elseif os(watchOS) - return currentDevice.screenBounds.width - #endif - } - #endif - - /// SwifterSwift: Check if app is running in debug mode. - public static var isInDebuggingMode: Bool { - // http://stackoverflow.com/questions/9063100/xcode-ios-how-to-determine-whether-code-is-running-in-debug-release-build - #if DEBUG - return true - #else - return false - #endif - } - - #if !os(macOS) - /// SwifterSwift: Check if app is running in TestFlight mode. - public static var isInTestFlight: Bool { - // http://stackoverflow.com/questions/12431994/detect-testflight - return Bundle.main.appStoreReceiptURL?.path.contains("sandboxReceipt") == true - } - #endif - - #if os(iOS) - /// SwifterSwift: Check if multitasking is supported in current device. - public static var isMultitaskingSupported: Bool { - return UIDevice.current.isMultitaskingSupported - } - #endif - - #if os(iOS) - /// SwifterSwift: Current status bar network activity indicator state. - public static var isNetworkActivityIndicatorVisible: Bool { - get { - return UIApplication.shared.isNetworkActivityIndicatorVisible - } - set { - UIApplication.shared.isNetworkActivityIndicatorVisible = newValue - } - } - #endif - - #if os(iOS) - /// SwifterSwift: Check if device is iPad. - public static var isPad: Bool { - return UIDevice.current.userInterfaceIdiom == .pad - } - #endif - - #if os(iOS) - /// SwifterSwift: Check if device is iPhone. - public static var isPhone: Bool { - return UIDevice.current.userInterfaceIdiom == .phone - } - #endif - - #if os(iOS) || os(tvOS) - /// SwifterSwift: Check if device is registered for remote notifications for current app (read-only). - public static var isRegisteredForRemoteNotifications: Bool { - return UIApplication.shared.isRegisteredForRemoteNotifications - } - #endif - - /// SwifterSwift: Check if application is running on simulator (read-only). - public static var isRunningOnSimulator: Bool { - // http://stackoverflow.com/questions/24869481/detect-if-app-is-being-built-for-device-or-simulator-in-swift - #if targetEnvironment(simulator) - return true - #else - return false - #endif - } - - #if os(iOS) - /// SwifterSwift: Status bar visibility state. - public static var isStatusBarHidden: Bool { - get { - return UIApplication.shared.isStatusBarHidden - } - set { - UIApplication.shared.isStatusBarHidden = newValue - } - } - #endif - - #if os(iOS) || os(tvOS) - /// SwifterSwift: Key window (read only, if applicable). - public static var keyWindow: UIView? { - return UIApplication.shared.keyWindow - } - #endif - - #if os(iOS) || os(tvOS) - /// SwifterSwift: Most top view controller (if applicable). - public static var mostTopViewController: UIViewController? { - get { - return UIApplication.shared.keyWindow?.rootViewController - } - set { - UIApplication.shared.keyWindow?.rootViewController = newValue - } - } - #endif - - #if os(iOS) || os(tvOS) - /// SwifterSwift: Shared instance UIApplication. - public static var sharedApplication: UIApplication { - return UIApplication.shared - } - #endif - - #if os(iOS) - /// SwifterSwift: Current status bar style (if applicable). - public static var statusBarStyle: UIStatusBarStyle? { - get { - return UIApplication.shared.statusBarStyle - } - set { - if let style = newValue { - UIApplication.shared.statusBarStyle = style - } - } - } - #endif - - #if !os(macOS) - /// SwifterSwift: System current version (read-only). - public static var systemVersion: String { - return currentDevice.systemVersion - } - #endif - -} - -// MARK: - Methods -public extension SwifterSwift { - - /// SwifterSwift: Delay function or closure call. - /// - /// - Parameters: - /// - milliseconds: execute closure after the given delay. - /// - queue: a queue that completion closure should be executed on (default is DispatchQueue.main). - /// - completion: closure to be executed after delay. - /// - Returns: DispatchWorkItem task. You can call .cancel() on it to cancel delayed execution. - @discardableResult public static func delay(milliseconds: Double, queue: DispatchQueue = .main, completion: @escaping () -> Void) -> DispatchWorkItem { - let task = DispatchWorkItem { completion() } - queue.asyncAfter(deadline: .now() + (milliseconds/1000), execute: task) - return task - } - - /// SwifterSwift: Debounce function or closure call. - /// - /// - Parameters: - /// - millisecondsOffset: allow execution of method if it was not called since millisecondsOffset. - /// - queue: a queue that action closure should be executed on (default is DispatchQueue.main). - /// - action: closure to be executed in a debounced way. - public static func debounce(millisecondsDelay: Int, queue: DispatchQueue = .main, action: @escaping (() -> Void)) -> () -> Void { - // http://stackoverflow.com/questions/27116684/how-can-i-debounce-a-method-call - var lastFireTime = DispatchTime.now() - let dispatchDelay = DispatchTimeInterval.milliseconds(millisecondsDelay) - let dispatchTime: DispatchTime = lastFireTime + dispatchDelay - return { - queue.asyncAfter(deadline: dispatchTime) { - let when: DispatchTime = lastFireTime + dispatchDelay - let now = DispatchTime.now() - if now.rawValue >= when.rawValue { - lastFireTime = DispatchTime.now() - action() - } - } - } - } - - #if os(iOS) || os(tvOS) - /// SwifterSwift: Called when user takes a screenshot - /// - /// - Parameter action: a closure to run when user takes a screenshot - public static func didTakeScreenShot(_ action: @escaping (_ notification: Notification) -> Void) { - // http://stackoverflow.com/questions/13484516/ios-detection-of-screenshot - _ = NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, - object: nil, - queue: OperationQueue.main) { notification in - action(notification) - } - } - #endif - - /// SwifterSwift: Class name of object as string. - /// - /// - Parameter object: Any object to find its class name. - /// - Returns: Class name for given object. - public static func typeName(for object: Any) -> String { - let objectType = type(of: object.self) - return String.init(describing: objectType) - } - -} -#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/Deprecated/UIKitDeprecated.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/Deprecated/UIKitDeprecated.swift deleted file mode 100644 index d8a16d7..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/Deprecated/UIKitDeprecated.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// UIKitDeprecated.swift -// SwifterSwift -// -// Created by Omar Albeik on 5.04.2018. -// Copyright © 2018 SwifterSwift -// - -#if canImport(UIKit) && !os(watchOS) -import UIKit - -public extension UIStoryboard { - - /// SwifterSwift: Get main storyboard for application - @available(*, deprecated: 4.3, message: "Use main instead", renamed: "main") - public static var mainStoryboard: UIStoryboard? { - let bundle = Bundle.main - guard let name = bundle.object(forInfoDictionaryKey: "UIMainStoryboardFile") as? String else { return nil } - return UIStoryboard(name: name, bundle: bundle) - } - -} -#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/AppKit/NSImageExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/AppKit/NSImageExtensions.swift similarity index 81% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/AppKit/NSImageExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/AppKit/NSImageExtensions.swift index 4ea573d..efb4a6b 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/AppKit/NSImageExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/AppKit/NSImageExtensions.swift @@ -16,10 +16,10 @@ extension NSImage { /// /// - Parameter toMaxSize: maximum size /// - Returns: scaled NSImage - public func scaled(toMaxSize: NSSize) -> NSImage { + func scaled(toMaxSize: NSSize) -> NSImage { var ratio: Float = 0.0 - let imageWidth = Float(self.size.width) - let imageHeight = Float(self.size.height) + let imageWidth = Float(size.width) + let imageHeight = Float(size.height) let maxWidth = Float(toMaxSize.width) let maxHeight = Float(toMaxSize.height) @@ -40,8 +40,8 @@ extension NSImage { let newSize: NSSize = NSSize(width: Int(newWidth), height: Int(newHeight)) // Cast the NSImage to a CGImage - var imageRect: CGRect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height) - let imageRef = self.cgImage(forProposedRect: &imageRect, context: nil, hints: nil) + var imageRect: CGRect = CGRect(x: 0, y: 0, width: size.width, height: size.height) + let imageRef = cgImage(forProposedRect: &imageRect, context: nil, hints: nil) // Create NSImage from the CGImage using the new size let imageWithNewSize = NSImage(cgImage: imageRef!, size: newSize) @@ -56,7 +56,7 @@ extension NSImage { /// - url: Desired file URL. /// - type: Type of image (default is .jpeg). /// - compressionFactor: used only for JPEG files. The value is a float between 0.0 and 1.0, with 1.0 resulting in no compression and 0.0 resulting in the maximum compression possible. - public func write(to url: URL, fileType type: NSBitmapImageRep.FileType = .jpeg, compressionFactor: NSNumber = 1.0) { + func write(to url: URL, fileType type: NSBitmapImageRep.FileType = .jpeg, compressionFactor: NSNumber = 1.0) { // https://stackoverflow.com/a/45042611/3882644 guard let data = tiffRepresentation else { return } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/AppKit/NSViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/AppKit/NSViewExtensions.swift similarity index 81% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/AppKit/NSViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/AppKit/NSViewExtensions.swift index ffc9a33..ee27721 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/AppKit/NSViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/AppKit/NSViewExtensions.swift @@ -13,7 +13,8 @@ import Cocoa public extension NSView { /// SwifterSwift: Border color of view; also inspectable from Storyboard. - @IBInspectable public var borderColor: NSColor? { + @IBInspectable + var borderColor: NSColor? { get { guard let color = layer?.borderColor else { return nil } return NSColor(cgColor: color) @@ -25,7 +26,8 @@ public extension NSView { } /// SwifterSwift: Border width of view; also inspectable from Storyboard. - @IBInspectable public var borderWidth: CGFloat { + @IBInspectable + var borderWidth: CGFloat { get { return layer?.borderWidth ?? 0 } @@ -36,7 +38,8 @@ public extension NSView { } /// SwifterSwift: Corner radius of view; also inspectable from Storyboard. - @IBInspectable public var cornerRadius: CGFloat { + @IBInspectable + var cornerRadius: CGFloat { get { return layer?.cornerRadius ?? 0 } @@ -48,7 +51,7 @@ public extension NSView { } // SwifterSwift: Height of view. - public var height: CGFloat { + var height: CGFloat { get { return frame.size.height } @@ -58,7 +61,8 @@ public extension NSView { } /// SwifterSwift: Shadow color of view; also inspectable from Storyboard. - @IBInspectable public var shadowColor: NSColor? { + @IBInspectable + var shadowColor: NSColor? { get { guard let color = layer?.shadowColor else { return nil } return NSColor(cgColor: color) @@ -70,7 +74,8 @@ public extension NSView { } /// SwifterSwift: Shadow offset of view; also inspectable from Storyboard. - @IBInspectable public var shadowOffset: CGSize { + @IBInspectable + var shadowOffset: CGSize { get { return layer?.shadowOffset ?? CGSize.zero } @@ -81,7 +86,8 @@ public extension NSView { } /// SwifterSwift: Shadow opacity of view; also inspectable from Storyboard. - @IBInspectable public var shadowOpacity: Float { + @IBInspectable + var shadowOpacity: Float { get { return layer?.shadowOpacity ?? 0 } @@ -92,7 +98,8 @@ public extension NSView { } /// SwifterSwift: Shadow radius of view; also inspectable from Storyboard. - @IBInspectable public var shadowRadius: CGFloat { + @IBInspectable + var shadowRadius: CGFloat { get { return layer?.shadowRadius ?? 0 } @@ -103,7 +110,7 @@ public extension NSView { } /// SwifterSwift: Size of view. - public var size: CGSize { + var size: CGSize { get { return frame.size } @@ -114,7 +121,7 @@ public extension NSView { } /// SwifterSwift: Width of view. - public var width: CGFloat { + var width: CGFloat { get { return frame.size.width } @@ -131,13 +138,13 @@ extension NSView { /// SwifterSwift: Add array of subviews to view. /// /// - Parameter subviews: array of subviews to add to self. - public func addSubviews(_ subviews: [NSView]) { - subviews.forEach({self.addSubview($0)}) + func addSubviews(_ subviews: [NSView]) { + subviews.forEach { addSubview($0) } } /// SwifterSwift: Remove all subviews in view. - public func removeSubviews() { - subviews.forEach({$0.removeFromSuperview()}) + func removeSubviews() { + subviews.forEach { $0.removeFromSuperview() } } } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGColorExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGColorExtensions.swift similarity index 88% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGColorExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGColorExtensions.swift index e23da14..3470d50 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGColorExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGColorExtensions.swift @@ -22,17 +22,18 @@ public extension CGColor { #if canImport(UIKit) /// SwifterSwift: UIColor. - public var uiColor: UIColor? { + var uiColor: UIColor? { return UIColor(cgColor: self) } #endif #if canImport(Cocoa) /// SwifterSwift: NSColor. - public var nsColor: NSColor? { + var nsColor: NSColor? { return NSColor(cgColor: self) } #endif } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGFloatExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGFloatExtensions.swift similarity index 77% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGFloatExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGFloatExtensions.swift index a9c308e..bed796a 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGFloatExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGFloatExtensions.swift @@ -21,54 +21,55 @@ import Cocoa public extension CGFloat { /// SwifterSwift: Absolute of CGFloat value. - public var abs: CGFloat { + var abs: CGFloat { return Swift.abs(self) } /// SwifterSwift: Ceil of CGFloat value. - public var ceil: CGFloat { + var ceil: CGFloat { return Foundation.ceil(self) } /// SwifterSwift: Radian value of degree input. - public var degreesToRadians: CGFloat { + var degreesToRadians: CGFloat { return .pi * self / 180.0 } /// SwifterSwift: Floor of CGFloat value. - public var floor: CGFloat { + var floor: CGFloat { return Foundation.floor(self) } /// SwifterSwift: Check if CGFloat is positive. - public var isPositive: Bool { + var isPositive: Bool { return self > 0 } /// SwifterSwift: Check if CGFloat is negative. - public var isNegative: Bool { + var isNegative: Bool { return self < 0 } /// SwifterSwift: Int. - public var int: Int { + var int: Int { return Int(self) } /// SwifterSwift: Float. - public var float: Float { + var float: Float { return Float(self) } /// SwifterSwift: Double. - public var double: Double { + var double: Double { return Double(self) } /// SwifterSwift: Degree value of radian input. - public var radiansToDegrees: CGFloat { + var radiansToDegrees: CGFloat { return self * 180 / CGFloat.pi } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGPointExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGPointExtensions.swift similarity index 84% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGPointExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGPointExtensions.swift index 0199ead..a0b3a72 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGPointExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGPointExtensions.swift @@ -29,7 +29,7 @@ public extension CGPoint { /// /// - Parameter point: CGPoint to get distance from. /// - Returns: Distance between self and given CGPoint. - public func distance(from point: CGPoint) -> CGFloat { + func distance(from point: CGPoint) -> CGFloat { return CGPoint.distance(from: self, to: point) } @@ -44,7 +44,7 @@ public extension CGPoint { /// - point1: first CGPoint. /// - point2: second CGPoint. /// - Returns: distance between the two given CGPoints. - public static func distance(from point1: CGPoint, to point2: CGPoint) -> CGFloat { + static func distance(from point1: CGPoint, to point2: CGPoint) -> CGFloat { // http://stackoverflow.com/questions/6416101/calculate-the-distance-between-two-cgpoints return sqrt(pow(point2.x - point1.x, 2) + pow(point2.y - point1.y, 2)) } @@ -65,7 +65,7 @@ public extension CGPoint { /// - lhs: CGPoint to add to. /// - rhs: CGPoint to add. /// - Returns: result of addition of the two given CGPoints. - public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint { + static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint { return CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y) } @@ -79,8 +79,8 @@ public extension CGPoint { /// - Parameters: /// - lhs: self /// - rhs: CGPoint to add. - public static func += (lhs: inout CGPoint, rhs: CGPoint) { - // swiftlint:disable next shorthand_operator + static func += (lhs: inout CGPoint, rhs: CGPoint) { + // swiftlint:disable:next shorthand_operator lhs = lhs + rhs } @@ -95,7 +95,7 @@ public extension CGPoint { /// - lhs: CGPoint to subtract from. /// - rhs: CGPoint to subtract. /// - Returns: result of subtract of the two given CGPoints. - public static func - (lhs: CGPoint, rhs: CGPoint) -> CGPoint { + static func - (lhs: CGPoint, rhs: CGPoint) -> CGPoint { return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y) } @@ -109,8 +109,8 @@ public extension CGPoint { /// - Parameters: /// - lhs: self /// - rhs: CGPoint to subtract. - public static func -= (lhs: inout CGPoint, rhs: CGPoint) { - // swiftlint:disable next shorthand_operator + static func -= (lhs: inout CGPoint, rhs: CGPoint) { + // swiftlint:disable:next shorthand_operator lhs = lhs - rhs } @@ -124,7 +124,7 @@ public extension CGPoint { /// - point: CGPoint to multiply. /// - scalar: scalar value. /// - Returns: result of multiplication of the given CGPoint with the scalar. - public static func * (point: CGPoint, scalar: CGFloat) -> CGPoint { + static func * (point: CGPoint, scalar: CGFloat) -> CGPoint { return CGPoint(x: point.x * scalar, y: point.y * scalar) } @@ -138,8 +138,8 @@ public extension CGPoint { /// - point: self. /// - scalar: scalar value. /// - Returns: result of multiplication of the given CGPoint with the scalar. - public static func *= (point: inout CGPoint, scalar: CGFloat) { - // swiftlint:disable next shorthand_operator + static func *= (point: inout CGPoint, scalar: CGFloat) { + // swiftlint:disable:next shorthand_operator point = point * scalar } @@ -153,9 +153,10 @@ public extension CGPoint { /// - scalar: scalar value. /// - point: CGPoint to multiply. /// - Returns: result of multiplication of the given CGPoint with the scalar. - public static func * (scalar: CGFloat, point: CGPoint) -> CGPoint { + static func * (scalar: CGFloat, point: CGPoint) -> CGPoint { return CGPoint(x: point.x * scalar, y: point.y * scalar) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGSizeExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGSizeExtensions.swift similarity index 89% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGSizeExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGSizeExtensions.swift index d38992b..c12da63 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGSizeExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGSizeExtensions.swift @@ -29,7 +29,7 @@ public extension CGSize { /// /// - Parameter boundingSize: bounding size to fit self to. /// - Returns: self fitted into given bounding size - public func aspectFit(to boundingSize: CGSize) -> CGSize { + func aspectFit(to boundingSize: CGSize) -> CGSize { let minRatio = min(boundingSize.width / width, boundingSize.height / height) return CGSize(width: width * minRatio, height: height * minRatio) } @@ -43,7 +43,7 @@ public extension CGSize { /// /// - Parameter boundingSize: bounding size to fill self to. /// - Returns: self filled into given bounding size - public func aspectFill(to boundingSize: CGSize) -> CGSize { + func aspectFill(to boundingSize: CGSize) -> CGSize { let minRatio = max(boundingSize.width / width, boundingSize.height / height) let aWidth = min(width * minRatio, boundingSize.width) let aHeight = min(height * minRatio, boundingSize.height) @@ -66,7 +66,7 @@ public extension CGSize { /// - lhs: CGSize to add to. /// - rhs: CGSize to add. /// - Returns: The result comes from the addition of the two given CGSize struct. - public static func + (lhs: CGSize, rhs: CGSize) -> CGSize { + static func + (lhs: CGSize, rhs: CGSize) -> CGSize { return CGSize(width: lhs.width + rhs.width, height: lhs.height + rhs.height) } @@ -80,7 +80,7 @@ public extension CGSize { /// - Parameters: /// - lhs: self /// - rhs: CGSize to add. - public static func += (lhs: inout CGSize, rhs: CGSize) { + static func += (lhs: inout CGSize, rhs: CGSize) { lhs.width += rhs.width lhs.height += rhs.height } @@ -96,7 +96,7 @@ public extension CGSize { /// - lhs: CGSize to subtract from. /// - rhs: CGSize to subtract. /// - Returns: The result comes from the subtract of the two given CGSize struct. - public static func - (lhs: CGSize, rhs: CGSize) -> CGSize { + static func - (lhs: CGSize, rhs: CGSize) -> CGSize { return CGSize(width: lhs.width - rhs.width, height: lhs.height - rhs.height) } @@ -110,7 +110,7 @@ public extension CGSize { /// - Parameters: /// - lhs: self /// - rhs: CGSize to subtract. - public static func -= (lhs: inout CGSize, rhs: CGSize) { + static func -= (lhs: inout CGSize, rhs: CGSize) { lhs.width -= rhs.width lhs.height -= rhs.height } @@ -126,7 +126,7 @@ public extension CGSize { /// - lhs: CGSize to multiply. /// - rhs: CGSize to multiply with. /// - Returns: The result comes from the multiplication of the two given CGSize structs. - public static func * (lhs: CGSize, rhs: CGSize) -> CGSize { + static func * (lhs: CGSize, rhs: CGSize) -> CGSize { return CGSize(width: lhs.width * rhs.width, height: lhs.height * rhs.height) } @@ -140,7 +140,7 @@ public extension CGSize { /// - lhs: CGSize to multiply. /// - scalar: scalar value. /// - Returns: The result comes from the multiplication of the given CGSize and scalar. - public static func * (lhs: CGSize, scalar: CGFloat) -> CGSize { + static func * (lhs: CGSize, scalar: CGFloat) -> CGSize { return CGSize(width: lhs.width * scalar, height: lhs.height * scalar) } @@ -154,7 +154,7 @@ public extension CGSize { /// - scalar: scalar value. /// - rhs: CGSize to multiply. /// - Returns: The result comes from the multiplication of the given scalar and CGSize. - public static func * (scalar: CGFloat, rhs: CGSize) -> CGSize { + static func * (scalar: CGFloat, rhs: CGSize) -> CGSize { return CGSize(width: scalar * rhs.width, height: scalar * rhs.height) } @@ -168,7 +168,7 @@ public extension CGSize { /// - Parameters: /// - lhs: self. /// - rhs: CGSize to multiply. - public static func *= (lhs: inout CGSize, rhs: CGSize) { + static func *= (lhs: inout CGSize, rhs: CGSize) { lhs.width *= rhs.width lhs.height *= rhs.height } @@ -182,10 +182,11 @@ public extension CGSize { /// - Parameters: /// - lhs: self. /// - scalar: scalar value. - public static func *= (lhs: inout CGSize, scalar: CGFloat) { + static func *= (lhs: inout CGSize, scalar: CGFloat) { lhs.width *= scalar lhs.height *= scalar } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGVectorExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGVectorExtensions.swift similarity index 86% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGVectorExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGVectorExtensions.swift index 1881f9f..b078346 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreGraphics/CGVectorExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreGraphics/CGVectorExtensions.swift @@ -16,14 +16,14 @@ public extension CGVector { /// The range of the angle is -π to π; an angle of 0 points to the right. /// /// https://en.wikipedia.org/wiki/Atan2 - public var angle: CGFloat { + var angle: CGFloat { return atan2(dy, dx) } /// SwifterSwift: The magnitude (or length) of the vector. /// /// https://en.wikipedia.org/wiki/Euclidean_vector#Length - public var magnitude: CGFloat { + var magnitude: CGFloat { return sqrt((dx * dx) + (dy * dy)) } @@ -42,7 +42,7 @@ public extension CGVector { /// - angle: The angle of rotation (in radians) counterclockwise from the positive x-axis. /// - magnitude: The lenth of the vector. /// - public init(angle: CGFloat, magnitude: CGFloat) { + init(angle: CGFloat, magnitude: CGFloat) { self.init(dx: magnitude * cos(angle), dy: magnitude * sin(angle)) } @@ -60,7 +60,7 @@ public extension CGVector { /// - vector: The vector to be multiplied /// - scalar: The scale by which the vector will be multiplied /// - Returns: The vector with its magnitude scaled - public static func * (vector: CGVector, scalar: CGFloat) -> CGVector { + static func * (vector: CGVector, scalar: CGFloat) -> CGVector { return CGVector(dx: vector.dx * scalar, dy: vector.dy * scalar) } @@ -73,7 +73,7 @@ public extension CGVector { /// - scalar: The scalar by which the vector will be multiplied /// - vector: The vector to be multiplied /// - Returns: The vector with its magnitude scaled - public static func * (scalar: CGFloat, vector: CGVector) -> CGVector { + static func * (scalar: CGFloat, vector: CGVector) -> CGVector { return CGVector(dx: scalar * vector.dx, dy: scalar * vector.dy) } @@ -85,8 +85,8 @@ public extension CGVector { /// - Parameters: /// - vector: The vector to be multiplied /// - scalar: The scale by which the vector will be multiplied - public static func *= (vector: inout CGVector, scalar: CGFloat) { - // swiftlint:disable next shorthand_operator + static func *= (vector: inout CGVector, scalar: CGFloat) { + // swiftlint:disable:next shorthand_operator vector = vector * scalar } @@ -98,7 +98,7 @@ public extension CGVector { /// /// - Parameter vector: The vector to be negated /// - Returns: The negated vector - public static prefix func - (vector: CGVector) -> CGVector { + static prefix func - (vector: CGVector) -> CGVector { return CGVector(dx: -vector.dx, dy: -vector.dy) } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreLocation/CLLocationExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreLocation/CLLocationExtensions.swift similarity index 92% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreLocation/CLLocationExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreLocation/CLLocationExtensions.swift index e563f1a..9b8354e 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/CoreLocation/CLLocationExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/CoreLocation/CLLocationExtensions.swift @@ -18,7 +18,7 @@ public extension CLLocation { /// - start: Start location. /// - end: End location. /// - Returns: Location that represents the half-way point. - public static func midLocation(start: CLLocation, end: CLLocation) -> CLLocation { + static func midLocation(start: CLLocation, end: CLLocation) -> CLLocation { let lat1 = Double.pi * start.coordinate.latitude / 180.0 let long1 = Double.pi * start.coordinate.longitude / 180.0 let lat2 = Double.pi * end.coordinate.latitude / 180.0 @@ -43,7 +43,7 @@ public extension CLLocation { /// /// - Parameter point: End location. /// - Returns: Location that represents the half-way point. - public func midLocation(to point: CLLocation) -> CLLocation { + func midLocation(to point: CLLocation) -> CLLocation { return CLLocation.midLocation(start: self, end: point) } @@ -52,7 +52,7 @@ public extension CLLocation { /// - Parameters: /// - destination: Location to calculate bearing. /// - Returns: Calculated bearing degrees in the range 0° ... 360° - public func bearing(to destination: CLLocation) -> Double { + func bearing(to destination: CLLocation) -> Double { // http://stackoverflow.com/questions/3925942/cllocation-category-for-calculating-bearing-w-haversine-function let lat1 = Double.pi * coordinate.latitude / 180.0 let long1 = Double.pi * coordinate.longitude / 180.0 @@ -71,4 +71,5 @@ public extension CLLocation { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Dispatch/DispatchQueueExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Dispatch/DispatchQueueExtensions.swift new file mode 100644 index 0000000..57ed987 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Dispatch/DispatchQueueExtensions.swift @@ -0,0 +1,49 @@ +// +// DispatchQueueExtensions.swift +// SwifterSwift +// +// Created by Quentin Jin on 2018/10/13. +// Copyright © 2018 SwifterSwift +// + +#if canImport(Dispatch) +import Dispatch + +// MARK: - Properties +public extension DispatchQueue { + + /// SwifterSwift: A Boolean value indicating whether the current + /// dispatch queue is the main queue. + static var isMainQueue: Bool { + enum Static { + static var key: DispatchSpecificKey = { + let key = DispatchSpecificKey() + DispatchQueue.main.setSpecific(key: key, value: ()) + return key + }() + } + return DispatchQueue.getSpecific(key: Static.key) != nil + } + +} + +// MARK: - Methods +public extension DispatchQueue { + + /// SwifterSwift: Returns a Boolean value indicating whether the current + /// dispatch queue is the specified queue. + /// + /// - Parameter queue: The queue to compare against. + /// - Returns: `true` if the current queue is the specified queue, otherwise `false`. + static func isCurrent(_ queue: DispatchQueue) -> Bool { + let key = DispatchSpecificKey() + + queue.setSpecific(key: key, value: ()) + defer { queue.setSpecific(key: key, value: nil) } + + return DispatchQueue.getSpecific(key: key) != nil + } + +} + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/CalendarExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/CalendarExtensions.swift similarity index 91% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/CalendarExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/CalendarExtensions.swift index 918c3b1..7d18969 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/CalendarExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/CalendarExtensions.swift @@ -19,9 +19,10 @@ public extension Calendar { /// /// - Parameter date: the date form which the number of days in month is calculated. /// - Returns: The number of days in the month of 'Date'. - public func numberOfDaysInMonth(for date: Date) -> Int { + func numberOfDaysInMonth(for date: Date) -> Int { return range(of: .day, in: .month, for: date)!.count } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/DataExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/DataExtensions.swift similarity index 87% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/DataExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/DataExtensions.swift index 1584377..a73392f 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/DataExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/DataExtensions.swift @@ -13,7 +13,7 @@ import Foundation public extension Data { /// SwifterSwift: Return data as an array of bytes. - public var bytes: [UInt8] { + var bytes: [UInt8] { // http://stackoverflow.com/questions/38097710/swift-3-changes-for-getbytes-method return [UInt8](self) } @@ -27,7 +27,7 @@ public extension Data { /// /// - Parameter encoding: encoding. /// - Returns: String by encoding Data using the given encoding (if applicable). - public func string(encoding: String.Encoding) -> String? { + func string(encoding: String.Encoding) -> String? { return String(data: self, encoding: encoding) } @@ -38,9 +38,10 @@ public extension Data { /// For possible values, see `JSONSerialization.ReadingOptions`. /// - Returns: A Foundation object from the JSON data in the receiver, or `nil` if an error occurs. /// - Throws: An `NSError` if the receiver does not represent a valid JSON object. - public func jsonObject(options: JSONSerialization.ReadingOptions = []) throws -> Any { + func jsonObject(options: JSONSerialization.ReadingOptions = []) throws -> Any { return try JSONSerialization.jsonObject(with: self, options: options) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/DateExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/DateExtensions.swift similarity index 85% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/DateExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/DateExtensions.swift index 91c8aac..d19d123 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/DateExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/DateExtensions.swift @@ -17,7 +17,8 @@ public extension Date { /// - threeLetters: 3 letter day abbreviation of day name. /// - oneLetter: 1 letter day abbreviation of day name. /// - full: Full day name. - public enum DayNameStyle { + enum DayNameStyle { + /// 3 letter day abbreviation of day name. case threeLetters @@ -26,6 +27,7 @@ public extension Date { /// Full day name. case full + } /// SwifterSwift: Month name format. @@ -33,7 +35,8 @@ public extension Date { /// - threeLetters: 3 letter month abbreviation of month name. /// - oneLetter: 1 letter month abbreviation of month name. /// - full: Full month name. - public enum MonthNameStyle { + enum MonthNameStyle { + /// 3 letter month abbreviation of month name. case threeLetters @@ -42,6 +45,7 @@ public extension Date { /// Full month name. case full + } } @@ -50,7 +54,7 @@ public extension Date { public extension Date { /// SwifterSwift: User’s current calendar. - public var calendar: Calendar { + var calendar: Calendar { return Calendar.current } @@ -58,7 +62,7 @@ public extension Date { /// /// Date().era -> 1 /// - public var era: Int { + var era: Int { return Calendar.current.component(.era, from: self) } @@ -66,7 +70,7 @@ public extension Date { /// /// Date().quarter -> 3 // date in third quarter of the year. /// - public var quarter: Int { + var quarter: Int { let month = Double(Calendar.current.component(.month, from: self)) let numberOfMonths = Double(Calendar.current.monthSymbols.count) let numberOfMonthsInQuarter = numberOfMonths / 4 @@ -77,7 +81,7 @@ public extension Date { /// /// Date().weekOfYear -> 2 // second week in the year. /// - public var weekOfYear: Int { + var weekOfYear: Int { return Calendar.current.component(.weekOfYear, from: self) } @@ -85,7 +89,7 @@ public extension Date { /// /// Date().weekOfMonth -> 3 // date is in third week of the month. /// - public var weekOfMonth: Int { + var weekOfMonth: Int { return Calendar.current.component(.weekOfMonth, from: self) } @@ -96,7 +100,7 @@ public extension Date { /// var someDate = Date() /// someDate.year = 2000 // sets someDate's year to 2000 /// - public var year: Int { + var year: Int { get { return Calendar.current.component(.year, from: self) } @@ -117,7 +121,7 @@ public extension Date { /// var someDate = Date() /// someDate.month = 10 // sets someDate's month to 10. /// - public var month: Int { + var month: Int { get { return Calendar.current.component(.month, from: self) } @@ -140,7 +144,7 @@ public extension Date { /// var someDate = Date() /// someDate.day = 1 // sets someDate's day of month to 1. /// - public var day: Int { + var day: Int { get { return Calendar.current.component(.day, from: self) } @@ -160,7 +164,7 @@ public extension Date { /// /// Date().weekday -> 5 // fifth day in the current week. /// - public var weekday: Int { + var weekday: Int { return Calendar.current.component(.weekday, from: self) } @@ -171,7 +175,7 @@ public extension Date { /// var someDate = Date() /// someDate.hour = 13 // sets someDate's hour to 1 pm. /// - public var hour: Int { + var hour: Int { get { return Calendar.current.component(.hour, from: self) } @@ -194,7 +198,7 @@ public extension Date { /// var someDate = Date() /// someDate.minute = 10 // sets someDate's minutes to 10. /// - public var minute: Int { + var minute: Int { get { return Calendar.current.component(.minute, from: self) } @@ -217,7 +221,7 @@ public extension Date { /// var someDate = Date() /// someDate.second = 15 // sets someDate's seconds to 15. /// - public var second: Int { + var second: Int { get { return Calendar.current.component(.second, from: self) } @@ -240,7 +244,7 @@ public extension Date { /// var someDate = Date() /// someDate.nanosecond = 981379985 // sets someDate's seconds to 981379985. /// - public var nanosecond: Int { + var nanosecond: Int { get { return Calendar.current.component(.nanosecond, from: self) } @@ -264,7 +268,7 @@ public extension Date { /// var someDate = Date() /// someDate.millisecond = 68 // sets someDate's nanosecond to 68000000. /// - public var millisecond: Int { + var millisecond: Int { get { return Calendar.current.component(.nanosecond, from: self) / 1000000 } @@ -283,7 +287,7 @@ public extension Date { /// /// Date(timeInterval: 100, since: Date()).isInFuture -> true /// - public var isInFuture: Bool { + var isInFuture: Bool { return self > Date() } @@ -291,7 +295,7 @@ public extension Date { /// /// Date(timeInterval: -100, since: Date()).isInPast -> true /// - public var isInPast: Bool { + var isInPast: Bool { return self < Date() } @@ -299,7 +303,7 @@ public extension Date { /// /// Date().isInToday -> true /// - public var isInToday: Bool { + var isInToday: Bool { return Calendar.current.isDateInToday(self) } @@ -307,7 +311,7 @@ public extension Date { /// /// Date().isInYesterday -> false /// - public var isInYesterday: Bool { + var isInYesterday: Bool { return Calendar.current.isDateInYesterday(self) } @@ -315,32 +319,32 @@ public extension Date { /// /// Date().isInTomorrow -> false /// - public var isInTomorrow: Bool { + var isInTomorrow: Bool { return Calendar.current.isDateInTomorrow(self) } /// SwifterSwift: Check if date is within a weekend period. - public var isInWeekend: Bool { + var isInWeekend: Bool { return Calendar.current.isDateInWeekend(self) } /// SwifterSwift: Check if date is within a weekday period. - public var isWorkday: Bool { + var isWorkday: Bool { return !Calendar.current.isDateInWeekend(self) } /// SwifterSwift: Check if date is within the current week. - public var isInCurrentWeek: Bool { + var isInCurrentWeek: Bool { return Calendar.current.isDate(self, equalTo: Date(), toGranularity: .weekOfYear) } /// SwifterSwift: Check if date is within the current month. - public var isInCurrentMonth: Bool { + var isInCurrentMonth: Bool { return Calendar.current.isDate(self, equalTo: Date(), toGranularity: .month) } /// SwifterSwift: Check if date is within the current year. - public var isInCurrentYear: Bool { + var isInCurrentYear: Bool { return Calendar.current.isDate(self, equalTo: Date(), toGranularity: .year) } @@ -348,7 +352,7 @@ public extension Date { /// /// Date().iso8601String -> "2017-01-12T14:51:29.574Z" /// - public var iso8601String: String { + var iso8601String: String { // https://github.com/justinmakaila/NSDate-ISO-8601/blob/master/NSDateISO8601.swift let dateFormatter = DateFormatter() dateFormatter.locale = Locale(identifier: "en_US_POSIX") @@ -367,7 +371,7 @@ public extension Date { /// date.minute = 44 // "5:44 PM" /// date.nearestFiveMinutes // "5:45 PM" /// - public var nearestFiveMinutes: Date { + var nearestFiveMinutes: Date { var components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second, .nanosecond], from: self) let min = components.minute! components.minute! = min % 5 < 3 ? min - min % 5 : min + 5 - (min % 5) @@ -385,7 +389,7 @@ public extension Date { /// date.minute = 48 // "5:48 PM" /// date.nearestTenMinutes // "5:50 PM" /// - public var nearestTenMinutes: Date { + var nearestTenMinutes: Date { var components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second, .nanosecond], from: self) let min = components.minute! components.minute? = min % 10 < 6 ? min - min % 10 : min + 10 - (min % 10) @@ -403,7 +407,7 @@ public extension Date { /// date.minute = 40 // "5:40 PM" /// date.nearestQuarterHour // "5:45 PM" /// - public var nearestQuarterHour: Date { + var nearestQuarterHour: Date { var components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second, .nanosecond], from: self) let min = components.minute! components.minute! = min % 15 < 8 ? min - min % 15 : min + 15 - (min % 15) @@ -421,7 +425,7 @@ public extension Date { /// date.minute = 51 // "6:51 PM" /// date.nearestHalfHour // "7:00 PM" /// - public var nearestHalfHour: Date { + var nearestHalfHour: Date { var components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second, .nanosecond], from: self) let min = components.minute! components.minute! = min % 30 < 15 ? min - min % 30 : min + 30 - (min % 30) @@ -438,7 +442,7 @@ public extension Date { /// date.minute = 36 // "6:36 PM" /// date.nearestHour // "7:00 PM" /// - public var nearestHour: Date { + var nearestHour: Date { let min = Calendar.current.component(.minute, from: self) let components: Set = [.year, .month, .day, .hour] let date = Calendar.current.date(from: Calendar.current.dateComponents(components, from: self))! @@ -449,19 +453,29 @@ public extension Date { return Calendar.current.date(byAdding: .hour, value: 1, to: date)! } - /// SwifterSwift: Time zone used currently by system. + /// SwifterSwift: Yesterday date. + /// + /// let date = Date() // "Oct 3, 2018, 10:57:11" + /// let yesterday = date.yesterday // "Oct 2, 2018, 10:57:11" + /// + var yesterday: Date { + return addingTimeInterval(-86400.0) + } + + /// SwifterSwift: Tomorrow's date. /// - /// Date().timeZone -> Europe/Istanbul (current) + /// let date = Date() // "Oct 3, 2018, 10:57:11" + /// let tomorrow = date.tomorrow // "Oct 4, 2018, 10:57:11" /// - public var timeZone: TimeZone { - return Calendar.current.timeZone + var tomorrow: Date { + return addingTimeInterval(86400.0) } /// SwifterSwift: UNIX timestamp from date. /// /// Date().unixTimestamp -> 1484233862.826291 /// - public var unixTimestamp: Double { + var unixTimestamp: Double { return timeIntervalSince1970 } @@ -482,7 +496,7 @@ public extension Date { /// - component: component type. /// - value: multiples of components to add. /// - Returns: original date + multiples of component added. - public func adding(_ component: Calendar.Component, value: Int) -> Date { + func adding(_ component: Calendar.Component, value: Int) -> Date { return Calendar.current.date(byAdding: component, value: value, to: self)! } @@ -497,14 +511,12 @@ public extension Date { /// - Parameters: /// - component: component type. /// - value: multiples of compnenet to add. - public mutating func add(_ component: Calendar.Component, value: Int) { + mutating func add(_ component: Calendar.Component, value: Int) { if let date = Calendar.current.date(byAdding: component, value: value, to: self) { self = date } } - // swiftlint:disable function_body_length, function_body_length - // swiftlint:disable cyclomatic_complexity /// SwifterSwift: Date by changing value of calendar component. /// /// let date = Date() // "Jan 12, 2017, 7:07 PM" @@ -517,7 +529,8 @@ public extension Date { /// - component: component type. /// - value: new value of compnenet to change. /// - Returns: original date after changing given component to given value. - public func changing(_ component: Calendar.Component, value: Int) -> Date? { + // swiftlint:disable:next cyclomatic_complexity function_body_length + func changing(_ component: Calendar.Component, value: Int) -> Date? { switch component { case .nanosecond: let allowedRange = Calendar.current.range(of: .nanosecond, in: .second, for: self)! @@ -582,7 +595,7 @@ public extension Date { /// /// - Parameter component: calendar component to get date at the beginning of. /// - Returns: date at the beginning of calendar component (if applicable). - public func beginning(of component: Calendar.Component) -> Date? { + func beginning(of component: Calendar.Component) -> Date? { if component == .day { return Calendar.current.startOfDay(for: self) } @@ -616,7 +629,6 @@ public extension Date { return Calendar.current.date(from: Calendar.current.dateComponents(components, from: self)) } - // swiftlint:disable function_body_length /// SwifterSwift: Date at the end of calendar component. /// /// let date = Date() // "Jan 12, 2017, 7:27 PM" @@ -626,7 +638,8 @@ public extension Date { /// /// - Parameter component: calendar component to get date at the end of. /// - Returns: date at the end of calendar component (if applicable). - public func end(of component: Calendar.Component) -> Date? { + // swiftlint:disable:next function_body_length + func end(of component: Calendar.Component) -> Date? { switch component { case .second: var date = adding(.second, value: 1) @@ -689,7 +702,7 @@ public extension Date { /// /// - Parameter component: calendar component to check. /// - Returns: true if date is in current given calendar component. - public func isInCurrent(_ component: Calendar.Component) -> Bool { + func isInCurrent(_ component: Calendar.Component) -> Bool { return Calendar.current.isDate(self, equalTo: Date(), toGranularity: component) } @@ -701,7 +714,7 @@ public extension Date { /// /// - Parameter format: Date format (default is "dd/MM/yyyy"). /// - Returns: date string. - public func string(withFormat format: String = "dd/MM/yyyy HH:mm") -> String { + func string(withFormat format: String = "dd/MM/yyyy HH:mm") -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = format return dateFormatter.string(from: self) @@ -716,7 +729,7 @@ public extension Date { /// /// - Parameter style: DateFormatter style (default is .medium). /// - Returns: date string. - public func dateString(ofStyle style: DateFormatter.Style = .medium) -> String { + func dateString(ofStyle style: DateFormatter.Style = .medium) -> String { let dateFormatter = DateFormatter() dateFormatter.timeStyle = .none dateFormatter.dateStyle = style @@ -732,7 +745,7 @@ public extension Date { /// /// - Parameter style: DateFormatter style (default is .medium). /// - Returns: date and time string. - public func dateTimeString(ofStyle style: DateFormatter.Style = .medium) -> String { + func dateTimeString(ofStyle style: DateFormatter.Style = .medium) -> String { let dateFormatter = DateFormatter() dateFormatter.timeStyle = style dateFormatter.dateStyle = style @@ -748,7 +761,7 @@ public extension Date { /// /// - Parameter style: DateFormatter style (default is .medium). /// - Returns: time string. - public func timeString(ofStyle style: DateFormatter.Style = .medium) -> String { + func timeString(ofStyle style: DateFormatter.Style = .medium) -> String { let dateFormatter = DateFormatter() dateFormatter.timeStyle = style dateFormatter.dateStyle = .none @@ -763,7 +776,7 @@ public extension Date { /// /// - Parameter Style: style of day name (default is DayNameStyle.full). /// - Returns: day name string (example: W, Wed, Wednesday). - public func dayName(ofStyle style: DayNameStyle = .full) -> String { + func dayName(ofStyle style: DayNameStyle = .full) -> String { // http://www.codingexplorer.com/swiftly-getting-human-readable-date-nsdateformatter/ let dateFormatter = DateFormatter() var format: String { @@ -788,7 +801,7 @@ public extension Date { /// /// - Parameter Style: style of month name (default is MonthNameStyle.full). /// - Returns: month name string (example: D, Dec, December). - public func monthName(ofStyle style: MonthNameStyle = .full) -> String { + func monthName(ofStyle style: MonthNameStyle = .full) -> String { // http://www.codingexplorer.com/swiftly-getting-human-readable-date-nsdateformatter/ let dateFormatter = DateFormatter() var format: String { @@ -809,7 +822,7 @@ public extension Date { /// /// - Parameter date: date to compate self to. /// - Returns: number of seconds between self and given date. - public func secondsSince(_ date: Date) -> Double { + func secondsSince(_ date: Date) -> Double { return timeIntervalSince(date) } @@ -817,7 +830,7 @@ public extension Date { /// /// - Parameter date: date to compate self to. /// - Returns: number of minutes between self and given date. - public func minutesSince(_ date: Date) -> Double { + func minutesSince(_ date: Date) -> Double { return timeIntervalSince(date)/60 } @@ -825,7 +838,7 @@ public extension Date { /// /// - Parameter date: date to compate self to. /// - Returns: number of hours between self and given date. - public func hoursSince(_ date: Date) -> Double { + func hoursSince(_ date: Date) -> Double { return timeIntervalSince(date)/3600 } @@ -833,7 +846,7 @@ public extension Date { /// /// - Parameter date: date to compate self to. /// - Returns: number of days between self and given date. - public func daysSince(_ date: Date) -> Double { + func daysSince(_ date: Date) -> Double { return timeIntervalSince(date)/(3600*24) } @@ -844,7 +857,7 @@ public extension Date { /// - endDate: endDate date to compare self to. /// - includeBounds: true if the start and end date should be included (default is false) /// - Returns: true if the date is between the two given dates. - public func isBetween(_ startDate: Date, _ endDate: Date, includeBounds: Bool = false) -> Bool { + func isBetween(_ startDate: Date, _ endDate: Date, includeBounds: Bool = false) -> Bool { if includeBounds { return startDate.compare(self).rawValue * compare(endDate).rawValue >= 0 } @@ -858,34 +871,52 @@ public extension Date { /// - component: Calendar.Component to use. /// - date: Date to compare self to. /// - Returns: true if the date is within a number of components of another date - public func isWithin(_ value: UInt, _ component: Calendar.Component, of date: Date) -> Bool { + func isWithin(_ value: UInt, _ component: Calendar.Component, of date: Date) -> Bool { let components = Calendar.current.dateComponents([component], from: self, to: date) let componentValue = components.value(for: component)! return abs(componentValue) <= value } - /// SwifterSwift: Random date between two dates. + /// SwifterSwift: Returns a random date within the specified range. /// - /// Date.random() - /// Date.random(from: Date()) - /// Date.random(upTo: Date()) - /// Date.random(from: Date(), upTo: Date()) + /// - Parameter range: The range in which to create a random date. `range` must not be empty. + /// - Returns: A random date within the bounds of `range`. + static func random(in range: Range) -> Date { + return Date(timeIntervalSinceReferenceDate: + TimeInterval.random(in: range.lowerBound.timeIntervalSinceReferenceDate.. Date { - guard fromDate != toDate else { - return fromDate - } + /// - Parameter range: The range in which to create a random date. + /// - Returns: A random date within the bounds of `range`. + static func random(in range: ClosedRange) -> Date { + return Date(timeIntervalSinceReferenceDate: + TimeInterval.random(in: range.lowerBound.timeIntervalSinceReferenceDate...range.upperBound.timeIntervalSinceReferenceDate)) + } - let diff = llabs(Int64(toDate.timeIntervalSinceReferenceDate - fromDate.timeIntervalSinceReferenceDate)) - var randomValue: Int64 = Int64.random(in: Int64.min...Int64.max) - randomValue = llabs(randomValue%diff) + /// SwifterSwift: Returns a random date within the specified range, using the given generator as a source for randomness. + /// + /// - Parameters: + /// - range: The range in which to create a random date. `range` must not be empty. + /// - generator: The random number generator to use when creating the new random date. + /// - Returns: A random date within the bounds of `range`. + static func random(in range: Range, using generator: inout T) -> Date where T: RandomNumberGenerator { + return Date(timeIntervalSinceReferenceDate: + TimeInterval.random(in: range.lowerBound.timeIntervalSinceReferenceDate.. fromDate ? fromDate : toDate - return startReferenceDate.addingTimeInterval(TimeInterval(randomValue)) + /// SwifterSwift: Returns a random date within the specified range, using the given generator as a source for randomness. + /// + /// - Parameters: + /// - range: The range in which to create a random date. + /// - generator: The random number generator to use when creating the new random date. + /// - Returns: A random date within the bounds of `range`. + static func random(in range: ClosedRange, using generator: inout T) -> Date where T: RandomNumberGenerator { + return Date(timeIntervalSinceReferenceDate: + TimeInterval.random(in: range.lowerBound.timeIntervalSinceReferenceDate...range.upperBound.timeIntervalSinceReferenceDate, + using: &generator)) } } @@ -908,9 +939,9 @@ public extension Date { /// - minute: Minute (default is current minute). /// - second: Second (default is current second). /// - nanosecond: Nanosecond (default is current nanosecond). - public init?( + init?( calendar: Calendar? = Calendar.current, - timeZone: TimeZone? = TimeZone.current, + timeZone: TimeZone? = NSTimeZone.default, era: Int? = Date().era, year: Int? = Date().year, month: Int? = Date().month, @@ -932,11 +963,8 @@ public extension Date { components.second = second components.nanosecond = nanosecond - if let date = calendar?.date(from: components) { - self = date - } else { - return nil - } + guard let date = calendar?.date(from: components) else { return nil } + self = date } /// SwifterSwift: Create date object from ISO8601 string. @@ -944,17 +972,14 @@ public extension Date { /// let date = Date(iso8601String: "2017-01-12T16:48:00.959Z") // "Jan 12, 2017, 7:48 PM" /// /// - Parameter iso8601String: ISO8601 string of format (yyyy-MM-dd'T'HH:mm:ss.SSSZ). - public init?(iso8601String: String) { + init?(iso8601String: String) { // https://github.com/justinmakaila/NSDate-ISO-8601/blob/master/NSDateISO8601.swift let dateFormatter = DateFormatter() dateFormatter.locale = Locale(identifier: "en_US_POSIX") dateFormatter.timeZone = TimeZone.current dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" - if let date = dateFormatter.date(from: iso8601String) { - self = date - } else { - return nil - } + guard let date = dateFormatter.date(from: iso8601String) else { return nil } + self = date } /// SwifterSwift: Create new date object from UNIX timestamp. @@ -962,7 +987,7 @@ public extension Date { /// let date = Date(unixTimestamp: 1484239783.922743) // "Jan 12, 2017, 7:49 PM" /// /// - Parameter unixTimestamp: UNIX timestamp. - public init(unixTimestamp: Double) { + init(unixTimestamp: Double) { self.init(timeIntervalSince1970: unixTimestamp) } @@ -970,7 +995,7 @@ public extension Date { /// /// let date = Date(integerLiteral: 2017_12_25) // "2017-12-25 00:00:00 +0000" /// - Parameter value: Int value, e.g. 20171225, or 2017_12_25 etc. - public init?(integerLiteral value: Int) { + init?(integerLiteral value: Int) { let formatter = DateFormatter() formatter.dateFormat = "yyyyMMdd" guard let date = formatter.date(from: String(value)) else { return nil } @@ -978,4 +1003,5 @@ public extension Date { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/FileManagerExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/FileManagerExtensions.swift similarity index 63% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/FileManagerExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/FileManagerExtensions.swift index 8c4a678..dfbe3bf 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/FileManagerExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/FileManagerExtensions.swift @@ -18,7 +18,7 @@ public extension FileManager { /// - options: JSONSerialization reading options. /// - Returns: Optional dictionary. /// - Throws: Throws any errors thrown by Data creation or JSON serialization. - public func jsonFromFile( + func jsonFromFile( atPath path: String, readingOptions: JSONSerialization.ReadingOptions = .allowFragments) throws -> [String: Any]? { @@ -36,7 +36,7 @@ public extension FileManager { /// - readingOptions: JSONSerialization reading options. /// - Returns: Optional dictionary. /// - Throws: Throws any errors thrown by Data creation or JSON serialization. - public func jsonFromFile( + func jsonFromFile( withFilename filename: String, at bundleClass: AnyClass? = nil, readingOptions: JSONSerialization.ReadingOptions = .allowFragments) throws -> [String: Any]? { @@ -56,5 +56,29 @@ public extension FileManager { return nil } + /// Creates a unique directory for saving temporary files. + /// + /// The directory can be used to create multiple temporary files used for a common purpose. + /// + /// let tempDirectory = try fileManager.createTemporaryDirectory() + /// let tempFile1URL = tempDirectory.appendingPathComponent(ProcessInfo().globallyUniqueString) + /// let tempFile2URL = tempDirectory.appendingPathComponent(ProcessInfo().globallyUniqueString) + /// + /// - Returns: A URL to a new directory for saving temporary files. + /// - Throws: An error if a temporary directory cannot be found or created. + func createTemporaryDirectory() throws -> URL { + let temporaryDirectoryURL: URL + if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) { + temporaryDirectoryURL = temporaryDirectory + } else { + temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) + } + return try url(for: .itemReplacementDirectory, + in: .userDomainMask, + appropriateFor: temporaryDirectoryURL, + create: true) + } + } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/LocaleExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/LocaleExtensions.swift similarity index 90% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/LocaleExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/LocaleExtensions.swift index 4481630..2d9724b 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/LocaleExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/LocaleExtensions.swift @@ -13,9 +13,10 @@ import Foundation public extension Locale { /// SwifterSwift: UNIX representation of locale usually used for normalizing. - public static var posix: Locale { + static var posix: Locale { return Locale(identifier: "en_US_POSIX") } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/NSAttributedStringExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/NSAttributedStringExtensions.swift similarity index 82% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/NSAttributedStringExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/NSAttributedStringExtensions.swift index 78e4f45..c902697 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/NSAttributedStringExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/NSAttributedStringExtensions.swift @@ -6,7 +6,7 @@ // Copyright © 2016 SwifterSwift // -#if canImport(Foundation) +#if canImport(Foundation) && !os(Linux) import Foundation #if canImport(UIKit) @@ -22,30 +22,31 @@ public extension NSAttributedString { #if os(iOS) /// SwifterSwift: Bolded string. - public var bolded: NSAttributedString { + var bolded: NSAttributedString { return applying(attributes: [.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) } #endif /// SwifterSwift: Underlined string. - public var underlined: NSAttributedString { + var underlined: NSAttributedString { return applying(attributes: [.underlineStyle: NSUnderlineStyle.single.rawValue]) } #if os(iOS) /// SwifterSwift: Italicized string. - public var italicized: NSAttributedString { + var italicized: NSAttributedString { return applying(attributes: [.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) } #endif /// SwifterSwift: Struckthrough string. - public var struckthrough: NSAttributedString { + var struckthrough: NSAttributedString { return applying(attributes: [.strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue as Int)]) } /// SwifterSwift: Dictionary of the attributes applied across the whole string - public var attributes: [NSAttributedString.Key: Any] { + var attributes: [NSAttributedString.Key: Any] { + guard self.length > 0 else { return [:] } return attributes(at: 0, effectiveRange: nil) } @@ -71,7 +72,7 @@ public extension NSAttributedString { /// /// - Parameter color: text color. /// - Returns: a NSAttributedString colored with given color. - public func colored(with color: NSColor) -> NSAttributedString { + func colored(with color: NSColor) -> NSAttributedString { return applying(attributes: [.foregroundColor: color]) } #else @@ -79,7 +80,7 @@ public extension NSAttributedString { /// /// - Parameter color: text color. /// - Returns: a NSAttributedString colored with given color. - public func colored(with color: UIColor) -> NSAttributedString { + func colored(with color: UIColor) -> NSAttributedString { return applying(attributes: [.foregroundColor: color]) } #endif @@ -90,7 +91,7 @@ public extension NSAttributedString { /// - attributes: Dictionary of attributes /// - pattern: a regular expression to target /// - Returns: An NSAttributedString with attributes applied to substrings matching the pattern - public func applying(attributes: [NSAttributedString.Key: Any], toRangesMatching pattern: String) -> NSAttributedString { + func applying(attributes: [NSAttributedString.Key: Any], toRangesMatching pattern: String) -> NSAttributedString { guard let pattern = try? NSRegularExpression(pattern: pattern, options: []) else { return self } let matches = pattern.matches(in: string, options: [], range: NSRange(0..(attributes: [NSAttributedString.Key: Any], toOccurrencesOf target: T) -> NSAttributedString { + func applying(attributes: [NSAttributedString.Key: Any], toOccurrencesOf target: T) -> NSAttributedString { let pattern = "\\Q\(target)\\E" return applying(attributes: attributes, toRangesMatching: pattern) @@ -125,7 +126,7 @@ public extension NSAttributedString { /// - Parameters: /// - lhs: NSAttributedString to add to. /// - rhs: NSAttributedString to add. - public static func += (lhs: inout NSAttributedString, rhs: NSAttributedString) { + static func += (lhs: inout NSAttributedString, rhs: NSAttributedString) { let string = NSMutableAttributedString(attributedString: lhs) string.append(rhs) lhs = string @@ -137,7 +138,7 @@ public extension NSAttributedString { /// - lhs: NSAttributedString to add. /// - rhs: NSAttributedString to add. /// - Returns: New instance with added NSAttributedString. - public static func + (lhs: NSAttributedString, rhs: NSAttributedString) -> NSAttributedString { + static func + (lhs: NSAttributedString, rhs: NSAttributedString) -> NSAttributedString { let string = NSMutableAttributedString(attributedString: lhs) string.append(rhs) return NSAttributedString(attributedString: string) @@ -148,7 +149,7 @@ public extension NSAttributedString { /// - Parameters: /// - lhs: NSAttributedString to add to. /// - rhs: String to add. - public static func += (lhs: inout NSAttributedString, rhs: String) { + static func += (lhs: inout NSAttributedString, rhs: String) { lhs += NSAttributedString(string: rhs) } @@ -158,9 +159,10 @@ public extension NSAttributedString { /// - lhs: NSAttributedString to add. /// - rhs: String to add. /// - Returns: New instance with added NSAttributedString. - public static func + (lhs: NSAttributedString, rhs: String) -> NSAttributedString { + static func + (lhs: NSAttributedString, rhs: String) -> NSAttributedString { return lhs + NSAttributedString(string: rhs) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/NSPredicateExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/NSPredicateExtensions.swift similarity index 79% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/NSPredicateExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/NSPredicateExtensions.swift index c6d5e6e..e0b3394 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/NSPredicateExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/NSPredicateExtensions.swift @@ -13,7 +13,7 @@ import Foundation public extension NSPredicate { /// SwifterSwift: Returns a new predicate formed by NOT-ing the predicate. - public var not: NSCompoundPredicate { + var not: NSCompoundPredicate { return NSCompoundPredicate(notPredicateWithSubpredicate: self) } @@ -26,7 +26,7 @@ public extension NSPredicate { /// /// - Parameter predicate: NSPredicate /// - Returns: NSCompoundPredicate - public func and(_ predicate: NSPredicate) -> NSCompoundPredicate { + func and(_ predicate: NSPredicate) -> NSCompoundPredicate { return NSCompoundPredicate(andPredicateWithSubpredicates: [self, predicate]) } @@ -34,7 +34,7 @@ public extension NSPredicate { /// /// - Parameter predicate: NSPredicate /// - Returns: NSCompoundPredicate - public func or(_ predicate: NSPredicate) -> NSCompoundPredicate { + func or(_ predicate: NSPredicate) -> NSCompoundPredicate { return NSCompoundPredicate(orPredicateWithSubpredicates: [self, predicate]) } @@ -46,7 +46,7 @@ public extension NSPredicate { /// SwifterSwift: Returns a new predicate formed by NOT-ing the predicate. /// - Parameters: rhs: NSPredicate to convert. /// - Returns: NSCompoundPredicate - static public prefix func ! (rhs: NSPredicate) -> NSCompoundPredicate { + static prefix func ! (rhs: NSPredicate) -> NSCompoundPredicate { return rhs.not } @@ -56,7 +56,7 @@ public extension NSPredicate { /// - lhs: NSPredicate. /// - rhs: NSPredicate. /// - Returns: NSCompoundPredicate - static public func + (lhs: NSPredicate, rhs: NSPredicate) -> NSCompoundPredicate { + static func + (lhs: NSPredicate, rhs: NSPredicate) -> NSCompoundPredicate { return lhs.and(rhs) } @@ -66,7 +66,7 @@ public extension NSPredicate { /// - lhs: NSPredicate. /// - rhs: NSPredicate. /// - Returns: NSCompoundPredicate - static public func | (lhs: NSPredicate, rhs: NSPredicate) -> NSCompoundPredicate { + static func | (lhs: NSPredicate, rhs: NSPredicate) -> NSCompoundPredicate { return lhs.or(rhs) } @@ -76,9 +76,10 @@ public extension NSPredicate { /// - lhs: NSPredicate. /// - rhs: NSPredicate. /// - Returns: NSCompoundPredicate - static public func - (lhs: NSPredicate, rhs: NSPredicate) -> NSCompoundPredicate { + static func - (lhs: NSPredicate, rhs: NSPredicate) -> NSCompoundPredicate { return lhs + !rhs } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/URLExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/URLExtensions.swift similarity index 87% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/URLExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/URLExtensions.swift index cd7a99e..2bd026d 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/URLExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/URLExtensions.swift @@ -18,7 +18,7 @@ import AVFoundation public extension URL { /// SwifterSwift: Dictionary of the URL's query parameters - public var queryParameters: [String: String]? { + var queryParameters: [String: String]? { guard let components = URLComponents(url: self, resolvingAgainstBaseURL: false), let queryItems = components.queryItems else { return nil } var items: [String: String] = [:] @@ -43,7 +43,7 @@ public extension URL { /// /// - Parameter parameters: parameters dictionary. /// - Returns: URL with appending given query parameters. - public func appendingQueryParameters(_ parameters: [String: String]) -> URL { + func appendingQueryParameters(_ parameters: [String: String]) -> URL { var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: true)! var items = urlComponents.queryItems ?? [] items += parameters.map({ URLQueryItem(name: $0, value: $1) }) @@ -59,7 +59,7 @@ public extension URL { /// print(url) // prints "https://google.com?q=Swifter%20Swift" /// /// - Parameter parameters: parameters dictionary. - public mutating func appendQueryParameters(_ parameters: [String: String]) { + mutating func appendQueryParameters(_ parameters: [String: String]) { self = appendingQueryParameters(parameters) } @@ -69,8 +69,8 @@ public extension URL { /// queryValue(for: "code") -> "12345" /// /// - Parameter key: The key of a query value. - public func queryValue(for key: String) -> String? { - let stringURL = self.absoluteString + func queryValue(for key: String) -> String? { + let stringURL = absoluteString guard let items = URLComponents(string: stringURL)?.queryItems else { return nil } for item in items where item.name == key { return item.value @@ -84,7 +84,7 @@ public extension URL { /// print(url.deletingAllPathComponents()) // prints "https://domain.com/" /// /// - Returns: URL with all path components removed. - public func deletingAllPathComponents() -> URL { + func deletingAllPathComponents() -> URL { var url: URL = self for _ in 0.. URL? { - if let scheme = self.scheme { - let droppedScheme = String(self.absoluteString.dropFirst(scheme.count + 3)) + func droppedScheme() -> URL? { + if let scheme = scheme { + let droppedScheme = String(absoluteString.dropFirst(scheme.count + 3)) return URL(string: droppedScheme) } @@ -137,7 +137,7 @@ public extension URL { /// /// - Parameter time: Seconds into the video where the image should be generated. /// - Returns: The UIImage result of the AVAssetImageGenerator - public func thumbnail(fromTime time: Float64 = 0) -> UIImage? { + func thumbnail(fromTime time: Float64 = 0) -> UIImage? { let imageGenerator = AVAssetImageGenerator(asset: AVAsset(url: self)) let time = CMTimeMakeWithSeconds(time, preferredTimescale: 1) var actualTime = CMTimeMake(value: 0, timescale: 0) @@ -150,4 +150,5 @@ public extension URL { #endif } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/URLRequestExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/URLRequestExtensions.swift similarity index 92% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/URLRequestExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/URLRequestExtensions.swift index 33455e9..20f5884 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/URLRequestExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/URLRequestExtensions.swift @@ -15,10 +15,11 @@ public extension URLRequest { /// SwifterSwift: Create URLRequest from URL string. /// /// - Parameter urlString: URL string to initialize URL request from - public init?(urlString: String) { + init?(urlString: String) { guard let url = URL(string: urlString) else { return nil } self.init(url: url) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/UserDefaultsExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/UserDefaultsExtensions.swift similarity index 75% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/UserDefaultsExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/UserDefaultsExtensions.swift index 779b203..4279a6c 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Foundation/UserDefaultsExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Foundation/UserDefaultsExtensions.swift @@ -6,7 +6,7 @@ // Copyright © 2017 SwifterSwift // -#if canImport(Foundation) +#if canImport(Foundation) && !os(Linux) import Foundation // MARK: - Methods @@ -15,7 +15,7 @@ public extension UserDefaults { /// SwifterSwift: get object from UserDefaults by using subscript /// /// - Parameter key: key in the current user's defaults database. - public subscript(key: String) -> Any? { + subscript(key: String) -> Any? { get { return object(forKey: key) } @@ -28,7 +28,7 @@ public extension UserDefaults { /// /// - Parameter forKey: key to find float for. /// - Returns: Float object for key (if exists). - public func float(forKey key: String) -> Float? { + func float(forKey key: String) -> Float? { return object(forKey: key) as? Float } @@ -36,7 +36,7 @@ public extension UserDefaults { /// /// - Parameter forKey: key to find date for. /// - Returns: Date object for key (if exists). - public func date(forKey key: String) -> Date? { + func date(forKey key: String) -> Date? { return object(forKey: key) as? Date } @@ -47,8 +47,8 @@ public extension UserDefaults { /// - key: Identifier of the object. /// - decoder: Custom JSONDecoder instance. Defaults to `JSONDecoder()`. /// - Returns: Codable object for key (if exists). - public func object(_ type: T.Type, with key: String, usingDecoder decoder: JSONDecoder = JSONDecoder()) -> T? { - guard let data = self.value(forKey: key) as? Data else { return nil } + func object(_ type: T.Type, with key: String, usingDecoder decoder: JSONDecoder = JSONDecoder()) -> T? { + guard let data = value(forKey: key) as? Data else { return nil } return try? decoder.decode(type.self, from: data) } @@ -58,10 +58,11 @@ public extension UserDefaults { /// - object: Codable object to store. /// - key: Identifier of the object. /// - encoder: Custom JSONEncoder instance. Defaults to `JSONEncoder()`. - public func set(object: T, forKey key: String, usingEncoder encoder: JSONEncoder = JSONEncoder()) { + func set(object: T, forKey key: String, usingEncoder encoder: JSONEncoder = JSONEncoder()) { let data = try? encoder.encode(object) - self.set(data, forKey: key) + set(data, forKey: key) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/MapKit/MKMapViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/MapKit/MKMapViewExtensions.swift new file mode 100644 index 0000000..8db04f7 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/MapKit/MKMapViewExtensions.swift @@ -0,0 +1,51 @@ +// +// MKMapViewExtensions.swift +// SwifterSwift +// +// Created by Hannes Staffler on 24.01.19. +// Copyright © 2019 SwifterSwift +// + +#if canImport(MapKit) +import MapKit + +#if !os(watchOS) +@available(tvOS 9.2, *) +public extension MKMapView { + + /// SwifterSwift: Dequeue reusable MKAnnotationView using class type + /// + /// - Parameters: + /// - name: MKAnnotationView type. + /// - Returns: optional MKAnnotationView object. + func dequeueReusableAnnotationView(withClass name: T.Type) -> T? { + return dequeueReusableAnnotationView(withIdentifier: String(describing: name)) as? T + } + + /// SwifterSwift: Register MKAnnotationView using class type + /// + /// - Parameter name: MKAnnotationView type. + @available(iOS 11.0, tvOS 11.0, macOS 10.13, *) + func register(annotationViewWithClass name: T.Type) { + register(T.self, forAnnotationViewWithReuseIdentifier: String(describing: name)) + } + + /// SwifterSwift: Dequeue reusable MKAnnotationView using class type + /// + /// - Parameters: + /// - name: MKAnnotationView type. + /// - annotation: annotation of the mapView. + /// - Returns: optional MKAnnotationView object. + @available(iOS 11.0, tvOS 11.0, macOS 10.13, *) + func dequeueReusableAnnotationView(withClass name: T.Type, for annotation: MKAnnotation) -> T? { + guard let annotationView = dequeueReusableAnnotationView(withIdentifier: String(describing: name), for: annotation) as? T else { + fatalError("Couldn't find MKAnnotationView for \(String(describing: name))") + } + + return annotationView + } + +} +#endif + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/MapKit/MKPolylineExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/MapKit/MKPolylineExtensions.swift similarity index 82% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/MapKit/MKPolylineExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/MapKit/MKPolylineExtensions.swift index e072e83..6b7fe21 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/MapKit/MKPolylineExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/MapKit/MKPolylineExtensions.swift @@ -6,38 +6,34 @@ // Copyright © 2018 SwifterSwift // -#if canImport(MapKit) +#if canImport(MapKit) && !os(watchOS) import MapKit // MARK: - Initializers -#if !os(watchOS) @available(tvOS 9.2, *) public extension MKPolyline { /// SwifterSwift: Create a new MKPolyline from a provided Array of coordinates. /// /// - Parameter coordinates: Array of CLLocationCoordinate2D(s). - public convenience init(coordinates: [CLLocationCoordinate2D]) { + convenience init(coordinates: [CLLocationCoordinate2D]) { var refCoordinates = coordinates self.init(coordinates: &refCoordinates, count: refCoordinates.count) } } -#endif -#if !os(watchOS) // MARK: - Properties @available(tvOS 9.2, *) public extension MKPolyline { /// SwifterSwift: Return an Array of coordinates representing the provided polyline. - public var coordinates: [CLLocationCoordinate2D] { + var coordinates: [CLLocationCoordinate2D] { var coords = [CLLocationCoordinate2D](repeating: kCLLocationCoordinate2DInvalid, count: pointCount) getCoordinates(&coords, range: NSRange(location: 0, length: pointCount)) return coords } } -#endif #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Shared/ColorExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Shared/ColorExtensions.swift similarity index 97% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Shared/ColorExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Shared/ColorExtensions.swift index 152b329..ec7f3a1 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/Shared/ColorExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/Shared/ColorExtensions.swift @@ -6,6 +6,8 @@ // Copyright © 2017 SwifterSwift // +#if !os(Linux) + #if canImport(UIKit) import UIKit /// Color @@ -22,26 +24,25 @@ public typealias Color = NSColor import CoreImage #endif -#if !os(Linux) // MARK: - Properties public extension Color { /// SwifterSwift: Random color. - public static var random: Color { + static var random: Color { let red = Int.random(in: 0...255) let green = Int.random(in: 0...255) let blue = Int.random(in: 0...255) return Color(red: red, green: green, blue: blue)! } - // swiftlint:disable next large_tuple /// SwifterSwift: RGB components for a Color (between 0 and 255). /// - /// UIColor.red.rgbComponents.red -> 255 - /// NSColor.green.rgbComponents.green -> 255 - /// UIColor.blue.rgbComponents.blue -> 255 + /// UIColor.red.rgbComponents.red -> 255 + /// NSColor.green.rgbComponents.green -> 255 + /// UIColor.blue.rgbComponents.blue -> 255 /// - public var rgbComponents: (red: Int, green: Int, blue: Int) { + // swiftlint:disable:next large_tuple + var rgbComponents: (red: Int, green: Int, blue: Int) { var components: [CGFloat] { let comps = cgColor.components! if comps.count == 4 { return comps } @@ -53,14 +54,14 @@ public extension Color { return (red: Int(red * 255.0), green: Int(green * 255.0), blue: Int(blue * 255.0)) } - // swiftlint:disable next large_tuple /// SwifterSwift: RGB components for a Color represented as CGFloat numbers (between 0 and 1) /// - /// UIColor.red.rgbComponents.red -> 1.0 - /// NSColor.green.rgbComponents.green -> 1.0 - /// UIColor.blue.rgbComponents.blue -> 1.0 + /// UIColor.red.rgbComponents.red -> 1.0 + /// NSColor.green.rgbComponents.green -> 1.0 + /// UIColor.blue.rgbComponents.blue -> 1.0 /// - public var cgFloatComponents: (red: CGFloat, green: CGFloat, blue: CGFloat) { + // swiftlint:disable:next large_tuple + var cgFloatComponents: (red: CGFloat, green: CGFloat, blue: CGFloat) { var components: [CGFloat] { let comps = cgColor.components! if comps.count == 4 { return comps } @@ -72,9 +73,9 @@ public extension Color { return (red: red, green: green, blue: blue) } - // swiftlint:disable next large_tuple /// SwifterSwift: Get components of hue, saturation, and brightness, and alpha (read-only). - public var hsbaComponents: (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) { + // swiftlint:disable:next large_tuple + var hsbaComponents: (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) { var hue: CGFloat = 0.0 var saturation: CGFloat = 0.0 var brightness: CGFloat = 0.0 @@ -85,7 +86,7 @@ public extension Color { } /// SwifterSwift: Hexadecimal value string (read-only). - public var hexString: String { + var hexString: String { let components: [Int] = { let comps = cgColor.components! let components = comps.count == 4 ? comps : [comps[0], comps[0], comps[0], comps[1]] @@ -95,7 +96,7 @@ public extension Color { } /// SwifterSwift: Short hexadecimal value string (read-only, if applicable). - public var shortHexString: String? { + var shortHexString: String? { let string = hexString.replacingOccurrences(of: "#", with: "") let chrs = Array(string) guard chrs[0] == chrs[1], chrs[2] == chrs[3], chrs[4] == chrs[5] else { return nil } @@ -103,7 +104,7 @@ public extension Color { } /// SwifterSwift: Short hexadecimal value string, or full hexadecimal string if not possible (read-only). - public var shortHexOrHexString: String { + var shortHexOrHexString: String { let components: [Int] = { let comps = cgColor.components! let components = comps.count == 4 ? comps : [comps[0], comps[0], comps[0], comps[1]] @@ -117,19 +118,19 @@ public extension Color { } /// SwifterSwift: Alpha of Color (read-only). - public var alpha: CGFloat { + var alpha: CGFloat { return cgColor.alpha } #if !os(watchOS) /// SwifterSwift: CoreImage.CIColor (read-only) - public var coreImageColor: CoreImage.CIColor? { + var coreImageColor: CoreImage.CIColor? { return CoreImage.CIColor(color: self) } #endif /// SwifterSwift: Get UInt representation of a Color (read-only). - public var uInt: UInt { + var uInt: UInt { let comps: [CGFloat] = { let comps = cgColor.components! return comps.count == 4 ? comps : [comps[0], comps[0], comps[0], comps[1]] @@ -144,7 +145,7 @@ public extension Color { } /// SwifterSwift: Get color complementary (read-only, if applicable). - public var complementary: Color? { + var complementary: Color? { let colorSpaceRGB = CGColorSpaceCreateDeviceRGB() let convertColorToRGBSpace: ((_ color: Color) -> Color?) = { color -> Color? in if self.cgColor.colorSpace!.model == CGColorSpaceModel.monochrome { @@ -181,7 +182,7 @@ public extension Color { /// - color2: second color to blend /// - intensity2: intensity of second color (default is 0.5) /// - Returns: Color created by blending first and seond colors. - public static func blend(_ color1: Color, intensity1: CGFloat = 0.5, with color2: Color, intensity2: CGFloat = 0.5) -> Color { + static func blend(_ color1: Color, intensity1: CGFloat = 0.5, with color2: Color, intensity2: CGFloat = 0.5) -> Color { // http://stackoverflow.com/questions/27342715/blend-uicolors-in-swift let total = intensity1 + intensity2 @@ -228,10 +229,10 @@ public extension Color { /// /// - Parameter percentage: Percentage by which to lighten the color /// - Returns: A lightened color - public func lighten(by percentage: CGFloat = 0.2) -> Color { + func lighten(by percentage: CGFloat = 0.2) -> Color { // https://stackoverflow.com/questions/38435308/swift-get-lighter-and-darker-color-variations-for-a-given-uicolor var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0 - self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) + getRed(&red, green: &green, blue: &blue, alpha: &alpha) return Color(red: min(red + percentage, 1.0), green: min(green + percentage, 1.0), blue: min(blue + percentage, 1.0), @@ -245,10 +246,10 @@ public extension Color { /// /// - Parameter percentage: Percentage by which to darken the color /// - Returns: A darkened color - public func darken(by percentage: CGFloat = 0.2) -> Color { + func darken(by percentage: CGFloat = 0.2) -> Color { // https://stackoverflow.com/questions/38435308/swift-get-lighter-and-darker-color-variations-for-a-given-uicolor var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0 - self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) + getRed(&red, green: &green, blue: &blue, alpha: &alpha) return Color(red: max(red - percentage, 0), green: max(green - percentage, 0), blue: max(blue - percentage, 0), @@ -267,7 +268,7 @@ public extension Color { /// - green: green component. /// - blue: blue component. /// - transparency: optional transparency value (default is 1). - public convenience init?(red: Int, green: Int, blue: Int, transparency: CGFloat = 1) { + convenience init?(red: Int, green: Int, blue: Int, transparency: CGFloat = 1) { guard red >= 0 && red <= 255 else { return nil } guard green >= 0 && green <= 255 else { return nil } guard blue >= 0 && blue <= 255 else { return nil } @@ -284,7 +285,7 @@ public extension Color { /// - Parameters: /// - hex: hex Int (example: 0xDECEB5). /// - transparency: optional transparency value (default is 1). - public convenience init?(hex: Int, transparency: CGFloat = 1) { + convenience init?(hex: Int, transparency: CGFloat = 1) { var trans = transparency if trans < 0 { trans = 0 } if trans > 1 { trans = 1 } @@ -300,7 +301,7 @@ public extension Color { /// - Parameters: /// - hexString: hexadecimal string (examples: EDE7F6, 0xEDE7F6, #EDE7F6, #0ff, 0xF0F, ..). /// - transparency: optional transparency value (default is 1). - public convenience init?(hexString: String, transparency: CGFloat = 1) { + convenience init?(hexString: String, transparency: CGFloat = 1) { var string = "" if hexString.lowercased().hasPrefix("0x") { string = hexString.replacingOccurrences(of: "0x", with: "") @@ -331,7 +332,7 @@ public extension Color { /// SwifterSwift: Create Color from a complementary of a Color (if applicable). /// /// - Parameter color: color of which opposite color is desired. - public convenience init?(complementaryFor color: Color) { + convenience init?(complementaryFor color: Color) { let colorSpaceRGB = CGColorSpaceCreateDeviceRGB() let convertColorToRGBSpace: ((_ color: Color) -> Color?) = { color -> Color? in if color.cgColor.colorSpace!.model == CGColorSpaceModel.monochrome { @@ -356,14 +357,15 @@ public extension Color { } -// swiftlint:disable next type_body_length // MARK: - Social public extension Color { /// SwifterSwift: Brand identity color of popular social media platform. - public struct Social { + struct Social { // https://www.lockedowndesign.com/social-media-colors/ + private init() {} + /// red: 59, green: 89, blue: 152 public static let facebook = Color(red: 59, green: 89, blue: 152)! @@ -441,6 +443,9 @@ public extension Color { /// red: 255, green: 252, blue: 0 public static let snapchat = Color(red: 255, green: 252, blue: 0)! + + /// red: 37, green: 211, blue: 102 + public static let whatsApp = Color(red: 37, green: 211, blue: 102)! } } @@ -449,9 +454,12 @@ public extension Color { public extension Color { /// SwifterSwift: Google Material design colors palette. - public struct Material { + // swiftlint:disable:next type_body_length + struct Material { // https://material.google.com/style/color.html + private init() {} + /// SwifterSwift: color red500 public static let red = red500 @@ -1284,9 +1292,11 @@ public extension Color { public extension Color { /// SwifterSwift: CSS colors. - public struct CSS { + struct CSS { // http://www.w3schools.com/colors/colors_names.asp + private init() {} + /// SwifterSwift: hex #F0F8FF public static let aliceBlue = Color(hex: 0xF0F8FF)! @@ -1738,7 +1748,7 @@ public extension Color { public extension Color { /// SwifterSwift: Flat UI colors - public struct FlatUI { + struct FlatUI { // http://flatuicolors.com. /// SwifterSwift: hex #1ABC9C diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SpriteKit/SKNodeExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SpriteKit/SKNodeExtensions.swift similarity index 91% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SpriteKit/SKNodeExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SpriteKit/SKNodeExtensions.swift index 55bd30c..c41e468 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SpriteKit/SKNodeExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SpriteKit/SKNodeExtensions.swift @@ -16,9 +16,10 @@ public extension SKNode { /// /// mySKNode.descendants() -> [childNodeOne, childNodeTwo] /// - public func descendants() -> [SKNode] { + func descendants() -> [SKNode] { return children + children.reduce(into: [SKNode]()) { $0 += $1.descendants() } } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/ArrayExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/ArrayExtensions.swift similarity index 64% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/ArrayExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/ArrayExtensions.swift index 9971655..d514750 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/ArrayExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/ArrayExtensions.swift @@ -5,9 +5,6 @@ // Created by Omar Albeik on 8/5/16. // Copyright © 2016 SwifterSwift // -#if canImport(Foundation) -import Foundation -#endif // MARK: - Methods public extension Array { @@ -18,11 +15,11 @@ public extension Array { /// ["e", "l", "l", "o"].prepend("h") -> ["h", "e", "l", "l", "o"] /// /// - Parameter newElement: element to insert. - public mutating func prepend(_ newElement: Element) { + mutating func prepend(_ newElement: Element) { insert(newElement, at: 0) } - /// SwifterSwift: Safely Swap values at index positions. + /// SwifterSwift: Safely swap values at given index positions. /// /// [1, 2, 3, 4, 5].safeSwap(from: 3, to: 0) -> [4, 2, 3, 1, 5] /// ["h", "e", "l", "l", "o"].safeSwap(from: 1, to: 0) -> ["e", "h", "l", "l", "o"] @@ -30,62 +27,20 @@ public extension Array { /// - Parameters: /// - index: index of first element. /// - otherIndex: index of other element. - public mutating func safeSwap(from index: Index, to otherIndex: Index) { + mutating func safeSwap(from index: Index, to otherIndex: Index) { guard index != otherIndex else { return } guard startIndex.. [0, 2, 4] - /// - /// - Parameter condition: condition to evaluate each element against. - /// - Returns: self after applying provided condition. - /// - Throws: provided condition exception. - @discardableResult - public mutating func keep(while condition: (Element) throws -> Bool) rethrows -> [Element] { - for (index, element) in lazy.enumerated() where try !condition(element) { - self = Array(self[startIndex.. [0, 2, 4] - /// - /// - Parameter condition: condition to evaluate each element against. - /// - Returns: All elements up until condition evaluates to false. - public func take(while condition: (Element) throws -> Bool) rethrows -> [Element] { - for (index, element) in lazy.enumerated() where try !condition(element) { - return Array(self[startIndex.. [6, 8] - /// - /// - Parameter condition: condition to evaluate each element against. - /// - Returns: All elements after the condition evaluates to false. - public func skip(while condition: (Element) throws-> Bool) rethrows -> [Element] { - for (index, element) in lazy.enumerated() where try !condition(element) { - return Array(self[index.. ( [0, 2, 4], [1, 3, 5] ) /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: Two arrays, the first containing the elements for which the specified condition evaluates to true, the second containing the rest. - public func divided(by condition: (Element) throws -> Bool) rethrows -> (matching: [Element], nonMatching: [Element]) { + func divided(by condition: (Element) throws -> Bool) rethrows -> (matching: [Element], nonMatching: [Element]) { //Inspired by: http://ruby-doc.org/core-2.5.0/Enumerable.html#method-i-partition var matching = [Element]() var nonMatching = [Element]() @@ -100,10 +55,10 @@ public extension Array { /// - Parameter path: Key path to sort. The key path type must be Comparable. /// - Parameter ascending: If order must be ascending. /// - Returns: Sorted array based on keyPath. - public func sorted(by path: KeyPath, ascending: Bool = true) -> [Element] { + func sorted(by path: KeyPath, ascending: Bool = true) -> [Element] { return sorted(by: { (lhs, rhs) -> Bool in guard let lhsValue = lhs[keyPath: path], let rhsValue = rhs[keyPath: path] else { return false } - return ascending ? lhsValue < rhsValue : lhsValue > rhsValue + return ascending ? (lhsValue < rhsValue) : (lhsValue > rhsValue) }) } @@ -112,9 +67,9 @@ public extension Array { /// - Parameter path: Key path to sort. The key path type must be Comparable. /// - Parameter ascending: If order must be ascending. /// - Returns: Sorted array based on keyPath. - public func sorted(by path: KeyPath, ascending: Bool = true) -> [Element] { + func sorted(by path: KeyPath, ascending: Bool = true) -> [Element] { return sorted(by: { (lhs, rhs) -> Bool in - return ascending ? lhs[keyPath: path] < rhs[keyPath: path] : lhs[keyPath: path] > rhs[keyPath: path] + return ascending ? (lhs[keyPath: path] < rhs[keyPath: path]) : (lhs[keyPath: path] > rhs[keyPath: path]) }) } @@ -125,7 +80,7 @@ public extension Array { /// - ascending: whether order is ascending or not. /// - Returns: self after sorting. @discardableResult - public mutating func sort(by path: KeyPath, ascending: Bool = true) -> [Element] { + mutating func sort(by path: KeyPath, ascending: Bool = true) -> [Element] { self = sorted(by: path, ascending: ascending) return self } @@ -137,7 +92,7 @@ public extension Array { /// - ascending: whether order is ascending or not. /// - Returns: self after sorting. @discardableResult - public mutating func sort(by path: KeyPath, ascending: Bool = true) -> [Element] { + mutating func sort(by path: KeyPath, ascending: Bool = true) -> [Element] { self = sorted(by: path, ascending: ascending) return self } @@ -155,7 +110,7 @@ public extension Array where Element: Equatable { /// - Parameter item: item to remove. /// - Returns: self after removing all instances of item. @discardableResult - public mutating func removeAll(_ item: Element) -> [Element] { + mutating func removeAll(_ item: Element) -> [Element] { removeAll(where: { $0 == item }) return self } @@ -168,7 +123,7 @@ public extension Array where Element: Equatable { /// - Parameter items: items to remove. /// - Returns: self after removing all instances of all items in given array. @discardableResult - public mutating func removeAll(_ items: [Element]) -> [Element] { + mutating func removeAll(_ items: [Element]) -> [Element] { guard !items.isEmpty else { return self } removeAll(where: { items.contains($0) }) return self @@ -179,13 +134,16 @@ public extension Array where Element: Equatable { /// [1, 2, 2, 3, 4, 5].removeDuplicates() -> [1, 2, 3, 4, 5] /// ["h", "e", "l", "l", "o"]. removeDuplicates() -> ["h", "e", "l", "o"] /// - public mutating func removeDuplicates() { + /// - Returns: Return array with all duplicate elements removed. + @discardableResult + mutating func removeDuplicates() -> [Element] { // Thanks to https://github.com/sairamkotha for improving the method self = reduce(into: [Element]()) { if !$0.contains($1) { $0.append($1) } } + return self } /// SwifterSwift: Return array with all duplicate elements removed. @@ -195,7 +153,7 @@ public extension Array where Element: Equatable { /// /// - Returns: an array of unique elements. /// - public func withoutDuplicates() -> [Element] { + func withoutDuplicates() -> [Element] { // Thanks to https://github.com/sairamkotha for improving the method return reduce(into: [Element]()) { if !$0.contains($1) { diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BidirectionalCollectionExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BidirectionalCollectionExtensions.swift new file mode 100644 index 0000000..23efb27 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BidirectionalCollectionExtensions.swift @@ -0,0 +1,26 @@ +// +// BidirectionalCollectionExtensions.swift +// SwifterSwift +// +// Created by Quentin Jin on 2018/10/13. +// Copyright © 2018 SwifterSwift +// + +// MARK: - Methods +public extension BidirectionalCollection { + + /// SwifterSwift: Returns the element at the specified position. If offset + /// is negative, the `n`th element from the end will be returned where `n` + /// is the result of `abs(distance)`. + /// + /// let arr = [1, 2, 3, 4, 5] + /// arr[offset: 1] -> 2 + /// arr[offset: -2] -> 4 + /// + /// - Parameter distance: The distance to offset. + subscript(offset distance: Int) -> Element { + let index = distance >= 0 ? startIndex : endIndex + return self[indices.index(index, offsetBy: distance)] + } + +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BinaryFloatingPointExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BinaryFloatingPointExtensions.swift new file mode 100644 index 0000000..628cb10 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BinaryFloatingPointExtensions.swift @@ -0,0 +1,39 @@ +// +// BinaryFloatingPointExtensions.swift +// SwifterSwift +// +// Created by Quentin Jin on 2018/10/13. +// Copyright © 2018 SwifterSwift +// + +#if canImport(Foundation) +import Foundation + +// MARK: - Methods +public extension BinaryFloatingPoint { + + #if canImport(Foundation) + /// SwifterSwift: Returns a rounded value with the specified number of + /// decimal places and rounding rule. If `numberOfDecimalPlaces` is negative, + /// `0` will be used. + /// + /// let num = 3.1415927 + /// num.rounded(numberOfDecimalPlaces: 3, rule: .up) -> 3.142 + /// num.rounded(numberOfDecimalPlaces: 3, rule: .down) -> 3.141 + /// num.rounded(numberOfDecimalPlaces: 2, rule: .awayFromZero) -> 3.15 + /// num.rounded(numberOfDecimalPlaces: 4, rule: .towardZero) -> 3.1415 + /// num.rounded(numberOfDecimalPlaces: -1, rule: .toNearestOrEven) -> 3 + /// + /// - Parameters: + /// - numberOfDecimalPlaces: The expected number of decimal places. + /// - rule: The rounding rule to use. + /// - Returns: The rounded value. + func rounded(numberOfDecimalPlaces: Int, rule: FloatingPointRoundingRule) -> Self { + let factor = Self(pow(10.0, Double(max(0, numberOfDecimalPlaces)))) + return (self * factor).rounded(rule) / factor + } + #endif + +} + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/BoolExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BoolExtensions.swift similarity index 78% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/BoolExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BoolExtensions.swift index a88b7c4..fe384f9 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/BoolExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/BoolExtensions.swift @@ -6,10 +6,6 @@ // Copyright © 2016 SwifterSwift // -#if canImport(Foundation) -import Foundation -#endif - // MARK: - Properties public extension Bool { @@ -18,7 +14,7 @@ public extension Bool { /// false.int -> 0 /// true.int -> 1 /// - public var int: Int { + var int: Int { return self ? 1 : 0 } @@ -27,8 +23,8 @@ public extension Bool { /// false.string -> "false" /// true.string -> "true" /// - public var string: String { - return description + var string: String { + return self ? "true" : "false" } } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/CharacterExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/CharacterExtensions.swift similarity index 78% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/CharacterExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/CharacterExtensions.swift index 231ec56..4aaf2e2 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/CharacterExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/CharacterExtensions.swift @@ -6,10 +6,6 @@ // Copyright © 2016 SwifterSwift // -#if canImport(Foundation) -import Foundation -#endif - // MARK: - Properties public extension Character { @@ -17,15 +13,23 @@ public extension Character { /// /// Character("😀").isEmoji -> true /// - public var isEmoji: Bool { + var isEmoji: Bool { // http://stackoverflow.com/questions/30757193/find-out-if-character-in-string-is-emoji let scalarValue = String(self).unicodeScalars.first!.value switch scalarValue { - case 0x3030, 0x00AE, 0x00A9, // Special Characters - 0x1D000...0x1F77F, // Emoticons - 0x2100...0x27BF, // Misc symbols and Dingbats + case 0x1F600...0x1F64F, // Emoticons + 0x1F300...0x1F5FF, // Misc Symbols and Pictographs + 0x1F680...0x1F6FF, // Transport and Map + 0x1F1E6...0x1F1FF, // Regional country flags + 0x2600...0x26FF, // Misc symbols + 0x2700...0x27BF, // Dingbats + 0xE0020...0xE007F, // Tags 0xFE00...0xFE0F, // Variation Selectors - 0x1F900...0x1F9FF: // Supplemental Symbols and Pictographs + 0x1F900...0x1F9FF, // Supplemental Symbols and Pictographs + 127000...127600, // Various asian characters + 65024...65039, // Variation selector + 9100...9300, // Misc items + 8400...8447: // Combining Diacritical Marks for Symbols return true default: return false @@ -37,7 +41,7 @@ public extension Character { /// Character("1").isNumber -> true /// Character("a").isNumber -> false /// - public var isNumber: Bool { + var isNumber: Bool { return Int(String(self)) != nil } @@ -46,7 +50,7 @@ public extension Character { /// Character("4").isLetter -> false /// Character("a").isLetter -> true /// - public var isLetter: Bool { + var isLetter: Bool { return String(self).rangeOfCharacter(from: .letters, options: .numeric, range: nil) != nil } @@ -55,7 +59,7 @@ public extension Character { /// Character("a").isLowercased -> true /// Character("A").isLowercased -> false /// - public var isLowercased: Bool { + var isLowercased: Bool { return String(self) == String(self).lowercased() } @@ -64,7 +68,7 @@ public extension Character { /// Character("a").isUppercased -> false /// Character("A").isUppercased -> true /// - public var isUppercased: Bool { + var isUppercased: Bool { return String(self) == String(self).uppercased() } @@ -73,7 +77,7 @@ public extension Character { /// Character(" ").isWhiteSpace -> true /// Character("A").isWhiteSpace -> false /// - public var isWhiteSpace: Bool { + var isWhiteSpace: Bool { return String(self) == " " } @@ -82,7 +86,7 @@ public extension Character { /// Character("1").int -> 1 /// Character("A").int -> nil /// - public var int: Int? { + var int: Int? { return Int(String(self)) } @@ -90,7 +94,7 @@ public extension Character { /// /// Character("a").string -> "a" /// - public var string: String { + var string: String { return String(self) } @@ -98,7 +102,7 @@ public extension Character { /// /// Character("A").lowercased -> Character("a") /// - public var lowercased: Character { + var lowercased: Character { return String(self).lowercased().first! } @@ -106,7 +110,7 @@ public extension Character { /// /// Character("a").uppercased -> Character("A") /// - public var uppercased: Character { + var uppercased: Character { return String(self).uppercased().first! } @@ -115,16 +119,14 @@ public extension Character { // MARK: - Methods public extension Character { - #if canImport(Foundation) /// SwifterSwift: Random character. /// /// Character.random() -> k /// /// - Returns: A random character. - public static func randomAlphanumeric() -> Character { + static func randomAlphanumeric() -> Character { return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".randomElement()! } - #endif } @@ -139,7 +141,7 @@ public extension Character { /// - lhs: character to repeat. /// - rhs: number of times to repeat character. /// - Returns: string with character repeated n times. - public static func * (lhs: Character, rhs: Int) -> String { + static func * (lhs: Character, rhs: Int) -> String { guard rhs > 0 else { return "" } return String(repeating: String(lhs), count: rhs) } @@ -152,7 +154,7 @@ public extension Character { /// - lhs: number of times to repeat character. /// - rhs: character to repeat. /// - Returns: string with character repeated n times. - public static func * (lhs: Int, rhs: Character) -> String { + static func * (lhs: Int, rhs: Character) -> String { guard lhs > 0 else { return "" } return String(repeating: String(rhs), count: lhs) } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/CollectionExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/CollectionExtensions.swift similarity index 58% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/CollectionExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/CollectionExtensions.swift index b3f1577..5599389 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/CollectionExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/CollectionExtensions.swift @@ -6,13 +6,14 @@ // Copyright © 2016 SwifterSwift // -#if canImport(Foundation) -import Foundation +#if canImport(Dispatch) +import Dispatch #endif // MARK: - Methods public extension Collection { + #if canImport(Dispatch) /// SwifterSwift: Performs `each` closure for each element of collection in parallel. /// /// array.forEachInParallel { item in @@ -20,14 +21,14 @@ public extension Collection { /// } /// /// - Parameter each: closure to run for each element. - public func forEachInParallel(_ each: (Self.Element) -> Void) { + func forEachInParallel(_ each: (Self.Element) -> Void) { let indicesArray = Array(indices) - DispatchQueue.concurrentPerform(iterations: indicesArray.count) { (index) in let elementIndex = indicesArray[index] each(self[elementIndex]) } } + #endif /// SwifterSwift: Safe protects the array from out of bounds by use of optional. /// @@ -36,7 +37,7 @@ public extension Collection { /// arr[safe: 10] -> nil /// /// - Parameter index: index of element to access element. - public subscript(safe index: Index) -> Element? { + subscript(safe index: Index) -> Element? { return indices.contains(index) ? self[index] : nil } @@ -45,39 +46,13 @@ public extension Collection { // MARK: - Methods (Int) public extension Collection where Index == Int { - /// SwifterSwift: Get the first index where condition is met. - /// - /// [1, 7, 1, 2, 4, 1, 6].firstIndex { $0 % 2 == 0 } -> 3 - /// - /// - Parameter condition: condition to evaluate each element against. - /// - Returns: first index where the specified condition evaluates to true. (optional) - public func firstIndex(where condition: (Element) throws -> Bool) rethrows -> Index? { - for (index, value) in lazy.enumerated() where try condition(value) { - return index - } - return nil - } - - /// SwifterSwift: Get the last index where condition is met. - /// - /// [1, 7, 1, 2, 4, 1, 8].lastIndex { $0 % 2 == 0 } -> 6 - /// - /// - Parameter condition: condition to evaluate each element against. - /// - Returns: last index where the specified condition evaluates to true. (optional) - public func lastIndex(where condition: (Element) throws -> Bool) rethrows -> Index? { - for (index, value) in lazy.enumerated().reversed() where try condition(value) { - return index - } - return nil - } - /// SwifterSwift: Get all indices where condition is met. /// /// [1, 7, 1, 2, 4, 1, 8].indices(where: { $0 == 1 }) -> [0, 2, 5] /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: all indices where the specified condition evaluates to true. (optional) - public func indices(where condition: (Element) throws -> Bool) rethrows -> [Index]? { + func indices(where condition: (Element) throws -> Bool) rethrows -> [Index]? { var indicies: [Index] = [] for (index, value) in lazy.enumerated() where try condition(value) { indicies.append(index) @@ -93,7 +68,7 @@ public extension Collection where Index == Int { /// - Parameters: /// - slice: size of array in each interation. /// - body: a closure that takes an array of slice size as a parameter. - public func forEach(slice: Int, body: ([Element]) throws -> Void) rethrows { + func forEach(slice: Int, body: ([Element]) throws -> Void) rethrows { guard slice > 0, !isEmpty else { return } var value: Int = 0 @@ -110,7 +85,7 @@ public extension Collection where Index == Int { /// /// - Parameter size: The size of the slices to be returned. /// - Returns: grouped self. - public func group(by size: Int) -> [[Element]]? { + func group(by size: Int) -> [[Element]]? { //Inspired by: https://lodash.com/docs/4.17.4#chunk guard size > 0, !isEmpty else { return nil } var value: Int = 0 @@ -124,47 +99,13 @@ public extension Collection where Index == Int { } -public extension Collection where Element: Equatable, Index == Int { - - /// SwifterSwift: First index of a given item in an array. - /// - /// [1, 2, 2, 3, 4, 2, 5].firstIndex(of: 2) -> 1 - /// [1.2, 2.3, 4.5, 3.4, 4.5].firstIndex(of: 6.5) -> nil - /// ["h", "e", "l", "l", "o"].firstIndex(of: "l") -> 2 - /// - /// - Parameter item: item to check. - /// - Returns: first index of item in array (if exists). - public func firstIndex(of item: Element) -> Index? { - for (index, value) in lazy.enumerated() where value == item { - return index - } - return nil - } - - /// SwifterSwift: Last index of element in array. - /// - /// [1, 2, 2, 3, 4, 2, 5].lastIndex(of: 2) -> 5 - /// [1.2, 2.3, 4.5, 3.4, 4.5].lastIndex(of: 6.5) -> nil - /// ["h", "e", "l", "l", "o"].lastIndex(of: "l") -> 3 - /// - /// - Parameter item: item to check. - /// - Returns: last index of item in array (if exists). - public func lastIndex(of item: Element) -> Index? { - for (index, value) in lazy.enumerated().reversed() where value == item { - return index - } - return nil - } - -} - // MARK: - Methods (Integer) public extension Collection where Element == IntegerLiteralType, Index == Int { /// SwifterSwift: Average of all elements in array. /// /// - Returns: the average of the array's elements. - public func average() -> Double { + func average() -> Double { // http://stackoverflow.com/questions/28288148/making-my-function-calculate-average-of-array-swift return isEmpty ? 0 : Double(reduce(0, +)) / Double(count) } @@ -179,7 +120,7 @@ public extension Collection where Element: FloatingPoint { /// [1.2, 2.3, 4.5, 3.4, 4.5].average() = 3.18 /// /// - Returns: average of the array's elements. - public func average() -> Element { + func average() -> Element { guard !isEmpty else { return 0 } return reduce(0, {$0 + $1}) / Element(count) } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/ComparableExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/ComparableExtensions.swift similarity index 90% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/ComparableExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/ComparableExtensions.swift index 022e513..581ba12 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/ComparableExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/ComparableExtensions.swift @@ -21,7 +21,7 @@ public extension Comparable { /// - parameter max: Maximum comparable value. /// /// - returns: `true` if value is between `min` and `max`, `false` otherwise. - public func isBetween(_ range: ClosedRange) -> Bool { + func isBetween(_ range: ClosedRange) -> Bool { return range ~= self } @@ -36,7 +36,7 @@ public extension Comparable { /// - parameter max: Upper bound to limit the value to. /// /// - returns: A value limited to the range between `min` and `max`. - public func clamped(to range: ClosedRange) -> Self { + func clamped(to range: ClosedRange) -> Self { return max(range.lowerBound, min(self, range.upperBound)) } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/DictionaryExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/DictionaryExtensions.swift similarity index 74% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/DictionaryExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/DictionaryExtensions.swift index 0c3e9ae..ef74256 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/DictionaryExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/DictionaryExtensions.swift @@ -21,7 +21,7 @@ public extension Dictionary { /// /// - Parameter key: key to search for /// - Returns: true if key exists in dictionary. - public func has(key: Key) -> Bool { + func has(key: Key) -> Bool { return index(forKey: key) != nil } @@ -34,25 +34,23 @@ public extension Dictionary { /// dict.keys.contains("key2") -> false /// /// - Parameter keys: keys to be removed - public mutating func removeAll(keys: S) where S.Element == Key { + mutating func removeAll(keys: S) where S.Element == Key { keys.forEach { removeValue(forKey: $0) } } - #if canImport(Foundation) /// SwifterSwift: Remove a value for a random key from the dictionary. - @discardableResult public mutating func removeValueForRandomKey() -> Value? { - guard !isEmpty else { return nil } - let key = Array(keys)[Int.random(in: 0.. Value? { + guard let randomKey = keys.randomElement() else { return nil } + return removeValue(forKey: randomKey) } - #endif #if canImport(Foundation) /// SwifterSwift: JSON Data from dictionary. /// /// - Parameter prettify: set true to prettify data (default is false). /// - Returns: optional JSON Data (if applicable). - public func jsonData(prettify: Bool = false) -> Data? { + func jsonData(prettify: Bool = false) -> Data? { guard JSONSerialization.isValidJSONObject(self) else { return nil } @@ -85,7 +83,7 @@ public extension Dictionary { /// /// - Parameter prettify: set true to prettify string (default is false). /// - Returns: optional JSON String (if applicable). - public func jsonString(prettify: Bool = false) -> String? { + func jsonString(prettify: Bool = false) -> String? { guard JSONSerialization.isValidJSONObject(self) else { return nil } let options = (prettify == true) ? JSONSerialization.WritingOptions.prettyPrinted : JSONSerialization.WritingOptions() guard let jsonData = try? JSONSerialization.data(withJSONObject: self, options: options) else { return nil } @@ -96,7 +94,7 @@ public extension Dictionary { /// SwifterSwift: Returns a dictionary containing the results of mapping the given closure over the sequence’s elements. /// - Parameter transform: A mapping closure. `transform` accepts an element of this sequence as its parameter and returns a transformed value of the same or of a different type. /// - Returns: A dictionary containing the transformed elements of this sequence. - public func mapKeysAndValues(_ transform: ((key: Key, value: Value)) throws -> (K, V)) rethrows -> [K: V] { + func mapKeysAndValues(_ transform: ((key: Key, value: Value)) throws -> (K, V)) rethrows -> [K: V] { return [K: V](uniqueKeysWithValues: try map(transform)) } @@ -104,7 +102,7 @@ public extension Dictionary { /// - Parameter transform: A closure that accepts an element of this sequence as its argument and returns an optional value. /// - Returns: A dictionary of the non-`nil` results of calling `transform` with each element of the sequence. /// - Complexity: *O(m + n)*, where _m_ is the length of this sequence and _n_ is the length of the result. - public func compactMapKeysAndValues(_ transform: ((key: Key, value: Value)) throws -> (K, V)?) rethrows -> [K: V] { + func compactMapKeysAndValues(_ transform: ((key: Key, value: Value)) throws -> (K, V)?) rethrows -> [K: V] { return [K: V](uniqueKeysWithValues: try compactMap(transform)) } @@ -122,7 +120,7 @@ public extension Dictionary where Value: Equatable { /// /// - Parameter value: Value for which keys are to be fetched. /// - Returns: An array containing keys that have the given value. - public func keys(forValue value: Value) -> [Key] { + func keys(forValue value: Value) -> [Key] { return keys.filter { self[$0] == value } } @@ -137,7 +135,7 @@ public extension Dictionary where Key: StringProtocol { /// dict.lowercaseAllKeys() /// print(dict) // prints "["testkey": "value"]" /// - public mutating func lowercaseAllKeys() { + mutating func lowercaseAllKeys() { // http://stackoverflow.com/questions/33180028/extend-dictionary-where-key-is-of-type-string for key in keys { if let lowercaseKey = String(describing: key).lowercased() as? Key { @@ -145,7 +143,49 @@ public extension Dictionary where Key: StringProtocol { } } } +} + +// MARK: - Subscripts +public extension Dictionary { + /// SwifterSwift: Deep fetch or set a value from nested dictionaries. + /// + /// var dict = ["key": ["key1": ["key2": "value"]]] + /// dict[path: ["key", "key1", "key2"]] = "newValue" + /// dict[path: ["key", "key1", "key2"]] -> "newValue" + /// + /// - Note: Value fetching is iterative, while setting is recursive. + /// + /// - Complexity: O(N), _N_ being the length of the path passed in. + /// + /// - Parameter path: An array of keys to the desired value. + /// + /// - Returns: The value for the key-path passed in. `nil` if no value is found. + subscript(path path: [Key]) -> Any? { + get { + guard !path.isEmpty else { return nil } + var result: Any? = self + for key in path { + if let element = (result as? [Key: Any])?[key] { + result = element + } else { + return nil + } + } + return result + } + set { + if let first = path.first { + if path.count == 1, let new = newValue as? Value { + return self[first] = new + } + if var nested = self[first] as? [Key: Any] { + nested[path: Array(path.dropFirst())] = newValue + return self[first] = nested as? Value + } + } + } + } } // MARK: - Operators @@ -163,7 +203,7 @@ public extension Dictionary { /// - lhs: dictionary /// - rhs: dictionary /// - Returns: An dictionary with keys and values from both. - public static func + (lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value] { + static func + (lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value] { var result = lhs rhs.forEach { result[$0] = $1 } return result @@ -182,7 +222,7 @@ public extension Dictionary { /// - Parameters: /// - lhs: dictionary /// - rhs: dictionary - public static func += (lhs: inout [Key: Value], rhs: [Key: Value]) { + static func += (lhs: inout [Key: Value], rhs: [Key: Value]) { rhs.forEach { lhs[$0] = $1} } @@ -198,7 +238,7 @@ public extension Dictionary { /// - lhs: dictionary /// - rhs: array with the keys to be removed. /// - Returns: a new dictionary with keys removed. - public static func - (lhs: [Key: Value], keys: S) -> [Key: Value] where S.Element == Key { + static func - (lhs: [Key: Value], keys: S) -> [Key: Value] where S.Element == Key { var result = lhs result.removeAll(keys: keys) return result @@ -215,7 +255,7 @@ public extension Dictionary { /// - Parameters: /// - lhs: dictionary /// - rhs: array with the keys to be removed. - public static func -= (lhs: inout [Key: Value], keys: S) where S.Element == Key { + static func -= (lhs: inout [Key: Value], keys: S) where S.Element == Key { lhs.removeAll(keys: keys) } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/DoubleExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/DoubleExtensions.swift similarity index 81% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/DoubleExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/DoubleExtensions.swift index 439b370..f3b147d 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/DoubleExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/DoubleExtensions.swift @@ -14,18 +14,18 @@ import CoreGraphics public extension Double { /// SwifterSwift: Int. - public var int: Int { + var int: Int { return Int(self) } /// SwifterSwift: Float. - public var float: Float { + var float: Float { return Float(self) } #if canImport(CoreGraphics) /// SwifterSwift: CGFloat. - public var cgFloat: CGFloat { + var cgFloat: CGFloat { return CGFloat(self) } #endif @@ -34,6 +34,8 @@ public extension Double { // MARK: - Operators +#if canImport(Foundation) && !os(Linux) + precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence } infix operator ** : PowerPrecedence /// SwifterSwift: Value of exponentiation. @@ -42,18 +44,24 @@ infix operator ** : PowerPrecedence /// - lhs: base double. /// - rhs: exponent double. /// - Returns: exponentiation result (example: 4.4 ** 0.5 = 2.0976176963). -public func ** (lhs: Double, rhs: Double) -> Double { +func ** (lhs: Double, rhs: Double) -> Double { // http://nshipster.com/swift-operators/ return pow(lhs, rhs) } -// swiftlint:disable next identifier_name +#endif + +#if canImport(Foundation) && !os(Linux) + prefix operator √ /// SwifterSwift: Square root of double. /// /// - Parameter double: double value to find square root for. /// - Returns: square root of given double. +// swiftlint:disable:next identifier_name public prefix func √ (double: Double) -> Double { // http://nshipster.com/swift-operators/ return sqrt(double) } + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/FloatExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/FloatExtensions.swift similarity index 81% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/FloatExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/FloatExtensions.swift index b91d2de..7acfd0c 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/FloatExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/FloatExtensions.swift @@ -14,18 +14,18 @@ import CoreGraphics public extension Float { /// SwifterSwift: Int. - public var int: Int { + var int: Int { return Int(self) } /// SwifterSwift: Double. - public var double: Double { + var double: Double { return Double(self) } #if canImport(CoreGraphics) /// SwifterSwift: CGFloat. - public var cgFloat: CGFloat { + var cgFloat: CGFloat { return CGFloat(self) } #endif @@ -34,6 +34,8 @@ public extension Float { // MARK: - Operators +#if canImport(Foundation) && !os(Linux) + precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence } infix operator ** : PowerPrecedence /// SwifterSwift: Value of exponentiation. @@ -42,18 +44,24 @@ infix operator ** : PowerPrecedence /// - lhs: base float. /// - rhs: exponent float. /// - Returns: exponentiation result (4.4 ** 0.5 = 2.0976176963). -public func ** (lhs: Float, rhs: Float) -> Float { +func ** (lhs: Float, rhs: Float) -> Float { // http://nshipster.com/swift-operators/ return pow(lhs, rhs) } -// swiftlint:disable next identifier_name +#endif + +#if canImport(Foundation) && !os(Linux) + prefix operator √ /// SwifterSwift: Square root of float. /// /// - Parameter float: float value to find square root for /// - Returns: square root of given float. +// swiftlint:disable:next identifier_name public prefix func √ (float: Float) -> Float { // http://nshipster.com/swift-operators/ return sqrt(float) } + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/FloatingPointExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/FloatingPointExtensions.swift similarity index 77% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/FloatingPointExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/FloatingPointExtensions.swift index 12ff21c..286cbbe 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/FloatingPointExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/FloatingPointExtensions.swift @@ -14,41 +14,41 @@ import Foundation public extension FloatingPoint { /// SwifterSwift: Absolute value of number. - public var abs: Self { + var abs: Self { return Swift.abs(self) } /// SwifterSwift: Check if number is positive. - public var isPositive: Bool { + var isPositive: Bool { return self > 0 } /// SwifterSwift: Check if number is negative. - public var isNegative: Bool { + var isNegative: Bool { return self < 0 } #if canImport(Foundation) /// SwifterSwift: Ceil of number. - public var ceil: Self { + var ceil: Self { return Foundation.ceil(self) } #endif /// SwifterSwift: Radian value of degree input. - public var degreesToRadians: Self { + var degreesToRadians: Self { return Self.pi * self / Self(180) } #if canImport(Foundation) /// SwifterSwift: Floor of number. - public var floor: Self { + var floor: Self { return Foundation.floor(self) } #endif /// SwifterSwift: Degree value of radian input. - public var radiansToDegrees: Self { + var radiansToDegrees: Self { return self * Self(180) / Self.pi } @@ -56,7 +56,6 @@ public extension FloatingPoint { // MARK: - Operators -// swiftlint:disable next identifier_name infix operator ± /// SwifterSwift: Tuple of plus-minus operation. /// @@ -64,18 +63,19 @@ infix operator ± /// - lhs: number /// - rhs: number /// - Returns: tuple of plus-minus operation ( 2.5 ± 1.5 -> (4, 1)). -public func ± (lhs: T, rhs: T) -> (T, T) { +// swiftlint:disable:next identifier_name +func ± (lhs: T, rhs: T) -> (T, T) { // http://nshipster.com/swift-operators/ return (lhs + rhs, lhs - rhs) } -// swiftlint:disable next identifier_name prefix operator ± /// SwifterSwift: Tuple of plus-minus operation. /// /// - Parameter int: number /// - Returns: tuple of plus-minus operation (± 2.5 -> (2.5, -2.5)). -public prefix func ± (number: T) -> (T, T) { +// swiftlint:disable:next identifier_name +public prefix func ± (number: T) -> (T, T) { // http://nshipster.com/swift-operators/ return 0 ± number } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/IntExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/IntExtensions.swift similarity index 79% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/IntExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/IntExtensions.swift index 9569c09..dd847b3 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/IntExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/IntExtensions.swift @@ -14,44 +14,44 @@ import CoreGraphics public extension Int { /// SwifterSwift: CountableRange 0.. { + var countableRange: CountableRange { return 0..= 0 ? "" : "-" } @@ -67,10 +67,10 @@ public extension Int { } /// SwifterSwift: Array of digits of integer value. - public var digits: [Int] { + var digits: [Int] { guard self != 0 else { return [0] } var digits = [Int]() - var number = self.abs + var number = abs while number != 0 { let xNumber = number % 10 @@ -82,30 +82,30 @@ public extension Int { return digits } + #if canImport(Foundation) && !os(Linux) /// SwifterSwift: Number of digits of integer value. - public var digitsCount: Int { + var digitsCount: Int { guard self != 0 else { return 1 } - let number = Double(self.abs) + let number = Double(abs) return Int(log10(number) + 1) } + #endif } // MARK: - Methods public extension Int { + #if canImport(Foundation) && !os(Linux) /// SwifterSwift: check if given integer prime or not. /// Warning: Using big numbers can be computationally expensive! /// - Returns: true or false depending on prime-ness - public func isPrime() -> Bool { + func isPrime() -> Bool { // To improve speed on latter loop :) - if self == 2 { - return true - } + if self == 2 { return true } + + guard self > 1 && self % 2 != 0 else { return false } - guard self > 1 && self % 2 != 0 else { - return false - } // Explanation: It is enough to check numbers until // the square root of that number. If you go up from N by one, // other multiplier will go 1 down to get similar result @@ -116,15 +116,16 @@ public extension Int { } return true } + #endif /// SwifterSwift: Roman numeral string from integer (if applicable). /// ///10.romanNumeral() -> "X" /// /// - Returns: The roman numeral string. - public func romanNumeral() -> String? { + func romanNumeral() -> String? { // https://gist.github.com/kumo/a8e1cb1f4b7cff1548c7 - guard self > 0 else { // there is no roman numerals for 0 or negative numbers + guard self > 0 else { // there is no roman numeral for 0 or negative numbers return nil } let romanValues = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] @@ -146,16 +147,19 @@ public extension Int { return romanValue } - // swiftlint:disable next identifier_name + #if canImport(Foundation) && !os(Linux) /// SwifterSwift: Rounds to the closest multiple of n - public func roundToNearest(_ n: Int) -> Int { - return n == 0 ? self : Int(round(Double(self) / Double(n))) * n + func roundToNearest(_ number: Int) -> Int { + return number == 0 ? self : Int(round(Double(self) / Double(number))) * number } + #endif } // MARK: - Operators +#if canImport(Foundation) && !os(Linux) + precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence } infix operator ** : PowerPrecedence /// SwifterSwift: Value of exponentiation. @@ -164,23 +168,28 @@ infix operator ** : PowerPrecedence /// - lhs: base integer. /// - rhs: exponent integer. /// - Returns: exponentiation result (example: 2 ** 3 = 8). -public func ** (lhs: Int, rhs: Int) -> Double { +func ** (lhs: Int, rhs: Int) -> Double { // http://nshipster.com/swift-operators/ return pow(Double(lhs), Double(rhs)) } -// swiftlint:disable next identifier_name +#endif + +#if canImport(Foundation) && !os(Linux) + prefix operator √ /// SwifterSwift: Square root of integer. /// /// - Parameter int: integer value to find square root for /// - Returns: square root of given integer. +// swiftlint:disable:next identifier_name public prefix func √ (int: Int) -> Double { // http://nshipster.com/swift-operators/ return sqrt(Double(int)) } -// swiftlint:disable next identifier_name +#endif + infix operator ± /// SwifterSwift: Tuple of plus-minus operation. /// @@ -188,17 +197,18 @@ infix operator ± /// - lhs: integer number. /// - rhs: integer number. /// - Returns: tuple of plus-minus operation (example: 2 ± 3 -> (5, -1)). -public func ± (lhs: Int, rhs: Int) -> (Int, Int) { +// swiftlint:disable:next identifier_name +func ± (lhs: Int, rhs: Int) -> (Int, Int) { // http://nshipster.com/swift-operators/ return (lhs + rhs, lhs - rhs) } -// swiftlint:disable next identifier_name prefix operator ± /// SwifterSwift: Tuple of plus-minus operation. /// /// - Parameter int: integer number /// - Returns: tuple of plus-minus operation (example: ± 2 -> (2, -2)). +// swiftlint:disable:next identifier_name public prefix func ± (int: Int) -> (Int, Int) { // http://nshipster.com/swift-operators/ return 0 ± int diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/OptionalExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/OptionalExtensions.swift similarity index 84% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/OptionalExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/OptionalExtensions.swift index 60f6204..eeb479a 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/OptionalExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/OptionalExtensions.swift @@ -19,7 +19,7 @@ public extension Optional { /// /// - Parameter defaultValue: default value to return if self is nil. /// - Returns: self if not nil or default value if nil. - public func unwrapped(or defaultValue: Wrapped) -> Wrapped { + func unwrapped(or defaultValue: Wrapped) -> Wrapped { // http://www.russbishop.net/improving-optionals return self ?? defaultValue } @@ -35,7 +35,7 @@ public extension Optional { /// - Parameter error: The error to throw if the optional is `nil`. /// - Returns: The value wrapped by the optional. /// - Throws: The error passed in. - public func unwrapped(or error: Error) throws -> Wrapped { + func unwrapped(or error: Error) throws -> Wrapped { guard let wrapped = self else { throw error } return wrapped } @@ -55,9 +55,9 @@ public extension Optional { /// } /// /// - Parameter block: a block to run if self is not nil. - public func run(_ block: (Wrapped) -> Void) { + func run(_ block: (Wrapped) -> Void) { // http://www.russbishop.net/improving-optionals - _ = self.map(block) + _ = map(block) } /// SwifterSwift: Assign an optional value to a variable only if the value is not nil. @@ -69,7 +69,7 @@ public extension Optional { /// - Parameters: /// - lhs: Any? /// - rhs: Any? - public static func ??= (lhs: inout Optional, rhs: Optional) { + static func ??= (lhs: inout Optional, rhs: Optional) { guard let rhs = rhs else { return } lhs = rhs } @@ -85,7 +85,7 @@ public extension Optional { /// - Parameters: /// - lhs: Any? /// - rhs: Any? - public static func ?= (lhs: inout Optional, rhs: @autoclosure () -> Optional) { + static func ?= (lhs: inout Optional, rhs: @autoclosure () -> Optional) { if lhs == nil { lhs = rhs() } @@ -97,11 +97,18 @@ public extension Optional { public extension Optional where Wrapped: Collection { /// SwifterSwift: Check if optional is nil or empty collection. - public var isNilOrEmpty: Bool { + var isNilOrEmpty: Bool { guard let collection = self else { return true } return collection.isEmpty } + /// SwifterSwift: Returns the collection only if it is not nill and not empty. + var nonEmpty: Wrapped? { + guard let collection = self else { return nil } + guard !collection.isEmpty else { return nil } + return collection + } + } // MARK: - Operators diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/RandomAccessCollectionExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/RandomAccessCollectionExtensions.swift similarity index 93% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/RandomAccessCollectionExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/RandomAccessCollectionExtensions.swift index 00c8724..6472fd3 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/RandomAccessCollectionExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/RandomAccessCollectionExtensions.swift @@ -16,7 +16,7 @@ extension RandomAccessCollection where Element: Equatable { /// /// - Parameter item: item to check. /// - Returns: an array with all indices of the given item. - public func indices(of item: Element) -> [Index] { + func indices(of item: Element) -> [Index] { var indices: [Index] = [] var idx = startIndex while idx < endIndex { diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/RangeReplaceableCollectionExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/RangeReplaceableCollectionExtensions.swift similarity index 59% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/RangeReplaceableCollectionExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/RangeReplaceableCollectionExtensions.swift index 526147e..4a359c0 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/RangeReplaceableCollectionExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/RangeReplaceableCollectionExtensions.swift @@ -6,12 +6,8 @@ // Copyright © 2018 SwifterSwift // -#if canImport(Foundation) -import Foundation -#endif - // MARK: - Initializers -extension RangeReplaceableCollection { +public extension RangeReplaceableCollection { /// Creates a new collection of a given size where for each position of the collection the value will be the result /// of a call of the given expression. @@ -23,9 +19,10 @@ extension RangeReplaceableCollection { /// - Parameters: /// - expression: The expression to execute for each position of the collection. /// - count: The count of the collection. - public init(expression: @autoclosure () throws -> Element, count: Int) rethrows { + init(expression: @autoclosure () throws -> Element, count: Int) rethrows { self.init() - if count > 0 { //swiftlint:disable:this empty_count + //swiftlint:disable:next empty_count + if count > 0 { reserveCapacity(count) while self.count < count { append(try expression()) @@ -36,7 +33,7 @@ extension RangeReplaceableCollection { } // MARK: - Methods -extension RangeReplaceableCollection { +public extension RangeReplaceableCollection { /// SwifterSwift: Returns a new rotated collection by the given places. /// @@ -46,7 +43,7 @@ extension RangeReplaceableCollection { /// /// - Parameter places: Number of places that the array be rotated. If the value is positive the end becomes the start, if it negative it's that start becom the end. /// - Returns: The new rotated collection. - public func rotated(by places: Int) -> Self { + func rotated(by places: Int) -> Self { //Inspired by: https://ruby-doc.org/core-2.2.0/Array.html#method-i-rotate var copy = self return copy.rotate(by: places) @@ -61,7 +58,7 @@ extension RangeReplaceableCollection { /// - Parameter places: The number of places that the array should be rotated. If the value is positive the end becomes the start, if it negative it's that start become the end. /// - Returns: self after rotating. @discardableResult - public mutating func rotate(by places: Int) -> Self { + mutating func rotate(by places: Int) -> Self { guard places != 0 else { return self } let placesToMove = places%count if placesToMove > 0 { @@ -86,17 +83,52 @@ extension RangeReplaceableCollection { /// - Parameter predicate: A closure that takes an element as its argument and returns a Boolean value that indicates whether the passed element represents a match. /// - Returns: The first element for which predicate returns true, after removing it. If no elements in the collection satisfy the given predicate, returns `nil`. @discardableResult - public mutating func removeFirst(where predicate: (Element) throws -> Bool) rethrows -> Element? { - guard let index = try index(where: predicate) else { return nil } + mutating func removeFirst(where predicate: (Element) throws -> Bool) rethrows -> Element? { + guard let index = try firstIndex(where: predicate) else { return nil } return remove(at: index) } - #if canImport(Foundation) /// SwifterSwift: Remove a random value from the collection. - @discardableResult public mutating func removeRandomElement() -> Element? { - guard !isEmpty else { return nil } - return remove(at: index(startIndex, offsetBy: Int.random(in: 0.. Element? { + guard let randomIndex = indices.randomElement() else { return nil } + return remove(at: randomIndex) + } + + /// SwifterSwift: Keep elements of Array while condition is true. + /// + /// [0, 2, 4, 7].keep(while: { $0 % 2 == 0 }) -> [0, 2, 4] + /// + /// - Parameter condition: condition to evaluate each element against. + /// - Returns: self after applying provided condition. + /// - Throws: provided condition exception. + @discardableResult + mutating func keep(while condition: (Element) throws -> Bool) rethrows -> Self { + if let idx = try firstIndex(where: { try !condition($0) }) { + removeSubrange(idx...) + } + return self + } + + /// SwifterSwift: Take element of Array while condition is true. + /// + /// [0, 2, 4, 7, 6, 8].take( where: {$0 % 2 == 0}) -> [0, 2, 4] + /// + /// - Parameter condition: condition to evaluate each element against. + /// - Returns: All elements up until condition evaluates to false. + func take(while condition: (Element) throws -> Bool) rethrows -> Self { + return Self(try prefix(while: condition)) + } + + /// SwifterSwift: Skip elements of Array while condition is true. + /// + /// [0, 2, 4, 7, 6, 8].skip( where: {$0 % 2 == 0}) -> [6, 8] + /// + /// - Parameter condition: condition to evaluate each element against. + /// - Returns: All elements after the condition evaluates to false. + func skip(while condition: (Element) throws-> Bool) rethrows -> Self { + guard let idx = try firstIndex(where: { try !condition($0) }) else { return Self() } + return Self(self[idx...]) } - #endif } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SequenceExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SequenceExtensions.swift similarity index 80% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SequenceExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SequenceExtensions.swift index 154b005..e058fee 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SequenceExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SequenceExtensions.swift @@ -6,10 +6,6 @@ // Copyright © 2018 SwifterSwift // -#if canImport(Foundation) -import Foundation -#endif - public extension Sequence { /// SwifterSwift: Check if all elements in collection match a conditon. @@ -19,7 +15,7 @@ public extension Sequence { /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: true when all elements in the array match the specified condition. - public func all(matching condition: (Element) throws -> Bool) rethrows -> Bool { + func all(matching condition: (Element) throws -> Bool) rethrows -> Bool { return try !contains { try !condition($0) } } @@ -30,7 +26,7 @@ public extension Sequence { /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: true when no elements in the array match the specified condition. - public func none(matching condition: (Element) throws -> Bool) rethrows -> Bool { + func none(matching condition: (Element) throws -> Bool) rethrows -> Bool { return try !contains { try condition($0) } } @@ -41,7 +37,7 @@ public extension Sequence { /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: true when no elements in the array match the specified condition. - public func any(matching condition: (Element) throws -> Bool) rethrows -> Bool { + func any(matching condition: (Element) throws -> Bool) rethrows -> Bool { return try contains { try condition($0) } } @@ -51,7 +47,7 @@ public extension Sequence { /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: the last element in the array matching the specified condition. (optional) - public func last(where condition: (Element) throws -> Bool) rethrows -> Element? { + func last(where condition: (Element) throws -> Bool) rethrows -> Element? { for element in reversed() { if try condition(element) { return element } } @@ -64,7 +60,7 @@ public extension Sequence { /// /// - Parameter condition: to evaluate the exclusion of an element from the array. /// - Returns: the array with rejected values filtered from it. - public func reject(where condition: (Element) throws -> Bool) rethrows -> [Element] { + func reject(where condition: (Element) throws -> Bool) rethrows -> [Element] { return try filter { return try !condition($0) } } @@ -74,7 +70,7 @@ public extension Sequence { /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: number of times the condition evaluated to true. - public func count(where condition: (Element) throws -> Bool) rethrows -> Int { + func count(where condition: (Element) throws -> Bool) rethrows -> Int { var count = 0 for element in self where try condition(element) { count += 1 @@ -87,7 +83,7 @@ public extension Sequence { /// [0, 2, 4, 7].forEachReversed({ print($0)}) -> //Order of print: 7,4,2,0 /// /// - Parameter body: a closure that takes an element of the array as a parameter. - public func forEachReversed(_ body: (Element) throws -> Void) rethrows { + func forEachReversed(_ body: (Element) throws -> Void) rethrows { try reversed().forEach(body) } @@ -98,7 +94,7 @@ public extension Sequence { /// - Parameters: /// - condition: condition to evaluate each element against. /// - body: a closure that takes an element of the array as a parameter. - public func forEach(where condition: (Element) throws -> Bool, body: (Element) throws -> Void) rethrows { + func forEach(where condition: (Element) throws -> Bool, body: (Element) throws -> Void) rethrows { for element in self where try condition(element) { try body(element) } @@ -112,7 +108,7 @@ public extension Sequence { /// - initial: initial value. /// - next: closure that combines the accumulating value and next element of the array. /// - Returns: an array of the final accumulated value and each interim combination. - public func accumulate(initial: U, next: (U, Element) throws -> U) rethrows -> [U] { + func accumulate(initial: U, next: (U, Element) throws -> U) rethrows -> [U] { var runningTotal = initial return try map { element in runningTotal = try next(runningTotal, element) @@ -128,7 +124,7 @@ public extension Sequence { /// - isIncluded: condition of inclusion to evaluate each element against. /// - transform: transform element function to evaluate every element. /// - Returns: Return an filtered and mapped array. - public func filtered(_ isIncluded: (Element) throws -> Bool, map transform: (Element) throws -> T) rethrows -> [T] { + func filtered(_ isIncluded: (Element) throws -> Bool, map transform: (Element) throws -> T) rethrows -> [T] { return try compactMap({ if try isIncluded($0) { return try transform($0) @@ -146,7 +142,7 @@ public extension Sequence { /// /// - Parameter condition: condition to evaluate each element against. /// - Returns: The only element in the array matching the specified condition. If there are more matching elements, nil is returned. (optional) - public func single(where condition: ((Element) throws -> Bool)) rethrows -> Element? { + func single(where condition: ((Element) throws -> Bool)) rethrows -> Element? { var singleElement: Element? for element in self where try condition(element) { guard singleElement == nil else { @@ -170,7 +166,7 @@ public extension Sequence where Element: Equatable { /// /// - Parameter elements: array of elements to check. /// - Returns: true if array contains all given items. - public func contains(_ elements: [Element]) -> Bool { + func contains(_ elements: [Element]) -> Bool { guard !elements.isEmpty else { return true } for element in elements { if !contains(element) { @@ -187,7 +183,7 @@ public extension Sequence where Element: Hashable { /// SwifterSwift: Check whether a sequence contains duplicates. /// /// - Returns: true if the receiver contains duplicates. - public func containsDuplicates() -> Bool { + func containsDuplicates() -> Bool { var set = Set() for element in self { if !set.insert(element).inserted { @@ -197,6 +193,23 @@ public extension Sequence where Element: Hashable { return false } + /// SwifterSwift: Getting the duplicated elements in a sequence. + /// + /// [1, 1, 2, 2, 3, 3, 3, 4, 5].duplicates().sorted() -> [1, 2, 3]) + /// ["h", "e", "l", "l", "o"].duplicates().sorted() -> ["l"]) + /// + /// - Returns: An array of duplicated elements. + /// + func duplicates() -> [Element] { + var set = Set() + var duplicates = Set() + forEach { + if !set.insert($0).inserted { + duplicates.insert($0) + } + } + return Array(duplicates) + } } // MARK: - Methods (Numeric) @@ -207,7 +220,7 @@ public extension Sequence where Element: Numeric { /// [1, 2, 3, 4, 5].sum() -> 15 /// /// - Returns: sum of the array's elements. - public func sum() -> Element { + func sum() -> Element { return reduce(0, {$0 + $1}) } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SignedIntegerExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SignedIntegerExtensions.swift similarity index 76% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SignedIntegerExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SignedIntegerExtensions.swift index d764fc0..9aa5c69 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SignedIntegerExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SignedIntegerExtensions.swift @@ -13,32 +13,32 @@ import Foundation public extension SignedInteger { /// SwifterSwift: Absolute value of integer number. - public var abs: Self { + var abs: Self { return Swift.abs(self) } /// SwifterSwift: Check if integer is positive. - public var isPositive: Bool { + var isPositive: Bool { return self > 0 } /// SwifterSwift: Check if integer is negative. - public var isNegative: Bool { + var isNegative: Bool { return self < 0 } /// SwifterSwift: Check if integer is even. - public var isEven: Bool { + var isEven: Bool { return (self % 2) == 0 } /// SwifterSwift: Check if integer is odd. - public var isOdd: Bool { + var isOdd: Bool { return (self % 2) != 0 } /// SwifterSwift: String of format (XXh XXm) from seconds Int. - public var timeString: String { + var timeString: String { guard self > 0 else { return "0 sec" } @@ -62,22 +62,20 @@ public extension SignedInteger { // MARK: - Methods public extension SignedInteger { - // swiftlint:disable next identifier_name /// SwifterSwift: Greatest common divisor of integer value and n. /// - /// - Parameter n: integer value to find gcd with. + /// - Parameter number: integer value to find gcd with. /// - Returns: greatest common divisor of self and n. - public func gcd(of n: Self) -> Self { - return n == 0 ? self : n.gcd(of: self % n) + func gcd(of number: Self) -> Self { + return number == 0 ? self : number.gcd(of: self % number) } - // swiftlint:disable next identifier_name /// SwifterSwift: Least common multiple of integer and n. /// - /// - Parameter n: integer value to find lcm with. + /// - Parameter number: integer value to find lcm with. /// - Returns: least common multiple of self and n. - public func lcm(of n: Self) -> Self { - return (self * n).abs / gcd(of: n) + func lcm(of number: Self) -> Self { + return (self * number).abs / gcd(of: number) } #if canImport(Foundation) @@ -88,7 +86,7 @@ public extension SignedInteger { /// - Parameter locale: locale, default is .current. /// - Returns: string ordinal representation of number in specified locale language. E.g. input 92, output in "en": "92nd". @available(iOS 9.0, macOS 10.11, *) - public func ordinalString(locale: Locale = .current) -> String? { + func ordinalString(locale: Locale = .current) -> String? { let formatter = NumberFormatter() formatter.locale = locale formatter.numberStyle = .ordinal diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SignedNumericExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SignedNumericExtensions.swift similarity index 87% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SignedNumericExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SignedNumericExtensions.swift index 3b9c9d7..36cbf9b 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/SignedNumericExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/SignedNumericExtensions.swift @@ -14,17 +14,17 @@ import Foundation public extension SignedNumeric { /// SwifterSwift: String. - public var string: String { + var string: String { return String(describing: self) } #if canImport(Foundation) /// SwifterSwift: String with number and current locale currency. - public var asLocaleCurrency: String? { + var asLocaleCurrency: String? { let formatter = NumberFormatter() formatter.numberStyle = .currency formatter.locale = Locale.current - // swiftlint:disable next force_cast + // swiftlint:disable:next force_cast return formatter.string(from: self as! NSNumber) } #endif @@ -41,7 +41,7 @@ public extension SignedNumeric { /// /// - Parameter locale: Locale, default is .current. /// - Returns: String representation of number spelled in specified locale language. E.g. input 92, output in "en": "ninety-two" - public func spelledOutString(locale: Locale = .current) -> String? { + func spelledOutString(locale: Locale = .current) -> String? { let formatter = NumberFormatter() formatter.locale = locale formatter.numberStyle = .spellOut diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/StringExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/StringExtensions.swift similarity index 84% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/StringExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/StringExtensions.swift index 88e38ff..66016c8 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/SwiftStdlib/StringExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/StringExtensions.swift @@ -30,7 +30,7 @@ public extension String { /// /// "SGVsbG8gV29ybGQh".base64Decoded = Optional("Hello World!") /// - public var base64Decoded: String? { + var base64Decoded: String? { // https://github.com/Reza-Rg/Base64-Swift-Extension/blob/master/Base64.swift guard let decodedData = Data(base64Encoded: self) else { return nil } return String(data: decodedData, encoding: .utf8) @@ -42,7 +42,7 @@ public extension String { /// /// "Hello World!".base64Encoded -> Optional("SGVsbG8gV29ybGQh") /// - public var base64Encoded: String? { + var base64Encoded: String? { // https://github.com/Reza-Rg/Base64-Swift-Extension/blob/master/Base64.swift let plainData = data(using: .utf8) return plainData?.base64EncodedString() @@ -50,7 +50,7 @@ public extension String { #endif /// SwifterSwift: Array of characters of a string. - public var charactersArray: [Character] { + var charactersArray: [Character] { return Array(self) } @@ -59,7 +59,7 @@ public extension String { /// /// "sOme vAriable naMe".camelCased -> "someVariableName" /// - public var camelCased: String { + var camelCased: String { let source = lowercased() let first = source[.. true /// - public var containEmoji: Bool { + var containEmoji: Bool { // http://stackoverflow.com/questions/30757193/find-out-if-character-in-string-is-emoji for scalar in unicodeScalars { switch scalar.value { - case 0x3030, 0x00AE, 0x00A9, // Special Characters - 0x1D000...0x1F77F, // Emoticons - 0x2100...0x27BF, // Misc symbols and Dingbats + case 0x1F600...0x1F64F, // Emoticons + 0x1F300...0x1F5FF, // Misc Symbols and Pictographs + 0x1F680...0x1F6FF, // Transport and Map + 0x1F1E6...0x1F1FF, // Regional country flags + 0x2600...0x26FF, // Misc symbols + 0x2700...0x27BF, // Dingbats + 0xE0020...0xE007F, // Tags 0xFE00...0xFE0F, // Variation Selectors - 0x1F900...0x1F9FF: // Supplemental Symbols and Pictographs + 0x1F900...0x1F9FF, // Supplemental Symbols and Pictographs + 127000...127600, // Various asian characters + 65024...65039, // Variation selector + 9100...9300, // Misc items + 8400...8447: // Combining Diacritical Marks for Symbols return true default: continue @@ -99,60 +107,52 @@ public extension String { /// "Hello".firstCharacterAsString -> Optional("H") /// "".firstCharacterAsString -> nil /// - public var firstCharacterAsString: String? { - guard let first = self.first else { return nil } + var firstCharacterAsString: String? { + guard let first = first else { return nil } return String(first) } - #if canImport(Foundation) /// SwifterSwift: Check if string contains one or more letters. /// /// "123abc".hasLetters -> true /// "123".hasLetters -> false /// - public var hasLetters: Bool { + var hasLetters: Bool { return rangeOfCharacter(from: .letters, options: .numeric, range: nil) != nil } - #endif - #if canImport(Foundation) /// SwifterSwift: Check if string contains one or more numbers. /// /// "abcd".hasNumbers -> false /// "123abc".hasNumbers -> true /// - public var hasNumbers: Bool { + var hasNumbers: Bool { return rangeOfCharacter(from: .decimalDigits, options: .literal, range: nil) != nil } - #endif - #if canImport(Foundation) /// SwifterSwift: Check if string contains only letters. /// /// "abc".isAlphabetic -> true /// "123abc".isAlphabetic -> false /// - public var isAlphabetic: Bool { + var isAlphabetic: Bool { let hasLetters = rangeOfCharacter(from: .letters, options: .numeric, range: nil) != nil let hasNumbers = rangeOfCharacter(from: .decimalDigits, options: .literal, range: nil) != nil return hasLetters && !hasNumbers } - #endif - #if canImport(Foundation) /// SwifterSwift: Check if string contains at least one letter and one number. /// /// // useful for passwords /// "123abc".isAlphaNumeric -> true /// "abc".isAlphaNumeric -> false /// - public var isAlphaNumeric: Bool { + var isAlphaNumeric: Bool { let hasLetters = rangeOfCharacter(from: .letters, options: .numeric, range: nil) != nil let hasNumbers = rangeOfCharacter(from: .decimalDigits, options: .literal, range: nil) != nil let comps = components(separatedBy: .alphanumerics) return comps.joined(separator: "").count == 0 && hasLetters && hasNumbers } - #endif #if canImport(Foundation) /// SwifterSwift: Check if string is valid email format. @@ -161,7 +161,7 @@ public extension String { /// /// "john@doe.com".isValidEmail -> true /// - public var isValidEmail: Bool { + var isValidEmail: Bool { // http://emailregex.com/ let regex = "^(?:[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[\\p{L}0-9](?:[a-z0-9-]*[\\p{L}0-9])?\\.)+[\\p{L}0-9](?:[\\p{L}0-9-]*[\\p{L}0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[\\p{L}0-9-]*[\\p{L}0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$" return range(of: regex, options: .regularExpression, range: nil, locale: nil) != nil @@ -173,7 +173,7 @@ public extension String { /// /// "https://google.com".isValidUrl -> true /// - public var isValidUrl: Bool { + var isValidUrl: Bool { return URL(string: self) != nil } #endif @@ -184,7 +184,7 @@ public extension String { /// "https://google.com".isValidSchemedUrl -> true /// "google.com".isValidSchemedUrl -> false /// - public var isValidSchemedUrl: Bool { + var isValidSchemedUrl: Bool { guard let url = URL(string: self) else { return false } return url.scheme != nil } @@ -195,7 +195,7 @@ public extension String { /// /// "https://google.com".isValidHttpsUrl -> true /// - public var isValidHttpsUrl: Bool { + var isValidHttpsUrl: Bool { guard let url = URL(string: self) else { return false } return url.scheme == "https" } @@ -206,7 +206,7 @@ public extension String { /// /// "http://google.com".isValidHttpUrl -> true /// - public var isValidHttpUrl: Bool { + var isValidHttpUrl: Bool { guard let url = URL(string: self) else { return false } return url.scheme == "http" } @@ -217,12 +217,12 @@ public extension String { /// /// "file://Documents/file.txt".isValidFileUrl -> true /// - public var isValidFileUrl: Bool { + var isValidFileUrl: Bool { return URL(string: self)?.isFileURL ?? false } #endif - #if canImport(Foundation) + #if canImport(Foundation) && !os(Linux) /// SwifterSwift: Check if string is a valid Swift number. /// /// Note: @@ -234,7 +234,7 @@ public extension String { /// "1,3".isNumeric -> true (fr_FR) /// "abc".isNumeric -> false /// - public var isNumeric: Bool { + var isNumeric: Bool { let scanner = Scanner(string: self) scanner.locale = NSLocale.current return scanner.scanDecimal(nil) && scanner.isAtEnd @@ -248,7 +248,7 @@ public extension String { /// "1.3".isDigits -> false /// "abc".isDigits -> false /// - public var isDigits: Bool { + var isDigits: Bool { return CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: self)) } #endif @@ -258,8 +258,8 @@ public extension String { /// "Hello".lastCharacterAsString -> Optional("o") /// "".lastCharacterAsString -> nil /// - public var lastCharacterAsString: String? { - guard let last = self.last else { return nil } + var lastCharacterAsString: String? { + guard let last = last else { return nil } return String(last) } @@ -268,7 +268,7 @@ public extension String { /// /// "Hèllö Wórld!".latinized -> "Hello World!" /// - public var latinized: String { + var latinized: String { return folding(options: .diacriticInsensitive, locale: Locale.current) } #endif @@ -280,12 +280,12 @@ public extension String { /// "False".bool -> false /// "Hello".bool = nil /// - public var bool: Bool? { + var bool: Bool? { let selfLowercased = trimmingCharacters(in: .whitespacesAndNewlines).lowercased() switch selfLowercased { - case "true", "1": + case "true", "yes", "1": return true - case "false", "0": + case "false", "no", "0": return false default: return nil @@ -298,7 +298,7 @@ public extension String { /// /// "2007-06-29".date -> Optional(Date) /// - public var date: Date? { + var date: Date? { let selfLowercased = trimmingCharacters(in: .whitespacesAndNewlines).lowercased() let formatter = DateFormatter() formatter.timeZone = TimeZone.current @@ -312,7 +312,7 @@ public extension String { /// /// "2007-06-29 14:23:09".dateTime -> Optional(Date) /// - public var dateTime: Date? { + var dateTime: Date? { let selfLowercased = trimmingCharacters(in: .whitespacesAndNewlines).lowercased() let formatter = DateFormatter() formatter.timeZone = TimeZone.current @@ -325,7 +325,7 @@ public extension String { /// /// "101".int -> 101 /// - public var int: Int? { + var int: Int? { return Int(self) } @@ -333,7 +333,7 @@ public extension String { /// /// - Parameter length: number of characters to limit lorem ipsum to (default is 445 - full lorem ipsum). /// - Returns: Lorem ipsum dolor sit amet... string. - public static func loremIpsum(ofLength length: Int = 445) -> String { + static func loremIpsum(ofLength length: Int = 445) -> String { guard length > 0 else { return "" } // https://www.lipsum.com/ @@ -352,7 +352,7 @@ public extension String { /// "https://google.com".url -> URL(string: "https://google.com") /// "not url".url -> nil /// - public var url: URL? { + var url: URL? { return URL(string: self) } #endif @@ -362,7 +362,7 @@ public extension String { /// /// " hello \n".trimmed -> "hello" /// - public var trimmed: String { + var trimmed: String { return trimmingCharacters(in: .whitespacesAndNewlines) } #endif @@ -372,7 +372,7 @@ public extension String { /// /// "it's%20easy%20to%20decode%20strings".urlDecoded -> "it's easy to decode strings" /// - public var urlDecoded: String { + var urlDecoded: String { return removingPercentEncoding ?? self } #endif @@ -382,7 +382,7 @@ public extension String { /// /// "it's easy to encode strings".urlEncoded -> "it's%20easy%20to%20encode%20strings" /// - public var urlEncoded: String { + var urlEncoded: String { return addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)! } #endif @@ -392,23 +392,23 @@ public extension String { /// /// " \n Swifter \n Swift ".withoutSpacesAndNewLines -> "SwifterSwift" /// - public var withoutSpacesAndNewLines: String { + var withoutSpacesAndNewLines: String { return replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "") } #endif #if canImport(Foundation) /// SwifterSwift: Check if the given string contains only white spaces - public var isWhitespace: Bool { - return self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty + var isWhitespace: Bool { + return trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } #endif #if os(iOS) || os(tvOS) /// SwifterSwift: Check if the given string spelled correctly - public var isSpelledCorrectly: Bool { + var isSpelledCorrectly: Bool { let checker = UITextChecker() - let range = NSRange(location: 0, length: self.utf16.count) + let range = NSRange(location: 0, length: utf16.count) let misspelledRange = checker.rangeOfMisspelledWord(in: self, range: range, startingAt: 0, wrap: false, language: Locale.preferredLanguages.first ?? "en") return misspelledRange.location == NSNotFound @@ -425,7 +425,7 @@ public extension String { /// /// - Parameter locale: Locale (default is Locale.current) /// - Returns: Optional Float value from given string. - public func float(locale: Locale = .current) -> Float? { + func float(locale: Locale = .current) -> Float? { let formatter = NumberFormatter() formatter.locale = locale formatter.allowsFloats = true @@ -438,7 +438,7 @@ public extension String { /// /// - Parameter locale: Locale (default is Locale.current) /// - Returns: Optional Double value from given string. - public func double(locale: Locale = .current) -> Double? { + func double(locale: Locale = .current) -> Double? { let formatter = NumberFormatter() formatter.locale = locale formatter.allowsFloats = true @@ -451,7 +451,7 @@ public extension String { /// /// - Parameter locale: Locale (default is Locale.current) /// - Returns: Optional CGFloat value from given string. - public func cgFloat(locale: Locale = .current) -> CGFloat? { + func cgFloat(locale: Locale = .current) -> CGFloat? { let formatter = NumberFormatter() formatter.locale = locale formatter.allowsFloats = true @@ -465,7 +465,7 @@ public extension String { /// "Hello\ntest".lines() -> ["Hello", "test"] /// /// - Returns: Strings separated by new lines. - public func lines() -> [String] { + func lines() -> [String] { var result = [String]() enumerateLines { line, _ in result.append(line) @@ -479,7 +479,7 @@ public extension String { /// /// "Hello world".localized -> Hallo Welt /// - public func localized(comment: String = "") -> String { + func localized(comment: String = "") -> String { return NSLocalizedString(self, comment: comment) } #endif @@ -489,11 +489,11 @@ public extension String { /// "This is a test, since e is appearing everywhere e should be the common character".mostCommonCharacter() -> "e" /// /// - Returns: The most common character. - public func mostCommonCharacter() -> Character? { + func mostCommonCharacter() -> Character? { let mostCommon = withoutSpacesAndNewLines.reduce(into: [Character: Int]()) { let count = $0[$1] ?? 0 $0[$1] = count + 1 - }.max { $0.1 < $1.1 }?.0 + }.max { $0.1 < $1.1 }?.key return mostCommon } @@ -503,7 +503,7 @@ public extension String { /// "SwifterSwift".unicodeArray() -> [83, 119, 105, 102, 116, 101, 114, 83, 119, 105, 102, 116] /// /// - Returns: The unicodes for all characters in a string. - public func unicodeArray() -> [Int] { + func unicodeArray() -> [Int] { return unicodeScalars.map { Int($0.value) } } @@ -513,7 +513,7 @@ public extension String { /// "Swift is amazing".words() -> ["Swift", "is", "amazing"] /// /// - Returns: The words contained in a string. - public func words() -> [String] { + func words() -> [String] { // https://stackoverflow.com/questions/42822838 let chararacterSet = CharacterSet.whitespacesAndNewlines.union(.punctuationCharacters) let comps = components(separatedBy: chararacterSet) @@ -527,7 +527,7 @@ public extension String { /// "Swift is amazing".wordsCount() -> 3 /// /// - Returns: The count of words contained in a string. - public func wordCount() -> Int { + func wordCount() -> Int { // https://stackoverflow.com/questions/42822838 let chararacterSet = CharacterSet.whitespacesAndNewlines.union(.punctuationCharacters) let comps = components(separatedBy: chararacterSet) @@ -542,9 +542,9 @@ public extension String { /// "Swift is amazing".toSlug() -> "swift-is-amazing" /// /// - Returns: The string in slug format. - public func toSlug() -> String { + func toSlug() -> String { let lowercased = self.lowercased() - let latinized = lowercased.latinized + let latinized = lowercased.folding(options: .diacriticInsensitive, locale: Locale.current) let withDashes = latinized.replacingOccurrences(of: " ", with: "-") let alphanumerics = NSCharacterSet.alphanumerics @@ -566,16 +566,15 @@ public extension String { } #endif - // swiftlint:disable next identifier_name /// SwifterSwift: Safely subscript string with index. /// /// "Hello World!"[safe: 3] -> "l" /// "Hello World!"[safe: 20] -> nil /// - /// - Parameter i: index. - public subscript(safe i: Int) -> Character? { - guard i >= 0 && i < count else { return nil } - return self[index(startIndex, offsetBy: i)] + /// - Parameter index: index. + subscript(safe index: Int) -> Character? { + guard index >= 0 && index < count else { return nil } + return self[self.index(startIndex, offsetBy: index)] } /// SwifterSwift: Safely subscript string within a half-open range. @@ -584,7 +583,7 @@ public extension String { /// "Hello World!"[safe: 21..<110] -> nil /// /// - Parameter range: Half-open range. - public subscript(safe range: CountableRange) -> String? { + subscript(safe range: CountableRange) -> String? { guard let lowerIndex = index(startIndex, offsetBy: max(0, range.lowerBound), limitedBy: endIndex) else { return nil } guard let upperIndex = index(lowerIndex, offsetBy: range.upperBound - range.lowerBound, limitedBy: endIndex) else { return nil } return String(self[lowerIndex.. nil /// /// - Parameter range: Closed range. - public subscript(safe range: ClosedRange) -> String? { + subscript(safe range: ClosedRange) -> String? { guard let lowerIndex = index(startIndex, offsetBy: max(0, range.lowerBound), limitedBy: endIndex) else { return nil } guard let upperIndex = index(lowerIndex, offsetBy: range.upperBound - range.lowerBound + 1, limitedBy: endIndex) else { return nil } return String(self[lowerIndex.. String { let source = lowercased() let first = source[.. "Hello world" /// "".firstCharacterUppercased() -> "" /// - public mutating func firstCharacterUppercased() { + mutating func firstCharacterUppercased() { guard let first = first else { return } self = String(first).uppercased() + dropFirst() } /// SwifterSwift: Check if string contains only unique characters. /// - public func hasUniqueCharacters() -> Bool { + func hasUniqueCharacters() -> Bool { guard count > 0 else { return false } var uniqueChars = Set() for char in self { @@ -670,7 +671,7 @@ public extension String { /// - string: substring to search for. /// - caseSensitive: set true for case sensitive search (default is true). /// - Returns: true if string contains one or more instance of substring. - public func contains(_ string: String, caseSensitive: Bool = true) -> Bool { + func contains(_ string: String, caseSensitive: Bool = true) -> Bool { if !caseSensitive { return range(of: string, options: .caseInsensitive) != nil } @@ -688,7 +689,7 @@ public extension String { /// - string: substring to search for. /// - caseSensitive: set true for case sensitive search (default is true). /// - Returns: count of appearance of substring in string. - public func count(of string: String, caseSensitive: Bool = true) -> Int { + func count(of string: String, caseSensitive: Bool = true) -> Int { if !caseSensitive { return lowercased().components(separatedBy: string.lowercased()).count - 1 } @@ -705,7 +706,7 @@ public extension String { /// - suffix: substring to search if string ends with. /// - caseSensitive: set true for case sensitive search (default is true). /// - Returns: true if string ends with substring. - public func ends(with suffix: String, caseSensitive: Bool = true) -> Bool { + func ends(with suffix: String, caseSensitive: Bool = true) -> Bool { if !caseSensitive { return lowercased().hasSuffix(suffix.lowercased()) } @@ -719,8 +720,10 @@ public extension String { /// str.latinize() /// print(str) // prints "Hello World!" /// - public mutating func latinize() { + @discardableResult + mutating func latinize() -> String { self = folding(options: .diacriticInsensitive, locale: Locale.current) + return self } #endif @@ -730,43 +733,41 @@ public extension String { /// /// - Parameter length: number of characters in string. /// - Returns: random string of given length. - public static func random(ofLength length: Int) -> String { + static func random(ofLength length: Int) -> String { guard length > 0 else { return "" } let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" var randomString = "" for _ in 1...length { - let randomIndex = Int.random(in: 0.. String { let chars: [Character] = reversed() self = String(chars) + return self } - // swiftlint:disable next identifier_name /// SwifterSwift: Sliced string from a start index with length. /// /// "Hello World".slicing(from: 6, length: 5) -> "World" /// /// - Parameters: - /// - i: string index the slicing should start from. + /// - index: string index the slicing should start from. /// - length: amount of characters to be sliced after given index. /// - Returns: sliced substring of length number of characters (if applicable) (example: "Hello World".slicing(from: 6, length: 5) -> "World") - public func slicing(from i: Int, length: Int) -> String? { - guard length >= 0, i >= 0, i < count else { return nil } - guard i.advanced(by: length) <= count else { - return self[safe: i.. String? { + guard length >= 0, index >= 0, index < count else { return nil } + guard index.advanced(by: length) <= count else { + return self[safe: index.. 0 else { return "" } - return self[safe: i.. String { + if let str = slicing(from: index, length: length) { self = String(str) } + return self } /// SwifterSwift: Slice given string from a start index to an end index (if applicable). @@ -791,26 +794,29 @@ public extension String { /// - Parameters: /// - start: string index the slicing should start from. /// - end: string index the slicing should end at. - public mutating func slice(from start: Int, to end: Int) { - guard end >= start else { return } + @discardableResult + mutating func slice(from start: Int, to end: Int) -> String { + guard end >= start else { return self } if let str = self[safe: start.. String { + guard index < count else { return self } + if let str = self[safe: index.. Bool { + func starts(with prefix: String, caseSensitive: Bool = true) -> Bool { if !caseSensitive { return lowercased().hasPrefix(prefix.lowercased()) } @@ -837,7 +843,7 @@ public extension String { /// /// - Parameter format: date format. /// - Returns: Date object from string (if applicable). - public func date(withFormat format: String) -> Date? { + func date(withFormat format: String) -> Date? { let dateFormatter = DateFormatter() dateFormatter.dateFormat = format return dateFormatter.date(from: self) @@ -851,8 +857,10 @@ public extension String { /// str.trim() /// print(str) // prints "Hello World" /// - public mutating func trim() { + @discardableResult + mutating func trim() -> String { self = trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + return self } #endif @@ -865,11 +873,13 @@ public extension String { /// - Parameters: /// - toLength: maximum number of characters before cutting. /// - trailing: string to add at the end of truncated string (default is "..."). - public mutating func truncate(toLength length: Int, trailing: String? = "...") { - guard length > 0 else { return } + @discardableResult + mutating func truncate(toLength length: Int, trailing: String? = "...") -> String { + guard length > 0 else { return self } if count > length { self = self[startIndex.. String { + func truncated(toLength length: Int, trailing: String? = "...") -> String { guard 1.. String { if let decoded = removingPercentEncoding { self = decoded } + return self } #endif @@ -907,10 +919,12 @@ public extension String { /// str.urlEncode() /// print(str) // prints "it's%20easy%20to%20encode%20strings" /// - public mutating func urlEncode() { + @discardableResult + mutating func urlEncode() -> String { if let encoded = addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) { self = encoded } + return self } #endif @@ -919,7 +933,7 @@ public extension String { /// /// - Parameter pattern: Pattern to verify. /// - Returns: true if string matches the pattern. - public func matches(pattern: String) -> Bool { + func matches(pattern: String) -> Bool { return range(of: pattern, options: .regularExpression, range: nil, locale: nil) != nil } #endif @@ -931,8 +945,10 @@ public extension String { /// /// - Parameter length: The target length to pad. /// - Parameter string: Pad string. Default is " ". - public mutating func padStart(_ length: Int, with string: String = " ") { + @discardableResult + mutating func padStart(_ length: Int, with string: String = " ") -> String { self = paddingStart(length, with: string) + return self } /// SwifterSwift: Returns a string by padding to fit the length parameter size with another string in the start. @@ -943,7 +959,7 @@ public extension String { /// - Parameter length: The target length to pad. /// - Parameter string: Pad string. Default is " ". /// - Returns: The string with the padding on the start. - public func paddingStart(_ length: Int, with string: String = " ") -> String { + func paddingStart(_ length: Int, with string: String = " ") -> String { guard count < length else { return self } let padLength = length - count @@ -965,8 +981,10 @@ public extension String { /// /// - Parameter length: The target length to pad. /// - Parameter string: Pad string. Default is " ". - public mutating func padEnd(_ length: Int, with string: String = " ") { + @discardableResult + mutating func padEnd(_ length: Int, with string: String = " ") -> String { self = paddingEnd(length, with: string) + return self } /// SwifterSwift: Returns a string by padding to fit the length parameter size with another string in the end. @@ -977,7 +995,7 @@ public extension String { /// - Parameter length: The target length to pad. /// - Parameter string: Pad string. Default is " ". /// - Returns: The string with the padding on the end. - public func paddingEnd(_ length: Int, with string: String = " ") -> String { + func paddingEnd(_ length: Int, with string: String = " ") -> String { guard count < length else { return self } let padLength = length - count @@ -998,7 +1016,7 @@ public extension String { /// /// - Parameter prefix: Prefix to remove from the string. /// - Returns: The string after prefix removing. - public func removingPrefix(_ prefix: String) -> String { + func removingPrefix(_ prefix: String) -> String { guard hasPrefix(prefix) else { return self } return String(dropFirst(prefix.count)) } @@ -1009,7 +1027,7 @@ public extension String { /// /// - Parameter suffix: Suffix to remove from the string. /// - Returns: The string after suffix removing. - public func removingSuffix(_ suffix: String) -> String { + func removingSuffix(_ suffix: String) -> String { guard hasSuffix(suffix) else { return self } return String(dropLast(suffix.count)) } @@ -1026,7 +1044,7 @@ public extension String { /// String(base64: "hello") = nil /// /// - Parameter base64: base64 string. - public init?(base64: String) { + init?(base64: String) { guard let decodedData = Data(base64Encoded: base64) else { return nil } guard let str = String(data: decodedData, encoding: .utf8) else { return nil } self.init(str) @@ -1038,7 +1056,7 @@ public extension String { /// String(randomOfLength: 10) -> "gY8r3MHvlQ" /// /// - Parameter length: number of characters in string. - public init(randomOfLength length: Int) { + init(randomOfLength length: Int) { guard length > 0 else { self.init() return @@ -1047,15 +1065,15 @@ public extension String { let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" var randomString = "" for _ in 1...length { - let randomIndex = Int.random(in: 0.. NSAttributedString { + func colored(with color: UIColor) -> NSAttributedString { return NSMutableAttributedString(string: self, attributes: [.foregroundColor: color]) } #endif @@ -1110,13 +1128,15 @@ public extension String { /// /// - Parameter color: text color. /// - Returns: a NSAttributedString versions of string colored with given color. - public func colored(with color: NSColor) -> NSAttributedString { + func colored(with color: NSColor) -> NSAttributedString { return NSMutableAttributedString(string: self, attributes: [.foregroundColor: color]) } #endif } +#endif + // MARK: - Operators public extension String { @@ -1128,7 +1148,7 @@ public extension String { /// - lhs: string to repeat. /// - rhs: number of times to repeat character. /// - Returns: new string with given string repeated n times. - public static func * (lhs: String, rhs: Int) -> String { + static func * (lhs: String, rhs: Int) -> String { guard rhs > 0 else { return "" } return String(repeating: lhs, count: rhs) } @@ -1141,44 +1161,45 @@ public extension String { /// - lhs: number of times to repeat character. /// - rhs: string to repeat. /// - Returns: new string with given string repeated n times. - public static func * (lhs: Int, rhs: String) -> String { + static func * (lhs: Int, rhs: String) -> String { guard lhs > 0 else { return "" } return String(repeating: rhs, count: lhs) } } -#if canImport(Foundation) +#if canImport(Foundation) && !os(Linux) + // MARK: - NSString extensions public extension String { /// SwifterSwift: NSString from a string. - public var nsString: NSString { + var nsString: NSString { return NSString(string: self) } /// SwifterSwift: NSString lastPathComponent. - public var lastPathComponent: String { + var lastPathComponent: String { return (self as NSString).lastPathComponent } /// SwifterSwift: NSString pathExtension. - public var pathExtension: String { + var pathExtension: String { return (self as NSString).pathExtension } /// SwifterSwift: NSString deletingLastPathComponent. - public var deletingLastPathComponent: String { + var deletingLastPathComponent: String { return (self as NSString).deletingLastPathComponent } /// SwifterSwift: NSString deletingPathExtension. - public var deletingPathExtension: String { + var deletingPathExtension: String { return (self as NSString).deletingPathExtension } /// SwifterSwift: NSString pathComponents. - public var pathComponents: [String] { + var pathComponents: [String] { return (self as NSString).pathComponents } @@ -1186,7 +1207,7 @@ public extension String { /// /// - Parameter str: the path component to append to the receiver. /// - Returns: a new string made by appending aString to the receiver, preceded if necessary by a path separator. - public func appendingPathComponent(_ str: String) -> String { + func appendingPathComponent(_ str: String) -> String { return (self as NSString).appendingPathComponent(str) } @@ -1194,9 +1215,10 @@ public extension String { /// /// - Parameter str: The extension to append to the receiver. /// - Returns: a new string made by appending to the receiver an extension separator followed by ext (if applicable). - public func appendingPathExtension(_ str: String) -> String? { + func appendingPathExtension(_ str: String) -> String? { return (self as NSString).appendingPathExtension(str) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/StringProtocolExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/StringProtocolExtensions.swift new file mode 100644 index 0000000..d89dd32 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/SwiftStdlib/StringProtocolExtensions.swift @@ -0,0 +1,41 @@ +// +// StringProtocolExtensions.swift +// SwifterSwift +// +// Created by Max Härtwig on 11/26/17. +// Copyright © 2017 SwifterSwift +// + +import Foundation + +public extension StringProtocol { + + /// SwifterSwift: The longest common suffix. + /// + /// "Hello world!".commonSuffix(with: "It's cold!") = "ld!" + /// + /// - Parameters: + /// - Parameter aString: The string with which to compare the receiver. + /// - Parameter options: Options for the comparison. + /// - Returns: The longest common suffix of the receiver and the given String + func commonSuffix(with aString: T, options: String.CompareOptions = []) -> String { + guard !isEmpty && !aString.isEmpty else { return "" } + + var idx = endIndex + var strIdx = aString.endIndex + + repeat { + formIndex(before: &idx) + aString.formIndex(before: &strIdx) + + guard String(self[idx]).compare(String(aString[strIdx]), options: options) == .orderedSame else { + formIndex(after: &idx) + break + } + + } while idx > startIndex && strIdx > aString.startIndex + + return String(self[idx...]) + } + +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIActivityExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIActivityExtensions.swift new file mode 100644 index 0000000..a225dc7 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIActivityExtensions.swift @@ -0,0 +1,29 @@ +// +// UIActivityExtensions.swift +// SwifterSwift +// +// Created by Hannes Staffler on 07.10.18. +// Copyright © 2018 SwifterSwift +// + +#if canImport(UIKit) && os(iOS) +import UIKit + +// MARK: - ActivityType +public extension UIActivity.ActivityType { + + /// SwifterSwift: AddToiCloudDrive + static let addToiCloudDrive = UIActivity.ActivityType("com.apple.CloudDocsUI.AddToiCloudDrive") + + /// SwifterSwift: WhatsApp share extension + static let postToWhatsApp = UIActivity.ActivityType("net.whatsapp.WhatsApp.ShareExtension") + + /// SwifterSwift: LinkedIn share extension + static let postToLinkedIn = UIActivity.ActivityType("com.linkedin.LinkedIn.ShareExtension") + + /// SwifterSwift: XING share extension + static let postToXing = UIActivity.ActivityType("com.xing.XING.Xing-Share") + +} + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIAlertControllerExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIAlertControllerExtensions.swift similarity index 82% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIAlertControllerExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIAlertControllerExtensions.swift index ae89572..011bc0d 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIAlertControllerExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIAlertControllerExtensions.swift @@ -13,7 +13,7 @@ import UIKit import AudioToolbox #endif -// MARK: - Methodss +// MARK: - Methods public extension UIAlertController { /// SwifterSwift: Present alert view controller in the current view controller. @@ -22,7 +22,7 @@ public extension UIAlertController { /// - animated: set true to animate presentation of alert controller (default is true). /// - vibrate: set true to vibrate the device while presenting the alert (default is false). /// - completion: an optional completion handler to be called after presenting alert controller (default is nil). - public func show(animated: Bool = true, vibrate: Bool = false, completion: (() -> Void)? = nil) { + func show(animated: Bool = true, vibrate: Bool = false, completion: (() -> Void)? = nil) { UIApplication.shared.keyWindow?.rootViewController?.present(self, animated: animated, completion: completion) if vibrate { #if canImport(AudioToolbox) @@ -39,7 +39,8 @@ public extension UIAlertController { /// - isEnabled: isEnabled status for action (default is true) /// - handler: optional action handler to be called when button is tapped (default is nil) /// - Returns: action created by this method - @discardableResult public func addAction(title: String, style: UIAlertAction.Style = .default, isEnabled: Bool = true, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction { + @discardableResult + func addAction(title: String, style: UIAlertAction.Style = .default, isEnabled: Bool = true, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction { let action = UIAlertAction(title: title, style: style, handler: handler) action.isEnabled = isEnabled addAction(action) @@ -53,7 +54,7 @@ public extension UIAlertController { /// - placeholder: text field placeholder text (default is nil) /// - editingChangedTarget: an optional target for text field's editingChanged /// - editingChangedSelector: an optional selector for text field's editingChanged - public func addTextField(text: String? = nil, placeholder: String? = nil, editingChangedTarget: Any?, editingChangedSelector: Selector?) { + func addTextField(text: String? = nil, placeholder: String? = nil, editingChangedTarget: Any?, editingChangedSelector: Selector?) { addTextField { textField in textField.text = text textField.placeholder = placeholder @@ -75,7 +76,7 @@ public extension UIAlertController { /// - message: alert controller's message (default is nil). /// - defaultActionButtonTitle: default action button title (default is "OK") /// - tintColor: alert controller's tint color (default is nil) - public convenience init(title: String, message: String? = nil, defaultActionButtonTitle: String = "OK", tintColor: UIColor? = nil) { + convenience init(title: String, message: String? = nil, defaultActionButtonTitle: String = "OK", tintColor: UIColor? = nil) { self.init(title: title, message: message, preferredStyle: .alert) let defaultAction = UIAlertAction(title: defaultActionButtonTitle, style: .default, handler: nil) addAction(defaultAction) @@ -91,7 +92,7 @@ public extension UIAlertController { /// - error: error to set alert controller's message to it's localizedDescription. /// - defaultActionButtonTitle: default action button title (default is "OK") /// - tintColor: alert controller's tint color (default is nil) - public convenience init(title: String = "Error", error: Error, defaultActionButtonTitle: String = "OK", preferredStyle: UIAlertController.Style = .alert, tintColor: UIColor? = nil) { + convenience init(title: String = "Error", error: Error, defaultActionButtonTitle: String = "OK", preferredStyle: UIAlertController.Style = .alert, tintColor: UIColor? = nil) { self.init(title: title, message: error.localizedDescription, preferredStyle: preferredStyle) let defaultAction = UIAlertAction(title: defaultActionButtonTitle, style: .default, handler: nil) addAction(defaultAction) @@ -101,4 +102,5 @@ public extension UIAlertController { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIApplicationExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIApplicationExtensions.swift new file mode 100644 index 0000000..e29d234 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIApplicationExtensions.swift @@ -0,0 +1,75 @@ +// +// UIApplicationExtensions.swift +// SwifterSwift +// +// Created by Omar Albeik on 3/30/19. +// Copyright © 2019 SwifterSwift +// + +#if canImport(UIKit) +import UIKit + +#if os(iOS) || os(tvOS) + +public extension UIApplication { + + /// SwifterSwift: Application running environment. + /// + /// - debug: Application is running in debug mode. + /// - testFlight: Application is installed from Test Flight. + /// - appStore: Application is installed from the App Store. + enum Environment { + case debug + case testFlight + case appStore + } + + /// SwifterSwift: Current inferred app environment. + var inferredEnvironment: Environment { + #if DEBUG + return .debug + + #elseif targetEnvironment(simulator) + return .debug + + #else + if Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil { + return .testFlight + } + + guard let appStoreReceiptUrl = Bundle.main.appStoreReceiptURL else { + return .debug + } + + if appStoreReceiptUrl.lastPathComponent.lowercased() == "sandboxreceipt" { + return .testFlight + } + + if appStoreReceiptUrl.path.lowercased().contains("simulator") { + return .debug + } + + return .appStore + #endif + } + + /// SwifterSwift: Application name (if applicable). + var displayName: String? { + return Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String + } + + /// SwifterSwift: App current build number (if applicable). + var buildNumber: String? { + return Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String + } + + /// SwifterSwift: App's current version number (if applicable). + var version: String? { + return Bundle.main.infoDictionary?[kCFBundleInfoDictionaryVersionKey as String] as? String + } + +} + +#endif + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIBarButtonItemExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIBarButtonItemExtensions.swift similarity index 86% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIBarButtonItemExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIBarButtonItemExtensions.swift index 281daa8..f38d171 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIBarButtonItemExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIBarButtonItemExtensions.swift @@ -17,10 +17,11 @@ public extension UIBarButtonItem { /// - Parameters: /// - target: target. /// - action: selector to run when button is tapped. - public func addTargetForAction(_ target: AnyObject, action: Selector) { + func addTargetForAction(_ target: AnyObject, action: Selector) { self.target = target self.action = action } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIButtonExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIButtonExtensions.swift similarity index 78% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIButtonExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIButtonExtensions.swift index b73cf41..5bbea63 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIButtonExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIButtonExtensions.swift @@ -13,7 +13,8 @@ import UIKit public extension UIButton { /// SwifterSwift: Image of disabled state for button; also inspectable from Storyboard. - @IBInspectable public var imageForDisabled: UIImage? { + @IBInspectable + var imageForDisabled: UIImage? { get { return image(for: .disabled) } @@ -23,7 +24,8 @@ public extension UIButton { } /// SwifterSwift: Image of highlighted state for button; also inspectable from Storyboard. - @IBInspectable public var imageForHighlighted: UIImage? { + @IBInspectable + var imageForHighlighted: UIImage? { get { return image(for: .highlighted) } @@ -33,7 +35,8 @@ public extension UIButton { } /// SwifterSwift: Image of normal state for button; also inspectable from Storyboard. - @IBInspectable public var imageForNormal: UIImage? { + @IBInspectable + var imageForNormal: UIImage? { get { return image(for: .normal) } @@ -43,7 +46,8 @@ public extension UIButton { } /// SwifterSwift: Image of selected state for button; also inspectable from Storyboard. - @IBInspectable public var imageForSelected: UIImage? { + @IBInspectable + var imageForSelected: UIImage? { get { return image(for: .selected) } @@ -53,7 +57,8 @@ public extension UIButton { } /// SwifterSwift: Title color of disabled state for button; also inspectable from Storyboard. - @IBInspectable public var titleColorForDisabled: UIColor? { + @IBInspectable + var titleColorForDisabled: UIColor? { get { return titleColor(for: .disabled) } @@ -63,7 +68,8 @@ public extension UIButton { } /// SwifterSwift: Title color of highlighted state for button; also inspectable from Storyboard. - @IBInspectable public var titleColorForHighlighted: UIColor? { + @IBInspectable + var titleColorForHighlighted: UIColor? { get { return titleColor(for: .highlighted) } @@ -73,7 +79,8 @@ public extension UIButton { } /// SwifterSwift: Title color of normal state for button; also inspectable from Storyboard. - @IBInspectable public var titleColorForNormal: UIColor? { + @IBInspectable + var titleColorForNormal: UIColor? { get { return titleColor(for: .normal) } @@ -83,7 +90,8 @@ public extension UIButton { } /// SwifterSwift: Title color of selected state for button; also inspectable from Storyboard. - @IBInspectable public var titleColorForSelected: UIColor? { + @IBInspectable + var titleColorForSelected: UIColor? { get { return titleColor(for: .selected) } @@ -93,7 +101,8 @@ public extension UIButton { } /// SwifterSwift: Title of disabled state for button; also inspectable from Storyboard. - @IBInspectable public var titleForDisabled: String? { + @IBInspectable + var titleForDisabled: String? { get { return title(for: .disabled) } @@ -103,7 +112,8 @@ public extension UIButton { } /// SwifterSwift: Title of highlighted state for button; also inspectable from Storyboard. - @IBInspectable public var titleForHighlighted: String? { + @IBInspectable + var titleForHighlighted: String? { get { return title(for: .highlighted) } @@ -113,7 +123,8 @@ public extension UIButton { } /// SwifterSwift: Title of normal state for button; also inspectable from Storyboard. - @IBInspectable public var titleForNormal: String? { + @IBInspectable + var titleForNormal: String? { get { return title(for: .normal) } @@ -123,7 +134,8 @@ public extension UIButton { } /// SwifterSwift: Title of selected state for button; also inspectable from Storyboard. - @IBInspectable public var titleForSelected: String? { + @IBInspectable + var titleForSelected: String? { get { return title(for: .selected) } @@ -144,28 +156,28 @@ public extension UIButton { /// SwifterSwift: Set image for all states. /// /// - Parameter image: UIImage. - public func setImageForAllStates(_ image: UIImage) { - states.forEach { self.setImage(image, for: $0) } + func setImageForAllStates(_ image: UIImage) { + states.forEach { setImage(image, for: $0) } } /// SwifterSwift: Set title color for all states. /// /// - Parameter color: UIColor. - public func setTitleColorForAllStates(_ color: UIColor) { - states.forEach { self.setTitleColor(color, for: $0) } + func setTitleColorForAllStates(_ color: UIColor) { + states.forEach { setTitleColor(color, for: $0) } } /// SwifterSwift: Set title for all states. /// /// - Parameter title: title string. - public func setTitleForAllStates(_ title: String) { - states.forEach { self.setTitle(title, for: $0) } + func setTitleForAllStates(_ title: String) { + states.forEach { setTitle(title, for: $0) } } /// SwifterSwift: Center align title text and image on UIButton /// /// - Parameter spacing: spacing between UIButton title text and UIButton Image. - public func centerTextAndImage(spacing: CGFloat) { + func centerTextAndImage(spacing: CGFloat) { let insetAmount = spacing / 2 imageEdgeInsets = UIEdgeInsets(top: 0, left: -insetAmount, bottom: 0, right: insetAmount) titleEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: -insetAmount) @@ -173,4 +185,5 @@ public extension UIButton { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UICollectionViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UICollectionViewExtensions.swift similarity index 80% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UICollectionViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UICollectionViewExtensions.swift index b9541f0..99e3a15 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UICollectionViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UICollectionViewExtensions.swift @@ -13,12 +13,12 @@ import UIKit public extension UICollectionView { /// SwifterSwift: Index path of last item in collectionView. - public var indexPathForLastItem: IndexPath? { + var indexPathForLastItem: IndexPath? { return indexPathForLastItem(inSection: lastSection) } /// SwifterSwift: Index of last section in collectionView. - public var lastSection: Int { + var lastSection: Int { return numberOfSections > 0 ? numberOfSections - 1 : 0 } @@ -30,10 +30,10 @@ public extension UICollectionView { /// SwifterSwift: Number of all items in all sections of collectionView. /// /// - Returns: The count of all rows in the collectionView. - public func numberOfItems() -> Int { + func numberOfItems() -> Int { var section = 0 var itemsCount = 0 - while section < self.numberOfSections { + while section < numberOfSections { itemsCount += numberOfItems(inSection: section) section += 1 } @@ -44,7 +44,7 @@ public extension UICollectionView { /// /// - Parameter section: section to get last item in. /// - Returns: optional last indexPath for last item in section (if applicable). - public func indexPathForLastItem(inSection section: Int) -> IndexPath? { + func indexPathForLastItem(inSection section: Int) -> IndexPath? { guard section >= 0 else { return nil } @@ -60,7 +60,7 @@ public extension UICollectionView { /// SwifterSwift: Reload data with a completion handler. /// /// - Parameter completion: completion handler to run after reloadData finishes. - public func reloadData(_ completion: @escaping () -> Void) { + func reloadData(_ completion: @escaping () -> Void) { UIView.animate(withDuration: 0, animations: { self.reloadData() }, completion: { _ in @@ -74,9 +74,9 @@ public extension UICollectionView { /// - name: UICollectionViewCell type. /// - indexPath: location of cell in collectionView. /// - Returns: UICollectionViewCell object with associated class name. - public func dequeueReusableCell(withClass name: T.Type, for indexPath: IndexPath) -> T { + func dequeueReusableCell(withClass name: T.Type, for indexPath: IndexPath) -> T { guard let cell = dequeueReusableCell(withReuseIdentifier: String(describing: name), for: indexPath) as? T else { - fatalError("Couldn't find UICollectionViewCell for \(String(describing: name))") + fatalError("Couldn't find UICollectionViewCell for \(String(describing: name)), make sure the cell is registered with collection view") } return cell } @@ -88,9 +88,9 @@ public extension UICollectionView { /// - name: UICollectionReusableView type. /// - indexPath: location of cell in collectionView. /// - Returns: UICollectionReusableView object with associated class name. - public func dequeueReusableSupplementaryView(ofKind kind: String, withClass name: T.Type, for indexPath: IndexPath) -> T { + func dequeueReusableSupplementaryView(ofKind kind: String, withClass name: T.Type, for indexPath: IndexPath) -> T { guard let cell = dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: name), for: indexPath) as? T else { - fatalError("Couldn't find UICollectionReusableView for \(String(describing: name))") + fatalError("Couldn't find UICollectionReusableView for \(String(describing: name)), make sure the view is registered with collection view") } return cell } @@ -100,7 +100,7 @@ public extension UICollectionView { /// - Parameters: /// - kind: the kind of supplementary view to retrieve. This value is defined by the layout object. /// - name: UICollectionReusableView type. - public func register(supplementaryViewOfKind kind: String, withClass name: T.Type) { + func register(supplementaryViewOfKind kind: String, withClass name: T.Type) { register(T.self, forSupplementaryViewOfKind: kind, withReuseIdentifier: String(describing: name)) } @@ -109,14 +109,14 @@ public extension UICollectionView { /// - Parameters: /// - nib: Nib file used to create the collectionView cell. /// - name: UICollectionViewCell type. - public func register(nib: UINib?, forCellWithClass name: T.Type) { + func register(nib: UINib?, forCellWithClass name: T.Type) { register(nib, forCellWithReuseIdentifier: String(describing: name)) } /// SwifterSwift: Register UICollectionViewCell using class name. /// /// - Parameter name: UICollectionViewCell type. - public func register(cellWithClass name: T.Type) { + func register(cellWithClass name: T.Type) { register(T.self, forCellWithReuseIdentifier: String(describing: name)) } @@ -126,7 +126,7 @@ public extension UICollectionView { /// - nib: Nib file used to create the reusable view. /// - kind: the kind of supplementary view to retrieve. This value is defined by the layout object. /// - name: UICollectionReusableView type. - public func register(nib: UINib?, forSupplementaryViewOfKind kind: String, withClass name: T.Type) { + func register(nib: UINib?, forSupplementaryViewOfKind kind: String, withClass name: T.Type) { register(nib, forSupplementaryViewOfKind: kind, withReuseIdentifier: String(describing: name)) } @@ -136,7 +136,7 @@ public extension UICollectionView { /// - Parameters: /// - name: UICollectionViewCell type. /// - bundleClass: Class in which the Bundle instance will be based on. - public func register(nibWithCellClass name: T.Type, at bundleClass: AnyClass? = nil) { + func register(nibWithCellClass name: T.Type, at bundleClass: AnyClass? = nil) { let identifier = String(describing: name) var bundle: Bundle? @@ -148,4 +148,5 @@ public extension UICollectionView { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIDatePickerExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIDatePickerExtensions.swift similarity index 92% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIDatePickerExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIDatePickerExtensions.swift index 2282d91..e691d6f 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIDatePickerExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIDatePickerExtensions.swift @@ -13,7 +13,7 @@ import UIKit public extension UIDatePicker { /// SwifterSwift: Text color of UIDatePicker. - public var textColor: UIColor? { + var textColor: UIColor? { set { setValue(newValue, forKeyPath: "textColor") } @@ -23,4 +23,5 @@ public extension UIDatePicker { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIEdgeInsetsExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIEdgeInsetsExtensions.swift similarity index 86% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIEdgeInsetsExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIEdgeInsetsExtensions.swift index 6c996d8..fd14a17 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIEdgeInsetsExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIEdgeInsetsExtensions.swift @@ -12,15 +12,15 @@ import UIKit extension UIEdgeInsets { /// SwifterSwift: Return the vertical insets. The vertical insets is composed by top + bottom. /// - public var vertical: CGFloat { - // Source: https://github.com/MessageKit/MessageKit/blob/master/Sources/Extensions/UIEdgeInsets%2BExtensions.swift + var vertical: CGFloat { + // Source: https://github.com/MessageKit/MessageKit/blob/master/Sources/SwifterSwift/UIEdgeInsets%2BExtensions.swift return top + bottom } /// SwifterSwift: Return the horizontal insets. The horizontal insets is composed by left + right. /// - public var horizontal: CGFloat { - // Source: https://github.com/MessageKit/MessageKit/blob/master/Sources/Extensions/UIEdgeInsets%2BExtensions.swift + var horizontal: CGFloat { + // Source: https://github.com/MessageKit/MessageKit/blob/master/Sources/SwifterSwift/UIEdgeInsets%2BExtensions.swift return left + right } @@ -50,7 +50,7 @@ extension UIEdgeInsets { /// - Parameters: /// - top: Offset to be applied in to the top edge. /// - Returns: UIEdgeInsets offset with given offset. - public func insetBy(top: CGFloat) -> UIEdgeInsets { + func insetBy(top: CGFloat) -> UIEdgeInsets { return UIEdgeInsets(top: self.top + top, left: left, bottom: bottom, right: right) } @@ -59,7 +59,7 @@ extension UIEdgeInsets { /// - Parameters: /// - left: Offset to be applied in to the left edge. /// - Returns: UIEdgeInsets offset with given offset. - public func insetBy(left: CGFloat) -> UIEdgeInsets { + func insetBy(left: CGFloat) -> UIEdgeInsets { return UIEdgeInsets(top: top, left: self.left + left, bottom: bottom, right: right) } @@ -68,7 +68,7 @@ extension UIEdgeInsets { /// - Parameters: /// - bottom: Offset to be applied in to the bottom edge. /// - Returns: UIEdgeInsets offset with given offset. - public func insetBy(bottom: CGFloat) -> UIEdgeInsets { + func insetBy(bottom: CGFloat) -> UIEdgeInsets { return UIEdgeInsets(top: top, left: left, bottom: self.bottom + bottom, right: right) } @@ -77,7 +77,7 @@ extension UIEdgeInsets { /// - Parameters: /// - right: Offset to be applied in to the right edge. /// - Returns: UIEdgeInsets offset with given offset. - public func insetBy(right: CGFloat) -> UIEdgeInsets { + func insetBy(right: CGFloat) -> UIEdgeInsets { return UIEdgeInsets(top: top, left: left, bottom: bottom, right: self.right + right) } @@ -86,7 +86,7 @@ extension UIEdgeInsets { /// - Parameters: /// - horizontal: Offset to be applied to right and left. /// - Returns: UIEdgeInsets offset with given offset. - public func insetBy(horizontal: CGFloat) -> UIEdgeInsets { + func insetBy(horizontal: CGFloat) -> UIEdgeInsets { return UIEdgeInsets(top: top, left: left + horizontal/2, bottom: bottom, right: right + horizontal/2) } @@ -95,7 +95,7 @@ extension UIEdgeInsets { /// - Parameters: /// - vertical: Offset to be applied to top and bottom. /// - Returns: UIEdgeInsets offset with given offset. - public func insetBy(vertical: CGFloat) -> UIEdgeInsets { + func insetBy(vertical: CGFloat) -> UIEdgeInsets { return UIEdgeInsets(top: top + vertical/2, left: left, bottom: bottom + vertical/2, right: right) } } @@ -109,7 +109,7 @@ extension UIEdgeInsets { /// - lhs: The left-hand expression /// - rhs: The right-hand expression /// - Returns: A new `UIEdgeInsets` instance where the values of `lhs` and `rhs` are added together. - public static func + (_ lhs: UIEdgeInsets, _ rhs: UIEdgeInsets) -> UIEdgeInsets { + static func + (_ lhs: UIEdgeInsets, _ rhs: UIEdgeInsets) -> UIEdgeInsets { return UIEdgeInsets(top: lhs.top + rhs.top, left: lhs.left + rhs.left, bottom: lhs.bottom + rhs.bottom, @@ -121,7 +121,7 @@ extension UIEdgeInsets { /// - Parameters: /// - lhs: The left-hand expression to be mutated /// - rhs: The right-hand expression - public static func += (_ lhs: inout UIEdgeInsets, _ rhs: UIEdgeInsets) { + static func += (_ lhs: inout UIEdgeInsets, _ rhs: UIEdgeInsets) { lhs.top += rhs.top lhs.left += rhs.left lhs.bottom += rhs.bottom diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIFontExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIFontExtensions.swift similarity index 91% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIFontExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIFontExtensions.swift index cc3fe26..740bb2d 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIFontExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIFontExtensions.swift @@ -13,12 +13,12 @@ import UIKit public extension UIFont { /// SwifterSwift: Font as bold font - public var bold: UIFont { + var bold: UIFont { return UIFont(descriptor: fontDescriptor.withSymbolicTraits(.traitBold)!, size: 0) } /// SwifterSwift: Font as italic font - public var italic: UIFont { + var italic: UIFont { return UIFont(descriptor: fontDescriptor.withSymbolicTraits(.traitItalic)!, size: 0) } @@ -26,7 +26,7 @@ public extension UIFont { /// /// UIFont.preferredFont(forTextStyle: .body).monospaced /// - public var monospaced: UIFont { + var monospaced: UIFont { let settings = [[UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType, UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector]] let attributes = [UIFontDescriptor.AttributeName.featureSettings: settings] @@ -35,4 +35,5 @@ public extension UIFont { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIGestureRecognizerExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIGestureRecognizerExtensions.swift similarity index 79% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIGestureRecognizerExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIGestureRecognizerExtensions.swift index 086f1ee..855abc0 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIGestureRecognizerExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIGestureRecognizerExtensions.swift @@ -13,9 +13,10 @@ import UIKit public extension UIGestureRecognizer { /// SwifterSwift: Remove Gesture Recognizer from its view. - public func removeFromView() { - self.view?.removeGestureRecognizer(self) + func removeFromView() { + view?.removeGestureRecognizer(self) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIImageExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIImageExtensions.swift similarity index 87% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIImageExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIImageExtensions.swift index 344fd67..8efa2a3 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIImageExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIImageExtensions.swift @@ -13,22 +13,22 @@ import UIKit public extension UIImage { /// SwifterSwift: Size in bytes of UIImage - public var bytesSize: Int { + var bytesSize: Int { return jpegData(compressionQuality: 1)?.count ?? 0 } /// SwifterSwift: Size in kilo bytes of UIImage - public var kilobytesSize: Int { + var kilobytesSize: Int { return bytesSize / 1024 } /// SwifterSwift: UIImage with .alwaysOriginal rendering mode. - public var original: UIImage { + var original: UIImage { return withRenderingMode(.alwaysOriginal) } /// SwifterSwift: UIImage with .alwaysTemplate rendering mode. - public var template: UIImage { + var template: UIImage { return withRenderingMode(.alwaysTemplate) } @@ -41,7 +41,7 @@ public extension UIImage { /// /// - Parameter quality: The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality), (default is 0.5). /// - Returns: optional UIImage (if applicable). - public func compressed(quality: CGFloat = 0.5) -> UIImage? { + func compressed(quality: CGFloat = 0.5) -> UIImage? { guard let data = compressedData(quality: quality) else { return nil } return UIImage(data: data) } @@ -50,7 +50,7 @@ public extension UIImage { /// /// - Parameter quality: The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality), (default is 0.5). /// - Returns: optional Data (if applicable). - public func compressedData(quality: CGFloat = 0.5) -> Data? { + func compressedData(quality: CGFloat = 0.5) -> Data? { return jpegData(compressionQuality: quality) } @@ -58,8 +58,8 @@ public extension UIImage { /// /// - Parameter rect: CGRect to crop UIImage to. /// - Returns: cropped UIImage - public func cropped(to rect: CGRect) -> UIImage { - guard rect.size.height < size.height && rect.size.height < size.height else { return self } + func cropped(to rect: CGRect) -> UIImage { + guard rect.size.width < size.width && rect.size.height < size.height else { return self } guard let image: CGImage = cgImage?.cropping(to: rect) else { return self } return UIImage(cgImage: image) } @@ -70,7 +70,7 @@ public extension UIImage { /// - toHeight: new height. /// - opaque: flag indicating whether the bitmap is opaque. /// - Returns: optional scaled UIImage (if applicable). - public func scaled(toHeight: CGFloat, opaque: Bool = false) -> UIImage? { + func scaled(toHeight: CGFloat, opaque: Bool = false) -> UIImage? { let scale = toHeight / size.height let newWidth = size.width * scale UIGraphicsBeginImageContextWithOptions(CGSize(width: newWidth, height: toHeight), opaque, 0) @@ -86,7 +86,7 @@ public extension UIImage { /// - toWidth: new width. /// - opaque: flag indicating whether the bitmap is opaque. /// - Returns: optional scaled UIImage (if applicable). - public func scaled(toWidth: CGFloat, opaque: Bool = false) -> UIImage? { + func scaled(toWidth: CGFloat, opaque: Bool = false) -> UIImage? { let scale = toWidth / size.width let newHeight = size.height * scale UIGraphicsBeginImageContextWithOptions(CGSize(width: toWidth, height: newHeight), opaque, 0) @@ -104,7 +104,7 @@ public extension UIImage { /// - Parameter angle: The angle measurement by which to rotate the image. /// - Returns: A new image rotated by the given angle. @available(iOS 10.0, tvOS 10.0, watchOS 3.0, *) - public func rotated(by angle: Measurement) -> UIImage? { + func rotated(by angle: Measurement) -> UIImage? { let radians = CGFloat(angle.converted(to: .radians).value) let destRect = CGRect(origin: .zero, size: size) @@ -136,7 +136,7 @@ public extension UIImage { /// /// - Parameter radians: The angle, in radians, by which to rotate the image. /// - Returns: A new image rotated by the given angle. - public func rotated(by radians: CGFloat) -> UIImage? { + func rotated(by radians: CGFloat) -> UIImage? { let destRect = CGRect(origin: .zero, size: size) .applying(CGAffineTransform(rotationAngle: radians)) let roundedDestRect = CGRect(x: destRect.origin.x.rounded(), @@ -163,7 +163,7 @@ public extension UIImage { /// /// - Parameter color: color to fill image with. /// - Returns: UIImage filled with given color. - public func filled(withColor color: UIColor) -> UIImage { + func filled(withColor color: UIColor) -> UIImage { UIGraphicsBeginImageContextWithOptions(size, false, scale) color.setFill() guard let context = UIGraphicsGetCurrentContext() else { return self } @@ -173,7 +173,7 @@ public extension UIImage { context.setBlendMode(CGBlendMode.normal) let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) - guard let mask = self.cgImage else { return self } + guard let mask = cgImage else { return self } context.clip(to: rect, mask: mask) context.fill(rect) @@ -188,17 +188,17 @@ public extension UIImage { /// - color: color to tint image with. /// - blendMode: how to blend the tint /// - Returns: UIImage tinted with given color. - public func tint(_ color: UIColor, blendMode: CGBlendMode) -> UIImage { + func tint(_ color: UIColor, blendMode: CGBlendMode) -> UIImage { let drawRect = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height) UIGraphicsBeginImageContextWithOptions(size, false, scale) + defer { + UIGraphicsEndImageContext() + } let context = UIGraphicsGetCurrentContext() - context!.clip(to: drawRect, mask: cgImage!) color.setFill() - UIRectFill(drawRect) + context?.fill(drawRect) draw(in: drawRect, blendMode: blendMode, alpha: 1.0) - let tintedImage = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - return tintedImage! + return UIGraphicsGetImageFromCurrentImageContext()! } /// SwifterSwift: UIImage with rounded corners @@ -206,7 +206,7 @@ public extension UIImage { /// - Parameters: /// - radius: corner radius (optional), resulting image will be round if unspecified /// - Returns: UIImage with all corners rounded - public func withRoundedCorners(radius: CGFloat? = nil) -> UIImage? { + func withRoundedCorners(radius: CGFloat? = nil) -> UIImage? { let maxRadius = min(size.width, size.height) / 2 let cornerRadius: CGFloat if let radius = radius, radius > 0 && radius <= maxRadius { @@ -236,7 +236,7 @@ public extension UIImage { /// - Parameters: /// - color: image fill color. /// - size: image size. - public convenience init(color: UIColor, size: CGSize) { + convenience init(color: UIColor, size: CGSize) { UIGraphicsBeginImageContextWithOptions(size, false, 1) defer { @@ -255,4 +255,5 @@ public extension UIImage { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIImageViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIImageViewExtensions.swift similarity index 90% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIImageViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIImageViewExtensions.swift index 076692d..cc3c623 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIImageViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIImageViewExtensions.swift @@ -19,7 +19,7 @@ public extension UIImageView { /// - contentMode: imageView content mode (default is .scaleAspectFit). /// - placeHolder: optional placeholder image /// - completionHandler: optional completion handler to run when download finishs (default is nil). - public func download( + func download( from url: URL, contentMode: UIView.ContentMode = .scaleAspectFit, placeholder: UIImage? = nil, @@ -37,7 +37,7 @@ public extension UIImageView { completionHandler?(nil) return } - DispatchQueue.main.async { + DispatchQueue.main.async { [unowned self] in self.image = image completionHandler?(image) } @@ -47,7 +47,7 @@ public extension UIImageView { /// SwifterSwift: Make image view blurry /// /// - Parameter style: UIBlurEffectStyle (default is .light). - public func blur(withStyle style: UIBlurEffect.Style = .light) { + func blur(withStyle style: UIBlurEffect.Style = .light) { let blurEffect = UIBlurEffect(style: style) let blurEffectView = UIVisualEffectView(effect: blurEffect) blurEffectView.frame = bounds @@ -60,11 +60,12 @@ public extension UIImageView { /// /// - Parameter style: UIBlurEffectStyle (default is .light). /// - Returns: blurred version of self. - public func blurred(withStyle style: UIBlurEffect.Style = .light) -> UIImageView { + func blurred(withStyle style: UIBlurEffect.Style = .light) -> UIImageView { let imgView = self imgView.blur(withStyle: style) return imgView } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UILabelExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UILabelExtensions.swift similarity index 61% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UILabelExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UILabelExtensions.swift index 0f9d6d3..ef8d36a 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UILabelExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UILabelExtensions.swift @@ -13,13 +13,24 @@ import UIKit public extension UILabel { /// SwifterSwift: Initialize a UILabel with text - public convenience init(text: String?) { + convenience init(text: String?) { self.init() self.text = text } + /// SwifterSwift: Initialize a UILabel with a text and font style. + /// + /// - Parameters: + /// - text: the label's text. + /// - style: the text style of the label, used to determine which font should be used. + convenience init(text: String, style: UIFont.TextStyle) { + self.init() + font = UIFont.preferredFont(forTextStyle: style) + self.text = text + } + /// SwifterSwift: Required height for a label - public var requiredHeight: CGFloat { + var requiredHeight: CGFloat { let label = UILabel(frame: CGRect(x: 0, y: 0, width: frame.width, height: CGFloat.greatestFiniteMagnitude)) label.numberOfLines = 0 label.lineBreakMode = NSLineBreakMode.byWordWrapping @@ -31,4 +42,5 @@ public extension UILabel { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UILayoutPriorityExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UILayoutPriorityExtensions.swift similarity index 99% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UILayoutPriorityExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UILayoutPriorityExtensions.swift index 6bf58d7..77435b7 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UILayoutPriorityExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UILayoutPriorityExtensions.swift @@ -30,6 +30,7 @@ extension UILayoutPriority: ExpressibleByFloatLiteral, ExpressibleByIntegerLiter public init(integerLiteral value: Int) { self.init(rawValue: Float(value)) } + } #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationBarExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationBarExtensions.swift similarity index 87% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationBarExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationBarExtensions.swift index 38ae6f4..00551ec 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationBarExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationBarExtensions.swift @@ -17,7 +17,7 @@ public extension UINavigationBar { /// - Parameters: /// - font: title font /// - color: title text color (default is .black). - public func setTitleFont(_ font: UIFont, color: UIColor = .black) { + func setTitleFont(_ font: UIFont, color: UIColor = .black) { var attrs = [NSAttributedString.Key: Any]() attrs[.font] = font attrs[.foregroundColor] = color @@ -27,7 +27,7 @@ public extension UINavigationBar { /// SwifterSwift: Make navigation bar transparent. /// /// - Parameter tint: tint color (default is .white). - public func makeTransparent(withTint tint: UIColor = .white) { + func makeTransparent(withTint tint: UIColor = .white) { isTranslucent = true backgroundColor = .clear barTintColor = .clear @@ -42,7 +42,7 @@ public extension UINavigationBar { /// - Parameters: /// - background: backgound color /// - text: text color - public func setColors(background: UIColor, text: UIColor) { + func setColors(background: UIColor, text: UIColor) { isTranslucent = false backgroundColor = background barTintColor = background @@ -52,4 +52,5 @@ public extension UINavigationBar { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationControllerExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationControllerExtensions.swift similarity index 86% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationControllerExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationControllerExtensions.swift index 16a3775..e835185 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationControllerExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationControllerExtensions.swift @@ -17,7 +17,7 @@ public extension UINavigationController { /// - Parameters: /// - animated: Set this value to true to animate the transition (default is true). /// - completion: optional completion handler (default is nil). - public func popViewController(animated: Bool = true, _ completion: (() -> Void)? = nil) { + func popViewController(animated: Bool = true, _ completion: (() -> Void)? = nil) { // https://github.com/cotkjaer/UserInterface/blob/master/UserInterface/UIViewController.swift CATransaction.begin() CATransaction.setCompletionBlock(completion) @@ -30,7 +30,7 @@ public extension UINavigationController { /// - Parameters: /// - viewController: viewController to push. /// - completion: optional completion handler (default is nil). - public func pushViewController(_ viewController: UIViewController, completion: (() -> Void)? = nil) { + func pushViewController(_ viewController: UIViewController, completion: (() -> Void)? = nil) { // https://github.com/cotkjaer/UserInterface/blob/master/UserInterface/UIViewController.swift CATransaction.begin() CATransaction.setCompletionBlock(completion) @@ -41,7 +41,7 @@ public extension UINavigationController { /// SwifterSwift: Make navigation controller's navigation bar transparent. /// /// - Parameter tint: tint color (default is .white). - public func makeTransparent(withTint tint: UIColor = .white) { + func makeTransparent(withTint tint: UIColor = .white) { navigationBar.setBackgroundImage(UIImage(), for: .default) navigationBar.shadowImage = UIImage() navigationBar.isTranslucent = true @@ -50,4 +50,5 @@ public extension UINavigationController { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationItemExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationItemExtensions.swift similarity index 92% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationItemExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationItemExtensions.swift index e06393c..35e1fff 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UINavigationItemExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UINavigationItemExtensions.swift @@ -15,7 +15,7 @@ public extension UINavigationItem { /// SwifterSwift: Replace title label with an image in navigation item. /// /// - Parameter image: UIImage to replace title with. - public func replaceTitle(with image: UIImage) { + func replaceTitle(with image: UIImage) { let logoImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 30)) logoImageView.contentMode = .scaleAspectFit logoImageView.image = image @@ -23,4 +23,5 @@ public extension UINavigationItem { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIRefreshControlExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIRefreshControlExtensions.swift similarity index 79% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIRefreshControlExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIRefreshControlExtensions.swift index 4652d63..0fd0c8c 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIRefreshControlExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIRefreshControlExtensions.swift @@ -18,8 +18,8 @@ public extension UIRefreshControl { /// - tableView: UITableView instance, inside which the refresh control is contained. /// - animated: Boolean, indicates that is the content offset changing should be animated or not. /// - sendAction: Boolean, indicates that should it fire sendActions method for valueChanged UIControlEvents - public func beginRefreshing(in tableView: UITableView, animated: Bool, sendAction: Bool = false) { - //https://stackoverflow.com/questions/14718850/uirefreshcontrol-beginrefreshing-not-working-when-uitableviewcontroller-is-ins/14719658#14719658 + func beginRefreshing(in tableView: UITableView, animated: Bool, sendAction: Bool = false) { + // https://stackoverflow.com/questions/14718850/14719658#14719658 assert(superview == tableView, "Refresh control does not belong to the receiving table view") beginRefreshing() @@ -32,4 +32,5 @@ public extension UIRefreshControl { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIScrollViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIScrollViewExtensions.swift similarity index 96% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIScrollViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIScrollViewExtensions.swift index 3d3aa0b..cbf38a3 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIScrollViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIScrollViewExtensions.swift @@ -18,7 +18,7 @@ public extension UIScrollView { /// UITableView().snapshot /// /// - Returns: Snapshot as UIimage for rendered ScrollView - public var snapshot: UIImage? { + var snapshot: UIImage? { // Original Source: https://gist.github.com/thestoics/1204051 UIGraphicsBeginImageContextWithOptions(contentSize, false, 0) defer { @@ -31,5 +31,7 @@ public extension UIScrollView { frame = previousFrame return UIGraphicsGetImageFromCurrentImageContext() } + } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISearchBarExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISearchBarExtensions.swift similarity index 88% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISearchBarExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISearchBarExtensions.swift index e963749..11d2a81 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISearchBarExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISearchBarExtensions.swift @@ -13,7 +13,7 @@ import UIKit public extension UISearchBar { /// SwifterSwift: Text field inside search bar (if applicable). - public var textField: UITextField? { + var textField: UITextField? { let subViews = subviews.flatMap { $0.subviews } guard let textField = (subViews.filter { $0 is UITextField }).first as? UITextField else { return nil @@ -22,7 +22,7 @@ public extension UISearchBar { } /// SwifterSwift: Text with no spaces or new lines in beginning and end (if applicable). - public var trimmedText: String? { + var trimmedText: String? { return text?.trimmingCharacters(in: .whitespacesAndNewlines) } @@ -32,9 +32,10 @@ public extension UISearchBar { public extension UISearchBar { /// SwifterSwift: Clear text. - public func clear() { + func clear() { text = "" } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISegmentedControlExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISegmentedControlExtensions.swift similarity index 92% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISegmentedControlExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISegmentedControlExtensions.swift index a3c2a98..8427183 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISegmentedControlExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISegmentedControlExtensions.swift @@ -13,7 +13,7 @@ import UIKit public extension UISegmentedControl { /// SwifterSwift: Segments titles. - public var segmentTitles: [String] { + var segmentTitles: [String] { get { let range = 0.. Void)? = nil) { + func setValue(_ value: Float, animated: Bool = true, duration: TimeInterval = 1, completion: (() -> Void)? = nil) { if animated { UIView.animate(withDuration: duration, animations: { self.setValue(value, animated: true) @@ -33,4 +33,5 @@ public extension UISlider { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIStackViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIStackViewExtensions.swift similarity index 80% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIStackViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIStackViewExtensions.swift index e412d60..7cbcf6a 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIStackViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIStackViewExtensions.swift @@ -23,10 +23,13 @@ public extension UIStackView { /// - spacing: The distance in points between the adjacent edges of the stack view’s arranged views.(default: 0.0) /// - alignment: The alignment of the arranged subviews perpendicular to the stack view’s axis. (default: .fill) /// - distribution: The distribution of the arranged views along the stack view’s axis.(default: .fill) - public convenience init(arrangedSubviews: [UIView], axis: NSLayoutConstraint.Axis, - spacing: CGFloat = 0.0, - alignment: UIStackView.Alignment = .fill, - distribution: UIStackView.Distribution = .fill) { + convenience init( + arrangedSubviews: [UIView], + axis: NSLayoutConstraint.Axis, + spacing: CGFloat = 0.0, + alignment: UIStackView.Alignment = .fill, + distribution: UIStackView.Distribution = .fill) { + self.init(arrangedSubviews: arrangedSubviews) self.axis = axis self.spacing = spacing @@ -37,18 +40,19 @@ public extension UIStackView { /// SwifterSwift: Adds array of views to the end of the arrangedSubviews array. /// /// - Parameter views: views array. - public func addArrangedSubviews(_ views: [UIView]) { + func addArrangedSubviews(_ views: [UIView]) { for view in views { addArrangedSubview(view) } } /// SwifterSwift: Removes all views in stack’s array of arranged subviews. - public func removeArrangedSubviews() { + func removeArrangedSubviews() { for view in arrangedSubviews { removeArrangedSubview(view) } } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIStoryboardExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIStoryboardExtensions.swift similarity index 85% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIStoryboardExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIStoryboardExtensions.swift index d2ff28b..61a40ff 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIStoryboardExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIStoryboardExtensions.swift @@ -13,7 +13,7 @@ import UIKit public extension UIStoryboard { /// SwifterSwift: Get main storyboard for application - public static var main: UIStoryboard? { + static var main: UIStoryboard? { let bundle = Bundle.main guard let name = bundle.object(forInfoDictionaryKey: "UIMainStoryboardFile") as? String else { return nil } return UIStoryboard(name: name, bundle: bundle) @@ -23,9 +23,10 @@ public extension UIStoryboard { /// /// - Parameter name: UIViewController type /// - Returns: The view controller corresponding to specified class name - public func instantiateViewController(withClass name: T.Type) -> T? { + func instantiateViewController(withClass name: T.Type) -> T? { return instantiateViewController(withIdentifier: String(describing: name)) as? T } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISwitchExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISwitchExtensions.swift similarity index 89% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISwitchExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISwitchExtensions.swift index ff5a6bf..63192e1 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UISwitchExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UISwitchExtensions.swift @@ -15,9 +15,10 @@ public extension UISwitch { /// SwifterSwift: Toggle a UISwitch /// /// - Parameter animated: set true to animate the change (default is true) - public func toggle(animated: Bool = true) { + func toggle(animated: Bool = true) { setOn(!isOn, animated: animated) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITabBarExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITabBarExtensions.swift similarity index 99% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITabBarExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITabBarExtensions.swift index c8d2a69..56515be 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITabBarExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITabBarExtensions.swift @@ -19,7 +19,7 @@ public extension UITabBar { /// - selectedBackground: background color for selected tab. /// - item: icon tint color for items. /// - selectedItem: icon tint color for item. - public func setColors( + func setColors( background: UIColor? = nil, selectedBackground: UIColor? = nil, item: UIColor? = nil, @@ -87,4 +87,5 @@ public extension UITabBar { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITableViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITableViewExtensions.swift similarity index 76% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITableViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITableViewExtensions.swift index 1d44be3..9ea027a 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITableViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITableViewExtensions.swift @@ -13,12 +13,12 @@ import UIKit public extension UITableView { /// SwifterSwift: Index path of last row in tableView. - public var indexPathForLastRow: IndexPath? { + var indexPathForLastRow: IndexPath? { return indexPathForLastRow(inSection: lastSection) } /// SwifterSwift: Index of last section in tableView. - public var lastSection: Int { + var lastSection: Int { return numberOfSections > 0 ? numberOfSections - 1 : 0 } @@ -30,7 +30,7 @@ public extension UITableView { /// SwifterSwift: Number of all rows in all sections of tableView. /// /// - Returns: The count of all rows in the tableView. - public func numberOfRows() -> Int { + func numberOfRows() -> Int { var section = 0 var rowCount = 0 while section < numberOfSections { @@ -44,7 +44,7 @@ public extension UITableView { /// /// - Parameter section: section to get last row in. /// - Returns: optional last indexPath for last row in section (if applicable). - public func indexPathForLastRow(inSection section: Int) -> IndexPath? { + func indexPathForLastRow(inSection section: Int) -> IndexPath? { guard section >= 0 else { return nil } guard numberOfRows(inSection: section) > 0 else { return IndexPath(row: 0, section: section) @@ -55,7 +55,7 @@ public extension UITableView { /// Reload data with a completion handler. /// /// - Parameter completion: completion handler to run after reloadData finishes. - public func reloadData(_ completion: @escaping () -> Void) { + func reloadData(_ completion: @escaping () -> Void) { UIView.animate(withDuration: 0, animations: { self.reloadData() }, completion: { _ in @@ -64,19 +64,19 @@ public extension UITableView { } /// SwifterSwift: Remove TableFooterView. - public func removeTableFooterView() { + func removeTableFooterView() { tableFooterView = nil } /// SwifterSwift: Remove TableHeaderView. - public func removeTableHeaderView() { + func removeTableHeaderView() { tableHeaderView = nil } /// SwifterSwift: Scroll to bottom of TableView. /// /// - Parameter animated: set true to animate scroll (default is true). - public func scrollToBottom(animated: Bool = true) { + func scrollToBottom(animated: Bool = true) { let bottomOffset = CGPoint(x: 0, y: contentSize.height - bounds.size.height) setContentOffset(bottomOffset, animated: animated) } @@ -84,7 +84,7 @@ public extension UITableView { /// SwifterSwift: Scroll to top of TableView. /// /// - Parameter animated: set true to animate scroll (default is true). - public func scrollToTop(animated: Bool = true) { + func scrollToTop(animated: Bool = true) { setContentOffset(CGPoint.zero, animated: animated) } @@ -92,33 +92,33 @@ public extension UITableView { /// /// - Parameter name: UITableViewCell type /// - Returns: UITableViewCell object with associated class name. - public func dequeueReusableCell(withClass name: T.Type) -> T { + func dequeueReusableCell(withClass name: T.Type) -> T { guard let cell = dequeueReusableCell(withIdentifier: String(describing: name)) as? T else { - fatalError("Couldn't find UITableViewCell for \(String(describing: name))") + fatalError("Couldn't find UITableViewCell for \(String(describing: name)), make sure the cell is registered with table view") } return cell } - /// SwiferSwift: Dequeue reusable UITableViewCell using class name for indexPath + /// SwifterSwift: Dequeue reusable UITableViewCell using class name for indexPath /// /// - Parameters: /// - name: UITableViewCell type. /// - indexPath: location of cell in tableView. /// - Returns: UITableViewCell object with associated class name. - public func dequeueReusableCell(withClass name: T.Type, for indexPath: IndexPath) -> T { + func dequeueReusableCell(withClass name: T.Type, for indexPath: IndexPath) -> T { guard let cell = dequeueReusableCell(withIdentifier: String(describing: name), for: indexPath) as? T else { - fatalError("Couldn't find UITableViewCell for \(String(describing: name))") + fatalError("Couldn't find UITableViewCell for \(String(describing: name)), make sure the cell is registered with table view") } return cell } - /// SwiferSwift: Dequeue reusable UITableViewHeaderFooterView using class name + /// SwifterSwift: Dequeue reusable UITableViewHeaderFooterView using class name /// /// - Parameter name: UITableViewHeaderFooterView type /// - Returns: UITableViewHeaderFooterView object with associated class name. - public func dequeueReusableHeaderFooterView(withClass name: T.Type) -> T { + func dequeueReusableHeaderFooterView(withClass name: T.Type) -> T { guard let headerFooterView = dequeueReusableHeaderFooterView(withIdentifier: String(describing: name)) as? T else { - fatalError("Couldn't find UITableViewHeaderFooterView for \(String(describing: name))") + fatalError("Couldn't find UITableViewHeaderFooterView for \(String(describing: name)), make sure the view is registered with table view") } return headerFooterView } @@ -128,21 +128,21 @@ public extension UITableView { /// - Parameters: /// - nib: Nib file used to create the header or footer view. /// - name: UITableViewHeaderFooterView type. - public func register(nib: UINib?, withHeaderFooterViewClass name: T.Type) { + func register(nib: UINib?, withHeaderFooterViewClass name: T.Type) { register(nib, forHeaderFooterViewReuseIdentifier: String(describing: name)) } /// SwifterSwift: Register UITableViewHeaderFooterView using class name /// /// - Parameter name: UITableViewHeaderFooterView type - public func register(headerFooterViewClassWith name: T.Type) { + func register(headerFooterViewClassWith name: T.Type) { register(T.self, forHeaderFooterViewReuseIdentifier: String(describing: name)) } /// SwifterSwift: Register UITableViewCell using class name /// /// - Parameter name: UITableViewCell type - public func register(cellWithClass name: T.Type) { + func register(cellWithClass name: T.Type) { register(T.self, forCellReuseIdentifier: String(describing: name)) } @@ -151,7 +151,7 @@ public extension UITableView { /// - Parameters: /// - nib: Nib file used to create the tableView cell. /// - name: UITableViewCell type. - public func register(nib: UINib?, withCellClass name: T.Type) { + func register(nib: UINib?, withCellClass name: T.Type) { register(nib, forCellReuseIdentifier: String(describing: name)) } @@ -161,7 +161,7 @@ public extension UITableView { /// - Parameters: /// - name: UITableViewCell type. /// - bundleClass: Class in which the Bundle instance will be based on. - public func register(nibWithCellClass name: T.Type, at bundleClass: AnyClass? = nil) { + func register(nibWithCellClass name: T.Type, at bundleClass: AnyClass? = nil) { let identifier = String(describing: name) var bundle: Bundle? @@ -176,8 +176,8 @@ public extension UITableView { /// /// - Parameter indexPath: An IndexPath to check /// - Returns: Boolean value for valid or invalid IndexPath - public func isValidIndexPath(_ indexPath: IndexPath) -> Bool { - return indexPath.section < self.numberOfSections && indexPath.row < self.numberOfRows(inSection: indexPath.section) + func isValidIndexPath(_ indexPath: IndexPath) -> Bool { + return indexPath.section < numberOfSections && indexPath.row < numberOfRows(inSection: indexPath.section) } /// SwifterSwift: Safely scroll to possibly invalid IndexPath @@ -186,11 +186,12 @@ public extension UITableView { /// - indexPath: Target IndexPath to scroll to /// - scrollPosition: Scroll position /// - animated: Whether to animate or not - public func safeScrollToRow(at indexPath: IndexPath, at scrollPosition: UITableView.ScrollPosition, animated: Bool) { + func safeScrollToRow(at indexPath: IndexPath, at scrollPosition: UITableView.ScrollPosition, animated: Bool) { guard indexPath.section < numberOfSections else { return } guard indexPath.row < numberOfRows(inSection: indexPath.section) else { return } scrollToRow(at: indexPath, at: scrollPosition, animated: animated) } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITextFieldExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITextFieldExtensions.swift similarity index 84% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITextFieldExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITextFieldExtensions.swift index f41e5da..e4ff460 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITextFieldExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITextFieldExtensions.swift @@ -17,7 +17,7 @@ public extension UITextField { /// - emailAddress: UITextField is used to enter email addresses. /// - password: UITextField is used to enter passwords. /// - generic: UITextField is used to enter generic text. - public enum TextType { + enum TextType { /// UITextField is used to enter email addresses. case emailAddress @@ -34,7 +34,7 @@ public extension UITextField { public extension UITextField { /// SwifterSwift: Set textField for common text types. - public var textType: TextType { + var textType: TextType { get { if keyboardType == .emailAddress { return .emailAddress @@ -66,12 +66,12 @@ public extension UITextField { } /// SwifterSwift: Check if text field is empty. - public var isEmpty: Bool { + var isEmpty: Bool { return text?.isEmpty == true } /// SwifterSwift: Return text with no spaces or new lines in beginning and end. - public var trimmedText: String? { + var trimmedText: String? { return text?.trimmingCharacters(in: .whitespacesAndNewlines) } @@ -83,7 +83,7 @@ public extension UITextField { /// textField.text = "swifterswift" /// textField.hasValidEmail -> false /// - public var hasValidEmail: Bool { + var hasValidEmail: Bool { // http://stackoverflow.com/questions/25471114/how-to-validate-an-e-mail-address-in-swift return text!.range(of: "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}", options: String.CompareOptions.regularExpression, @@ -91,7 +91,7 @@ public extension UITextField { } /// SwifterSwift: Left view tint color. - @IBInspectable public var leftViewTintColor: UIColor? { + @IBInspectable var leftViewTintColor: UIColor? { get { guard let iconView = leftView as? UIImageView else { return nil } return iconView.tintColor @@ -104,7 +104,7 @@ public extension UITextField { } /// SwifterSwift: Right view tint color. - @IBInspectable public var rightViewTintColor: UIColor? { + @IBInspectable var rightViewTintColor: UIColor? { get { guard let iconView = rightView as? UIImageView else { return nil } return iconView.tintColor @@ -122,7 +122,7 @@ public extension UITextField { public extension UITextField { /// SwifterSwift: Clear text. - public func clear() { + func clear() { text = "" attributedText = NSAttributedString(string: "") } @@ -130,15 +130,15 @@ public extension UITextField { /// SwifterSwift: Set placeholder text color. /// /// - Parameter color: placeholder text color. - public func setPlaceHolderTextColor(_ color: UIColor) { + func setPlaceHolderTextColor(_ color: UIColor) { guard let holder = placeholder, !holder.isEmpty else { return } - self.attributedPlaceholder = NSAttributedString(string: holder, attributes: [.foregroundColor: color]) + attributedPlaceholder = NSAttributedString(string: holder, attributes: [.foregroundColor: color]) } /// SwifterSwift: Add padding to the left of the textfield rect. /// /// - Parameter padding: amount of padding to apply to the left of the textfield rect. - public func addPaddingLeft(_ padding: CGFloat) { + func addPaddingLeft(_ padding: CGFloat) { let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: padding, height: frame.height)) leftView = paddingView leftViewMode = .always @@ -149,12 +149,12 @@ public extension UITextField { /// - Parameters: /// - image: left image /// - padding: amount of padding between icon and the left of textfield - public func addPaddingLeftIcon(_ image: UIImage, padding: CGFloat) { + func addPaddingLeftIcon(_ image: UIImage, padding: CGFloat) { let imageView = UIImageView(image: image) imageView.contentMode = .center - self.leftView = imageView - self.leftView?.frame.size = CGSize(width: image.size.width + padding, height: image.size.height) - self.leftViewMode = UITextField.ViewMode.always + leftView = imageView + leftView?.frame.size = CGSize(width: image.size.width + padding, height: image.size.height) + leftViewMode = .always } } diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITextViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITextViewExtensions.swift similarity index 80% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITextViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITextViewExtensions.swift index 81d3160..3a4907a 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UITextViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UITextViewExtensions.swift @@ -13,27 +13,27 @@ import UIKit public extension UITextView { /// SwifterSwift: Clear text. - public func clear() { + func clear() { text = "" attributedText = NSAttributedString(string: "") } /// SwifterSwift: Scroll to the bottom of text view - public func scrollToBottom() { - // swiftlint:disable next legacy_constructor + func scrollToBottom() { + // swiftlint:disable:next legacy_constructor let range = NSMakeRange((text as NSString).length - 1, 1) scrollRangeToVisible(range) } /// SwifterSwift: Scroll to the top of text view - public func scrollToTop() { - // swiftlint:disable next legacy_constructor + func scrollToTop() { + // swiftlint:disable:next legacy_constructor let range = NSMakeRange(0, 1) scrollRangeToVisible(range) } /// SwifterSwift: Wrap to the content (Text / Attributed Text). - public func wrapToContent() { + func wrapToContent() { contentInset = UIEdgeInsets.zero scrollIndicatorInsets = UIEdgeInsets.zero contentOffset = CGPoint.zero @@ -43,4 +43,5 @@ public extension UITextView { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIViewControllerExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIViewControllerExtensions.swift similarity index 63% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIViewControllerExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIViewControllerExtensions.swift index db73699..45f1cd5 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIViewControllerExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIViewControllerExtensions.swift @@ -13,9 +13,9 @@ import UIKit public extension UIViewController { /// SwifterSwift: Check if ViewController is onscreen and not hidden. - public var isVisible: Bool { + var isVisible: Bool { // http://stackoverflow.com/questions/2777438/how-to-tell-if-uiviewcontrollers-view-is-visible - return self.isViewLoaded && view.window != nil + return isViewLoaded && view.window != nil } } @@ -28,19 +28,19 @@ public extension UIViewController { /// - Parameters: /// - name: notification name. /// - selector: selector to run with notified. - public func addNotificationObserver(name: Notification.Name, selector: Selector) { + func addNotificationObserver(name: Notification.Name, selector: Selector) { NotificationCenter.default.addObserver(self, selector: selector, name: name, object: nil) } /// SwifterSwift: Unassign as listener to notification. /// /// - Parameter name: notification name. - public func removeNotificationObserver(name: Notification.Name) { + func removeNotificationObserver(name: Notification.Name) { NotificationCenter.default.removeObserver(self, name: name, object: nil) } /// SwifterSwift: Unassign as listener from all notifications. - public func removeNotificationsObserver() { + func removeNotificationsObserver() { NotificationCenter.default.removeObserver(self) } @@ -53,7 +53,8 @@ public extension UIViewController { /// - highlightedButtonIndex: (Optional) index of the button from buttonTitles that should be highlighted. If this parameter is nil no button will be highlighted /// - completion: (Optional) completion block to be invoked when any one of the buttons is tapped. It passes the index of the tapped button as an argument /// - Returns: UIAlertController object (discardable). - @discardableResult public func showAlert(title: String?, message: String?, buttonTitles: [String]? = nil, highlightedButtonIndex: Int? = nil, completion: ((Int) -> Void)? = nil) -> UIAlertController { + @discardableResult + func showAlert(title: String?, message: String?, buttonTitles: [String]? = nil, highlightedButtonIndex: Int? = nil, completion: ((Int) -> Void)? = nil) -> UIAlertController { let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) var allButtons = buttonTitles ?? [String]() if allButtons.count == 0 { @@ -82,19 +83,48 @@ public extension UIViewController { /// - Parameters: /// - child: the view controller to add as a child /// - containerView: the containerView for the child viewcontroller's root view. - public func addChildViewController(_ child: UIViewController, toContainerView containerView: UIView) { + func addChildViewController(_ child: UIViewController, toContainerView containerView: UIView) { addChild(child) containerView.addSubview(child.view) child.didMove(toParent: self) } /// SwifterSwift: Helper method to remove a UIViewController from its parent. - public func removeViewAndControllerFromParentViewController() { + func removeViewAndControllerFromParentViewController() { guard parent != nil else { return } willMove(toParent: nil) removeFromParent() view.removeFromSuperview() } + + #if os(iOS) + /// SwifterSwift: Helper method to present a UIViewController as a popover. + /// + /// - Parameters: + /// - popoverContent: the view controller to add as a popover. + /// - sourcePoint: the point in which to anchor the popover. + /// - size: the size of the popover. Default uses the popover preferredContentSize. + /// - delegate: the popover's presentationController delegate. Default is nil. + /// - animated: Pass true to animate the presentation; otherwise, pass false. + /// - completion: The block to execute after the presentation finishes. Default is nil. + func presentPopover(_ popoverContent: UIViewController, sourcePoint: CGPoint, size: CGSize? = nil, delegate: UIPopoverPresentationControllerDelegate? = nil, animated: Bool = true, completion: (() -> Void)? = nil) { + popoverContent.modalPresentationStyle = .popover + + if let size = size { + popoverContent.preferredContentSize = size + } + + if let popoverPresentationVC = popoverContent.popoverPresentationController { + popoverPresentationVC.sourceView = view + popoverPresentationVC.sourceRect = CGRect(origin: sourcePoint, size: .zero) + popoverPresentationVC.delegate = delegate + } + + present(popoverContent, animated: animated, completion: completion) + } + #endif + } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIViewExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIViewExtensions.swift similarity index 83% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIViewExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIViewExtensions.swift index 8361dae..03fe4af 100755 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIViewExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIViewExtensions.swift @@ -16,7 +16,7 @@ public extension UIView { /// /// - horizontal: Shake left and right. /// - vertical: Shake up and down. - public enum ShakeDirection { + enum ShakeDirection { /// Shake left and right. case horizontal @@ -28,7 +28,7 @@ public extension UIView { /// /// - degrees: degrees. /// - radians: radians. - public enum AngleUnit { + enum AngleUnit { /// degrees. case degrees @@ -42,7 +42,7 @@ public extension UIView { /// - easeIn: easeIn animation. /// - easeOut: easeOut animation. /// - easeInOut: easeInOut animation. - public enum ShakeAnimationType { + enum ShakeAnimationType { /// linear animation. case linear @@ -62,7 +62,7 @@ public extension UIView { public extension UIView { /// SwifterSwift: Border color of view; also inspectable from Storyboard. - @IBInspectable public var borderColor: UIColor? { + @IBInspectable var borderColor: UIColor? { get { guard let color = layer.borderColor else { return nil } return UIColor(cgColor: color) @@ -79,7 +79,7 @@ public extension UIView { } /// SwifterSwift: Border width of view; also inspectable from Storyboard. - @IBInspectable public var borderWidth: CGFloat { + @IBInspectable var borderWidth: CGFloat { get { return layer.borderWidth } @@ -89,7 +89,7 @@ public extension UIView { } /// SwifterSwift: Corner radius of view; also inspectable from Storyboard. - @IBInspectable public var cornerRadius: CGFloat { + @IBInspectable var cornerRadius: CGFloat { get { return layer.cornerRadius } @@ -100,7 +100,7 @@ public extension UIView { } /// SwifterSwift: Height of view. - public var height: CGFloat { + var height: CGFloat { get { return frame.size.height } @@ -110,7 +110,7 @@ public extension UIView { } /// SwifterSwift: Check if view is in RTL format. - public var isRightToLeft: Bool { + var isRightToLeft: Bool { if #available(iOS 10.0, *, tvOS 10.0, *) { return effectiveUserInterfaceLayoutDirection == .rightToLeft } else { @@ -119,7 +119,7 @@ public extension UIView { } /// SwifterSwift: Take screenshot of view (if applicable). - public var screenshot: UIImage? { + var screenshot: UIImage? { UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, 0) defer { UIGraphicsEndImageContext() @@ -130,7 +130,7 @@ public extension UIView { } /// SwifterSwift: Shadow color of view; also inspectable from Storyboard. - @IBInspectable public var shadowColor: UIColor? { + @IBInspectable var shadowColor: UIColor? { get { guard let color = layer.shadowColor else { return nil } return UIColor(cgColor: color) @@ -141,7 +141,7 @@ public extension UIView { } /// SwifterSwift: Shadow offset of view; also inspectable from Storyboard. - @IBInspectable public var shadowOffset: CGSize { + @IBInspectable var shadowOffset: CGSize { get { return layer.shadowOffset } @@ -151,7 +151,7 @@ public extension UIView { } /// SwifterSwift: Shadow opacity of view; also inspectable from Storyboard. - @IBInspectable public var shadowOpacity: Float { + @IBInspectable var shadowOpacity: Float { get { return layer.shadowOpacity } @@ -161,7 +161,7 @@ public extension UIView { } /// SwifterSwift: Shadow radius of view; also inspectable from Storyboard. - @IBInspectable public var shadowRadius: CGFloat { + @IBInspectable var shadowRadius: CGFloat { get { return layer.shadowRadius } @@ -171,7 +171,7 @@ public extension UIView { } /// SwifterSwift: Size of view. - public var size: CGSize { + var size: CGSize { get { return frame.size } @@ -182,7 +182,7 @@ public extension UIView { } /// SwifterSwift: Get view's parent view controller - public var parentViewController: UIViewController? { + var parentViewController: UIViewController? { weak var parentResponder: UIResponder? = self while parentResponder != nil { parentResponder = parentResponder!.next @@ -194,7 +194,7 @@ public extension UIView { } /// SwifterSwift: Width of view. - public var width: CGFloat { + var width: CGFloat { get { return frame.size.width } @@ -203,9 +203,9 @@ public extension UIView { } } - // swiftlint:disable next identifier_name /// SwifterSwift: x origin of view. - public var x: CGFloat { + // swiftlint:disable:next identifier_name + var x: CGFloat { get { return frame.origin.x } @@ -214,9 +214,9 @@ public extension UIView { } } - // swiftlint:disable next identifier_name /// SwifterSwift: y origin of view. - public var y: CGFloat { + // swiftlint:disable:next identifier_name + var y: CGFloat { get { return frame.origin.y } @@ -231,17 +231,17 @@ public extension UIView { public extension UIView { /// SwifterSwift: Recursively find the first responder. - public func firstResponder() -> UIView? { + func firstResponder() -> UIView? { var views = [UIView](arrayLiteral: self) - var i = 0 + var index = 0 repeat { - let view = views[i] + let view = views[index] if view.isFirstResponder { return view } views.append(contentsOf: view.subviews) - i += 1 - } while i < views.count + index += 1 + } while index < views.count return nil } @@ -250,7 +250,7 @@ public extension UIView { /// - Parameters: /// - corners: array of corners to change (example: [.bottomLeft, .topRight]). /// - radius: radius for selected corners. - public func roundCorners(_ corners: UIRectCorner, radius: CGFloat) { + func roundCorners(_ corners: UIRectCorner, radius: CGFloat) { let maskPath = UIBezierPath( roundedRect: bounds, byRoundingCorners: corners, @@ -268,7 +268,7 @@ public extension UIView { /// - radius: shadow radius (default is 3). /// - offset: shadow offset (default is .zero). /// - opacity: shadow opacity (default is 0.5). - public func addShadow(ofColor color: UIColor = UIColor(red: 0.07, green: 0.47, blue: 0.57, alpha: 1.0), radius: CGFloat = 3, offset: CGSize = .zero, opacity: Float = 0.5) { + func addShadow(ofColor color: UIColor = UIColor(red: 0.07, green: 0.47, blue: 0.57, alpha: 1.0), radius: CGFloat = 3, offset: CGSize = .zero, opacity: Float = 0.5) { layer.shadowColor = color.cgColor layer.shadowOffset = offset layer.shadowRadius = radius @@ -279,8 +279,8 @@ public extension UIView { /// SwifterSwift: Add array of subviews to view. /// /// - Parameter subviews: array of subviews to add to self. - public func addSubviews(_ subviews: [UIView]) { - subviews.forEach({ self.addSubview($0) }) + func addSubviews(_ subviews: [UIView]) { + subviews.forEach { addSubview($0) } } /// SwifterSwift: Fade in view. @@ -288,7 +288,7 @@ public extension UIView { /// - Parameters: /// - duration: animation duration in seconds (default is 1 second). /// - completion: optional completion handler to run with animation finishes (default is nil) - public func fadeIn(duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { + func fadeIn(duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { if isHidden { isHidden = false } @@ -302,7 +302,7 @@ public extension UIView { /// - Parameters: /// - duration: animation duration in seconds (default is 1 second). /// - completion: optional completion handler to run with animation finishes (default is nil) - public func fadeOut(duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { + func fadeOut(duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { if isHidden { isHidden = false } @@ -317,17 +317,17 @@ public extension UIView { /// - name: nib name. /// - bundle: bundle of nib (default is nil). /// - Returns: optional UIView (if applicable). - public class func loadFromNib(named name: String, bundle: Bundle? = nil) -> UIView? { + class func loadFromNib(named name: String, bundle: Bundle? = nil) -> UIView? { return UINib(nibName: name, bundle: bundle).instantiate(withOwner: nil, options: nil)[0] as? UIView } /// SwifterSwift: Remove all subviews in view. - public func removeSubviews() { + func removeSubviews() { subviews.forEach({ $0.removeFromSuperview() }) } /// SwifterSwift: Remove all gesture recognizers from view. - public func removeGestureRecognizers() { + func removeGestureRecognizers() { gestureRecognizers?.forEach(removeGestureRecognizer) } @@ -338,7 +338,7 @@ public extension UIView { /// subviews. The view establishes a strong reference to the gesture recognizers. /// /// - Parameter gestureRecognizers: The array of gesture recognizers to be added to the view. - public func addGestureRecognizers(_ gestureRecognizers: [UIGestureRecognizer]) { + func addGestureRecognizers(_ gestureRecognizers: [UIGestureRecognizer]) { for recognizer in gestureRecognizers { addGestureRecognizer(recognizer) } @@ -349,7 +349,7 @@ public extension UIView { /// This method releases gestureRecognizers in addition to detaching them from the view. /// /// - Parameter gestureRecognizers: The array of gesture recognizers to be removed from the view. - public func removeGestureRecognizers(_ gestureRecognizers: [UIGestureRecognizer]) { + func removeGestureRecognizers(_ gestureRecognizers: [UIGestureRecognizer]) { for recognizer in gestureRecognizers { removeGestureRecognizer(recognizer) } @@ -363,7 +363,7 @@ public extension UIView { /// - animated: set true to animate rotation (default is true). /// - duration: animation duration in seconds (default is 1 second). /// - completion: optional completion handler to run with animation finishes (default is nil). - public func rotate(byAngle angle: CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { + func rotate(byAngle angle: CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { let angleWithType = (type == .degrees) ? .pi * angle / 180.0 : angle let aDuration = animated ? duration : 0 UIView.animate(withDuration: aDuration, delay: 0, options: .curveLinear, animations: { () -> Void in @@ -379,7 +379,7 @@ public extension UIView { /// - animated: set true to animate rotation (default is false). /// - duration: animation duration in seconds (default is 1 second). /// - completion: optional completion handler to run with animation finishes (default is nil). - public func rotate(toAngle angle: CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { + func rotate(toAngle angle: CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { let angleWithType = (type == .degrees) ? .pi * angle / 180.0 : angle let aDuration = animated ? duration : 0 UIView.animate(withDuration: aDuration, animations: { @@ -394,7 +394,7 @@ public extension UIView { /// - animated: set true to animate scaling (default is false). /// - duration: animation duration in seconds (default is 1 second). /// - completion: optional completion handler to run with animation finishes (default is nil). - public func scale(by offset: CGPoint, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { + func scale(by offset: CGPoint, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil) { if animated { UIView.animate(withDuration: duration, delay: 0, options: .curveLinear, animations: { () -> Void in self.transform = self.transform.scaledBy(x: offset.x, y: offset.y) @@ -412,7 +412,7 @@ public extension UIView { /// - duration: animation duration in seconds (default is 1 second). /// - animationType: shake animation type (default is .easeOut). /// - completion: optional completion handler to run with animation finishes (default is nil). - public func shake(direction: ShakeDirection = .horizontal, duration: TimeInterval = 1, animationType: ShakeAnimationType = .easeOut, completion:(() -> Void)? = nil) { + func shake(direction: ShakeDirection = .horizontal, duration: TimeInterval = 1, animationType: ShakeAnimationType = .easeOut, completion:(() -> Void)? = nil) { CATransaction.begin() let animation: CAKeyframeAnimation switch direction { @@ -443,7 +443,7 @@ public extension UIView { /// - Parameters: /// - withFormat: visual Format language /// - views: array of views which will be accessed starting with index 0 (example: [v0], [v1], [v2]..) - @available(iOS 9, *) public func addConstraints(withFormat: String, views: UIView...) { + @available(iOS 9, *) func addConstraints(withFormat: String, views: UIView...) { // https://videos.letsbuildthatapp.com/ var viewsDictionary: [String: UIView] = [:] for (index, view) in views.enumerated() { @@ -455,7 +455,8 @@ public extension UIView { } /// SwifterSwift: Anchor all sides of the view into it's superview. - @available(iOS 9, *) public func fillToSuperview() { + @available(iOS 9, *) + func fillToSuperview() { // https://videos.letsbuildthatapp.com/ translatesAutoresizingMaskIntoConstraints = false if let superview = superview { @@ -481,7 +482,9 @@ public extension UIView { /// - widthConstant: current view's width /// - heightConstant: current view's height /// - Returns: array of newly added constraints (if applicable). - @available(iOS 9, *) @discardableResult public func anchor( + @available(iOS 9, *) + @discardableResult + func anchor( top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, @@ -529,7 +532,8 @@ public extension UIView { /// SwifterSwift: Anchor center X into current view's superview with a constant margin value. /// /// - Parameter constant: constant of the anchor constraint (default is 0). - @available(iOS 9, *) public func anchorCenterXToSuperview(constant: CGFloat = 0) { + @available(iOS 9, *) + func anchorCenterXToSuperview(constant: CGFloat = 0) { // https://videos.letsbuildthatapp.com/ translatesAutoresizingMaskIntoConstraints = false if let anchor = superview?.centerXAnchor { @@ -540,7 +544,8 @@ public extension UIView { /// SwifterSwift: Anchor center Y into current view's superview with a constant margin value. /// /// - Parameter withConstant: constant of the anchor constraint (default is 0). - @available(iOS 9, *) public func anchorCenterYToSuperview(constant: CGFloat = 0) { + @available(iOS 9, *) + func anchorCenterYToSuperview(constant: CGFloat = 0) { // https://videos.letsbuildthatapp.com/ translatesAutoresizingMaskIntoConstraints = false if let anchor = superview?.centerYAnchor { @@ -549,11 +554,30 @@ public extension UIView { } /// SwifterSwift: Anchor center X and Y into current view's superview - @available(iOS 9, *) public func anchorCenterSuperview() { + @available(iOS 9, *) + func anchorCenterSuperview() { // https://videos.letsbuildthatapp.com/ anchorCenterXToSuperview() anchorCenterYToSuperview() } + /// SwifterSwift: Search all superviews until a view with the condition is found. + /// + /// - Parameter predicate: predicate to evaluate on superviews. + func ancestorView(where predicate: (UIView?) -> Bool) -> UIView? { + if predicate(superview) { + return superview + } + return superview?.ancestorView(where: predicate) + } + + /// SwifterSwift: Search all superviews until a view with this class is found. + /// + /// - Parameter name: class of the view to search. + func ancestorView(withClass name: T.Type) -> T? { + return ancestorView(where: { $0 is T }) as? T + } + } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIWindowExtensions.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIWindowExtensions.swift similarity index 91% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIWindowExtensions.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIWindowExtensions.swift index 621dffd..d1c4529 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/Extensions/UIKit/UIWindowExtensions.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Sources/SwifterSwift/UIKit/UIWindowExtensions.swift @@ -18,9 +18,9 @@ public extension UIWindow { /// - viewController: new view controller. /// - animated: set to true to animate view controller change (default is true). /// - duration: animation duration in seconds (default is 0.5). - /// - options: animataion options (default is .transitionFlipFromRight). + /// - options: animation options (default is .transitionFlipFromRight). /// - completion: optional completion handler called after view controller is changed. - public func switchRootViewController( + func switchRootViewController( to viewController: UIViewController, animated: Bool = true, duration: TimeInterval = 0.5, @@ -44,4 +44,5 @@ public extension UIWindow { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/DispatchTests/DispatchQueueExtensionsTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/DispatchTests/DispatchQueueExtensionsTests.swift new file mode 100644 index 0000000..b9efadc --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/DispatchTests/DispatchQueueExtensionsTests.swift @@ -0,0 +1,57 @@ +// +// DispatchQueueExtensionsTests.swift +// SwifterSwift +// +// Created by Quentin Jin on 2018/10/13. +// Copyright © 2018 SwifterSwift +// + +import XCTest +@testable import SwifterSwift + +#if canImport(Dispatch) +import Dispatch + +final class DispatchQueueExtensionsTests: XCTestCase { + + func testIsMainQueue() { + let expect = expectation(description: "isMainQueue") + let group = DispatchGroup() + + DispatchQueue.main.async(group: group) { + XCTAssertTrue(DispatchQueue.isMainQueue) + } + DispatchQueue.global().async(group: group) { + XCTAssertFalse(DispatchQueue.isMainQueue) + } + + group.notify(queue: .main) { + expect.fulfill() + } + + waitForExpectations(timeout: 0.5, handler: nil) + } + + func testIsCurrent() { + let expect = expectation(description: "isCurrent") + let group = DispatchGroup() + let queue = DispatchQueue.global() + + queue.async(group: group) { + XCTAssertTrue(DispatchQueue.isCurrent(queue)) + } + DispatchQueue.main.async(group: group) { + XCTAssertTrue(DispatchQueue.isCurrent(DispatchQueue.main)) + XCTAssertFalse(DispatchQueue.isCurrent(queue)) + } + + group.notify(queue: .main) { + expect.fulfill() + } + + waitForExpectations(timeout: 0.5, handler: nil) + } + +} + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/MapKitTests/MKMapViewTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/MapKitTests/MKMapViewTests.swift new file mode 100644 index 0000000..f588ef0 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/MapKitTests/MKMapViewTests.swift @@ -0,0 +1,43 @@ +// +// MKMapViewTests.swift +// SwifterSwift +// +// Created by Hannes Staffler on 24.01.19. +// Copyright © 2019 SwifterSwift +// + +import XCTest +@testable import SwifterSwift + +#if canImport(MapKit) +import MapKit +import struct CoreLocation.CLLocationCoordinate2D + +#if !os(watchOS) +@available(tvOS 9.2, *) +final class MKMapViewTests: XCTestCase { + + @available(iOS 11.0, tvOS 11.0, macOS 10.13, *) + func testRegister() { + let mapView = MKMapView() + + mapView.register(annotationViewWithClass: MKPinAnnotationView.self) + let annotationView = mapView.dequeueReusableAnnotationView(withClass: MKPinAnnotationView.self) + XCTAssertNotNil(annotationView) + } + + @available(iOS 11.0, tvOS 11.0, macOS 10.13, *) + func testRegisterAndDequeue() { + let mapView = MKMapView() + let annotation = MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0)) + + mapView.register(annotationViewWithClass: MKPinAnnotationView.self) + let annotationViewWithAnnotation = mapView.dequeueReusableAnnotationView(withClass: MKPinAnnotationView.self, for: annotation) + XCTAssertNotNil(annotationViewWithAnnotation) + } + +} + +#endif + +#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwiftStdlibTests/BidirectionalCollectionExtensionsTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwiftStdlibTests/BidirectionalCollectionExtensionsTests.swift new file mode 100644 index 0000000..8f5f3c5 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwiftStdlibTests/BidirectionalCollectionExtensionsTests.swift @@ -0,0 +1,21 @@ +// +// BidirectionalCollectionExtensionsTests.swift +// SwifterSwift +// +// Created by Quentin Jin on 2018/10/13. +// Copyright © 2018 SwifterSwift +// + +import XCTest +@testable import SwifterSwift + +final class BidirectionalCollectionExtensionsTests: XCTestCase { + + func testOffsetSubscript() { + let arr = [1, 2, 3, 4, 5] + XCTAssertEqual(arr[offset: 0], 1) + XCTAssertEqual(arr[offset: 4], 5) + XCTAssertEqual(arr[offset: -2], 4) + } + +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwiftStdlibTests/BinaryFloatingPointExtensionsTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwiftStdlibTests/BinaryFloatingPointExtensionsTests.swift new file mode 100644 index 0000000..a7fafeb --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwiftStdlibTests/BinaryFloatingPointExtensionsTests.swift @@ -0,0 +1,26 @@ +// +// BinaryFloatingPointExtensionsTests.swift +// SwifterSwift +// +// Created by Quentin Jin on 2018/10/13. +// Copyright © 2018 SwifterSwift +// + +import XCTest +@testable import SwifterSwift + +final class BinaryFloatingPointExtensionsTests: XCTestCase { + + func testRounded() { + let double = 3.1415927 + XCTAssertEqual(double.rounded(numberOfDecimalPlaces: 3, rule: .up), 3.142) + XCTAssertEqual(double.rounded(numberOfDecimalPlaces: 3, rule: .down), 3.141) + XCTAssertEqual(double.rounded(numberOfDecimalPlaces: 2, rule: .awayFromZero), 3.15) + + let float: Float = 3.1415927 + XCTAssertEqual(float.rounded(numberOfDecimalPlaces: 4, rule: .towardZero), 3.1415) + XCTAssertEqual(float.rounded(numberOfDecimalPlaces: -1, rule: .toNearestOrEven), 3) + XCTAssertEqual(float.rounded(numberOfDecimalPlaces: 0, rule: .toNearestOrAwayFromZero), 3) + } + +} diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwifterSwiftTests/SwifterSwiftTests.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwifterSwiftTests/SwifterSwiftTests.swift deleted file mode 100644 index 48ceba6..0000000 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/SwifterSwiftTests/SwifterSwiftTests.swift +++ /dev/null @@ -1,66 +0,0 @@ -// -// SwifterSwiftTests.swift -// SwifterSwift -// -// Created by Omar Albeik on 8/27/16. -// Copyright © 2016 SwifterSwift -// -import XCTest -@testable import SwifterSwift - -#if !os(Linux) - -final class SwifterSwiftTests: XCTestCase { - - func testTypeName() { - let number = 8 - XCTAssertEqual(SwifterSwift.typeName(for: number), "Int") - } - - func testDelay() { - var value = 0 - let done = expectation(description: "Execute block after delay") - - SwifterSwift.delay(milliseconds: 50, queue: DispatchQueue.main, completion: { - value = 1 - done.fulfill() - }) - - XCTAssertEqual(value, 0, "Does not get executed right away") - - waitForExpectations(timeout: 2, handler: { _ in - XCTAssertEqual(value, 1, "Value was incremented after delay") - }) - } - - func testDebounce() { - var value = 0 - let done = expectation(description: "Execute block after delay") - - func incrementor() { - value += 1 - } - - let debouncedIncrementor = SwifterSwift.debounce(millisecondsDelay: 20) { - incrementor() - } - - for index in 1...10 { - debouncedIncrementor() - if index == 10 { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.02) { - done.fulfill() - } - } - } - - XCTAssertEqual(value, 0, "Debounced function does not get executed right away") - - waitForExpectations(timeout: 2.5, handler: { _ in - XCTAssertEqual(value, 1, "Value was incremented only once") - }) - } - -} - -#endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIFontExtensionsTest.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIFontExtensionsTests.swift similarity index 98% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIFontExtensionsTest.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIFontExtensionsTests.swift index c21fbc8..70279d6 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIFontExtensionsTest.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIFontExtensionsTests.swift @@ -1,5 +1,5 @@ // -// UIFontExtensionsTest.swift +// UIFontExtensionsTests.swift // SwifterSwift // // Created by Benjamin Meyer on 9/16/17. @@ -55,4 +55,5 @@ final class UIFontExtension: XCTestCase { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIScrollViewExtensionsTest.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIScrollViewExtensionsTests.swift similarity index 93% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIScrollViewExtensionsTest.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIScrollViewExtensionsTests.swift index 011aa95..0739a18 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIScrollViewExtensionsTest.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIScrollViewExtensionsTests.swift @@ -1,5 +1,5 @@ // -// UIScrollViewExtensionsTest.swift +// UIScrollViewExtensionsTests.swift // SwifterSwift // // Created by camila oliveira on 22/04/18. @@ -22,5 +22,7 @@ final class UIScrollViewExtensionsTest: XCTestCase { let view = UIScrollView() XCTAssertNil(view.snapshot) } + } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIStackViewExtensionsTest.swift b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIStackViewExtensionsTests.swift similarity index 98% rename from Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIStackViewExtensionsTest.swift rename to Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIStackViewExtensionsTests.swift index f527bd9..fedda2c 100644 --- a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIStackViewExtensionsTest.swift +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/Tests/UIKitTests/UIStackViewExtensionsTests.swift @@ -1,5 +1,5 @@ // -// UIStackViewExtensionsTest.swift +// UIStackViewExtensionsTests.swift // SwifterSwift // // Created by Benjamin Meyer on 2/18/18. @@ -66,4 +66,5 @@ final class UIStackViewExtensionsTest: XCTestCase { } } + #endif diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/.env b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/.env new file mode 100644 index 0000000..0bf5b65 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/.env @@ -0,0 +1,8 @@ +NAME = SwifterSwift +PODSPEC = SwifterSwift.podspec +REPO_URL = https://github.com/swifterswift/swifterswift +RELEASE_BRANCH = master +SOURCES_PATH = Sources/* + +SLACK_URL = https://hooks.slack.com/services/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 +SLACK_CHANNEL = '#general' \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/Appfile b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/Appfile new file mode 100644 index 0000000..e69de29 diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/Fastfile b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/Fastfile new file mode 100644 index 0000000..9626cb6 --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/Fastfile @@ -0,0 +1,89 @@ +fastlane_require 'dotenv' +default_platform(:ios) + +platform :ios do + + desc 'Validate the project is ready for releasing' + lane :lint do + swiftlint + pod_lib_lint( + allow_warnings: true + ) + end + + desc 'Release a new version with a `patch` bump_type' + lane :patch do + release('patch') + end + + desc 'Release a new version with a `minor` bump_type' + lane :minor do + release('minor') + end + + desc 'Release a new version with a `major` bump_type' + lane :major do + release('major') + end + + def release(type) + branch = ENV['RELEASE_BRANCH'] + ensure_git_branch( + branch: branch + ) + new_changes = sh("git log #{last_git_tag}..HEAD | wc -l").strip! + if new_changes == '0' + UI.user_error!("No changes since last release: #{last_git_tag}, please add new features and try again!") + end + + lint + + podspec = ENV['PODSPEC'] + sources_path = ENV['SOURCES_PATH'] + + version = version_bump_podspec( + path: podspec, + bump_type: type + ) + + increment_version_number( + version_number: version + ) + + git_add( + path: [podspec, sources_path], + shell_escape: false + ) + + git_commit( + path: [podspec, sources_path], + message: "release: v#{version}" + ) + + add_git_tag( + tag: "#{version}" + ) + + push_to_git_remote + + pod_push( + path: podspec, + allow_warnings: true + ) + + author = last_git_commit[:author] + alert("*#{ENV['NAME']} v#{version} is here 🎉*", { :'Download URL' => ENV['REPO_URL'], :Author => author }) + end + + def alert(message, payload) + payload['Date'] = Time.new.to_s + slack( + slack_url: ENV['SLACK_URL'], + message: message, + channel: ENV['SLACK_CHANNEL'], + payload: payload, + default_payloads: [] + ) + end + +end \ No newline at end of file diff --git a/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/README.md b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/README.md new file mode 100644 index 0000000..2ab792b --- /dev/null +++ b/Source Code/HostsToolForMac/Carthage/Checkouts/SwifterSwift/fastlane/README.md @@ -0,0 +1,44 @@ +fastlane documentation +================ +# Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +``` +xcode-select --install +``` + +Install _fastlane_ using +``` +[sudo] gem install fastlane -NV +``` +or alternatively using `brew cask install fastlane` + +# Available Actions +## iOS +### ios lint +``` +fastlane ios lint +``` +Validate the project is ready for releasing +### ios patch +``` +fastlane ios patch +``` +Release a new version with a `patch` bump_type +### ios minor +``` +fastlane ios minor +``` +Release a new version with a `minor` bump_type +### ios major +``` +fastlane ios major +``` +Release a new version with a `major` bump_type + +---- + +This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. +More information about fastlane can be found on [fastlane.tools](https://fastlane.tools). +The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools).