diff --git a/.gitignore b/.gitignore index f09f53a..e6ad4ef 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ DerivedData .idea/ # Pods - for those of you who use CocoaPods Pods +.build diff --git a/.travis.yml b/.travis.yml index 0218ce1..4421088 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,4 @@ language: objective-c osx_image: xcode7 script: -- xctool -workspace Dollar.xcworkspace -scheme Dollar -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO clean build test -- xctool -workspace Dollar.xcworkspace -scheme Cent -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO clean build test - -before_install: - - brew update - - brew uninstall xctool && brew install --HEAD xctool \ No newline at end of file +- xctool -scheme Dollar -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO clean build test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 808596e..5c371a0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Contributing 1. Please fork this project -2. Implement new methods or changes in the `Dollar.swift` file in `Dollar` folder or changes in the appropriate extension file in `Cent` folder. -3. Write tests in `DollarTests.swift` or `CentTests.swift` file as needed. -4. Write appropriate comments in code and docs in the README.md +2. Implement new methods or changes in the `Dollar.swift` file in `Dollar` folder. +3. Write tests in `DollarTests.swift` file as needed. +4. Write appropriate comments in code and docs in the `README.md`. 5. Submit a pull request. diff --git a/Cent.podspec b/Cent.podspec deleted file mode 100644 index 985530c..0000000 --- a/Cent.podspec +++ /dev/null @@ -1,14 +0,0 @@ -Pod::Spec.new do |s| - s.name = "Cent" - s.version = "4.1.0" - s.summary = "Extension for common object types for Swift Language" - s.homepage = "https://github.com/ankurp/Dollar.swift" - s.license = { :type => "MIT", :file => "LICENSE" } - s.author = { "Ankur Patel" => "ankur.patel@ymail.com" } - s.source = { :git => "https://github.com/ankurp/Dollar.swift.git", :tag => "#{s.version}" } - s.source_files = "Cent/Cent/*.{h,swift}" - s.requires_arc = true - s.ios.deployment_target = "8.0" - s.osx.deployment_target = "10.10" - s.dependency "Dollar", "~> #{s.version}" -end diff --git a/Cent/Cent.xcodeproj/project.pbxproj b/Cent/Cent.xcodeproj/project.pbxproj deleted file mode 100644 index d696f1a..0000000 --- a/Cent/Cent.xcodeproj/project.pbxproj +++ /dev/null @@ -1,569 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 920C569C1962514E009D5129 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C569B1962514E009D5129 /* Dictionary.swift */; }; - 920C569E196251B5009D5129 /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C569D196251B5009D5129 /* Int.swift */; }; - 920C56A0196251D7009D5129 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C569F196251D7009D5129 /* String.swift */; }; - 920C56A419625401009D5129 /* Range.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C56A319625401009D5129 /* Range.swift */; }; - 920C56A8196255E6009D5129 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C56A7196255E6009D5129 /* Date.swift */; }; - 924F92E2195F8338003DBB60 /* Cent.h in Headers */ = {isa = PBXBuildFile; fileRef = 924F92E1195F8338003DBB60 /* Cent.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 924F92FB195F854B003DBB60 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924F92FA195F854B003DBB60 /* Array.swift */; }; - 925CB1EB1A3FE717004F1319 /* Cent.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 924F92DC195F8338003DBB60 /* Cent.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 925CB1FD1A3FEA08004F1319 /* Dollar.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 925CB1F71A3FE9ED004F1319 /* Dollar.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 9299310319F747AA00150D45 /* Cent.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 924F92DC195F8338003DBB60 /* Cent.framework */; }; - 9299310519F747B700150D45 /* CentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924F92EE195F8338003DBB60 /* CentTests.swift */; }; - 9299310819F747F600150D45 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924F92FA195F854B003DBB60 /* Array.swift */; }; - 9299310919F747F600150D45 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C56A7196255E6009D5129 /* Date.swift */; }; - 9299310A19F747F600150D45 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C569B1962514E009D5129 /* Dictionary.swift */; }; - 9299310B19F747F600150D45 /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C569D196251B5009D5129 /* Int.swift */; }; - 9299310C19F747F600150D45 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C569F196251D7009D5129 /* String.swift */; }; - 9299310D19F747F600150D45 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D0253F19F73F6B00A8F5E3 /* Regex.swift */; }; - 9299310E19F747F600150D45 /* Range.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920C56A319625401009D5129 /* Range.swift */; }; - 92D0254019F73F6B00A8F5E3 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D0253F19F73F6B00A8F5E3 /* Regex.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 925CB1F61A3FE9ED004F1319 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 925CB1F11A3FE9ED004F1319 /* Dollar.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 92E0D03C19467C67002ACC3D; - remoteInfo = Dollar; - }; - 925CB1F81A3FE9ED004F1319 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 925CB1F11A3FE9ED004F1319 /* Dollar.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 92E6686F19F09C6400BB4FB8; - remoteInfo = DollarTests; - }; - 925CB1FA1A3FE9F5004F1319 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 925CB1F11A3FE9ED004F1319 /* Dollar.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 92E0D03B19467C67002ACC3D; - remoteInfo = Dollar; - }; - 9299310619F747BC00150D45 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 924F92D3195F8338003DBB60 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 924F92DB195F8338003DBB60; - remoteInfo = Cent; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 925CB1EA1A3FE70E004F1319 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - 925CB1FD1A3FEA08004F1319 /* Dollar.framework in CopyFiles */, - 925CB1EB1A3FE717004F1319 /* Cent.framework in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 920C569B1962514E009D5129 /* Dictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = ""; }; - 920C569D196251B5009D5129 /* Int.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; - 920C569F196251D7009D5129 /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = ""; }; - 920C56A319625401009D5129 /* Range.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Range.swift; sourceTree = ""; }; - 920C56A7196255E6009D5129 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; - 924F92DC195F8338003DBB60 /* Cent.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Cent.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 924F92E0195F8338003DBB60 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 924F92E1195F8338003DBB60 /* Cent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Cent.h; sourceTree = ""; }; - 924F92ED195F8338003DBB60 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 924F92EE195F8338003DBB60 /* CentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CentTests.swift; sourceTree = ""; }; - 924F92FA195F854B003DBB60 /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; - 925CB1F11A3FE9ED004F1319 /* Dollar.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Dollar.xcodeproj; path = ../Dollar/Dollar.xcodeproj; sourceTree = ""; }; - 92D0253F19F73F6B00A8F5E3 /* Regex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Regex.swift; sourceTree = ""; }; - 92E6688119F0B89600BB4FB8 /* CentTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CentTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 924F92D8195F8338003DBB60 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 92E6687E19F0B89600BB4FB8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 9299310319F747AA00150D45 /* Cent.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 924F92D2195F8338003DBB60 = { - isa = PBXGroup; - children = ( - 925CB1F11A3FE9ED004F1319 /* Dollar.xcodeproj */, - 924F92DE195F8338003DBB60 /* Cent */, - 924F92EB195F8338003DBB60 /* CentTests */, - 924F92DD195F8338003DBB60 /* Products */, - ); - sourceTree = ""; - }; - 924F92DD195F8338003DBB60 /* Products */ = { - isa = PBXGroup; - children = ( - 924F92DC195F8338003DBB60 /* Cent.framework */, - 92E6688119F0B89600BB4FB8 /* CentTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 924F92DE195F8338003DBB60 /* Cent */ = { - isa = PBXGroup; - children = ( - 924F92E1195F8338003DBB60 /* Cent.h */, - 924F92FA195F854B003DBB60 /* Array.swift */, - 920C56A7196255E6009D5129 /* Date.swift */, - 920C569B1962514E009D5129 /* Dictionary.swift */, - 920C569D196251B5009D5129 /* Int.swift */, - 920C569F196251D7009D5129 /* String.swift */, - 92D0253F19F73F6B00A8F5E3 /* Regex.swift */, - 920C56A319625401009D5129 /* Range.swift */, - 924F92DF195F8338003DBB60 /* Supporting Files */, - ); - path = Cent; - sourceTree = ""; - }; - 924F92DF195F8338003DBB60 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 924F92E0195F8338003DBB60 /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 924F92EB195F8338003DBB60 /* CentTests */ = { - isa = PBXGroup; - children = ( - 924F92EE195F8338003DBB60 /* CentTests.swift */, - 924F92EC195F8338003DBB60 /* Supporting Files */, - ); - path = CentTests; - sourceTree = ""; - }; - 924F92EC195F8338003DBB60 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 924F92ED195F8338003DBB60 /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 925CB1F21A3FE9ED004F1319 /* Products */ = { - isa = PBXGroup; - children = ( - 925CB1F71A3FE9ED004F1319 /* Dollar.framework */, - 925CB1F91A3FE9ED004F1319 /* DollarTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 924F92D9195F8338003DBB60 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 924F92E2195F8338003DBB60 /* Cent.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 924F92DB195F8338003DBB60 /* Cent */ = { - isa = PBXNativeTarget; - buildConfigurationList = 924F92F2195F8338003DBB60 /* Build configuration list for PBXNativeTarget "Cent" */; - buildPhases = ( - 924F92D7195F8338003DBB60 /* Sources */, - 924F92D8195F8338003DBB60 /* Frameworks */, - 924F92D9195F8338003DBB60 /* Headers */, - 924F92DA195F8338003DBB60 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 925CB1FB1A3FE9F5004F1319 /* PBXTargetDependency */, - ); - name = Cent; - productName = Cent; - productReference = 924F92DC195F8338003DBB60 /* Cent.framework */; - productType = "com.apple.product-type.framework"; - }; - 92E6688019F0B89600BB4FB8 /* CentTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 92E6688719F0B89700BB4FB8 /* Build configuration list for PBXNativeTarget "CentTests" */; - buildPhases = ( - 92E6687D19F0B89600BB4FB8 /* Sources */, - 92E6687E19F0B89600BB4FB8 /* Frameworks */, - 92E6687F19F0B89600BB4FB8 /* Resources */, - 925CB1EA1A3FE70E004F1319 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - 9299310719F747BC00150D45 /* PBXTargetDependency */, - ); - name = CentTests; - productName = CentTests; - productReference = 92E6688119F0B89600BB4FB8 /* CentTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 924F92D3195F8338003DBB60 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftMigration = 0700; - LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; - ORGANIZATIONNAME = "Encore Dev Labs LLC"; - TargetAttributes = { - 924F92DB195F8338003DBB60 = { - CreatedOnToolsVersion = 6.0; - }; - 92E6688019F0B89600BB4FB8 = { - CreatedOnToolsVersion = 6.0.1; - }; - }; - }; - buildConfigurationList = 924F92D6195F8338003DBB60 /* Build configuration list for PBXProject "Cent" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 924F92D2195F8338003DBB60; - productRefGroup = 924F92DD195F8338003DBB60 /* Products */; - projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 925CB1F21A3FE9ED004F1319 /* Products */; - ProjectRef = 925CB1F11A3FE9ED004F1319 /* Dollar.xcodeproj */; - }, - ); - projectRoot = ""; - targets = ( - 924F92DB195F8338003DBB60 /* Cent */, - 92E6688019F0B89600BB4FB8 /* CentTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXReferenceProxy section */ - 925CB1F71A3FE9ED004F1319 /* Dollar.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = Dollar.framework; - remoteRef = 925CB1F61A3FE9ED004F1319 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 925CB1F91A3FE9ED004F1319 /* DollarTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = DollarTests.xctest; - remoteRef = 925CB1F81A3FE9ED004F1319 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - -/* Begin PBXResourcesBuildPhase section */ - 924F92DA195F8338003DBB60 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 92E6687F19F0B89600BB4FB8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 924F92D7195F8338003DBB60 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 920C569E196251B5009D5129 /* Int.swift in Sources */, - 920C56A8196255E6009D5129 /* Date.swift in Sources */, - 924F92FB195F854B003DBB60 /* Array.swift in Sources */, - 92D0254019F73F6B00A8F5E3 /* Regex.swift in Sources */, - 920C56A419625401009D5129 /* Range.swift in Sources */, - 920C56A0196251D7009D5129 /* String.swift in Sources */, - 920C569C1962514E009D5129 /* Dictionary.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 92E6687D19F0B89600BB4FB8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 9299310819F747F600150D45 /* Array.swift in Sources */, - 9299310919F747F600150D45 /* Date.swift in Sources */, - 9299310A19F747F600150D45 /* Dictionary.swift in Sources */, - 9299310B19F747F600150D45 /* Int.swift in Sources */, - 9299310C19F747F600150D45 /* String.swift in Sources */, - 9299310D19F747F600150D45 /* Regex.swift in Sources */, - 9299310E19F747F600150D45 /* Range.swift in Sources */, - 9299310519F747B700150D45 /* CentTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 925CB1FB1A3FE9F5004F1319 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = Dollar; - targetProxy = 925CB1FA1A3FE9F5004F1319 /* PBXContainerItemProxy */; - }; - 9299310719F747BC00150D45 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 924F92DB195F8338003DBB60 /* Cent */; - targetProxy = 9299310619F747BC00150D45 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 924F92F0195F8338003DBB60 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MACOSX_DEPLOYMENT_TARGET = 10.10; - METAL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 924F92F1195F8338003DBB60 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MACOSX_DEPLOYMENT_TARGET = 10.10; - METAL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx"; - VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - 924F92F3195F8338003DBB60 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_ENABLE_MODULES = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/Dollar-cnpzzqqzcseuvucrfghsizcweovz/Build/Products/Debug-iphoneos", - ); - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = Cent/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.encoredevlabs.${PRODUCT_NAME:rfc1034identifier}"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 924F92F4195F8338003DBB60 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_ENABLE_MODULES = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/Dollar-cnpzzqqzcseuvucrfghsizcweovz/Build/Products/Debug-iphoneos", - ); - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = Cent/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.encoredevlabs.${PRODUCT_NAME:rfc1034identifier}"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 92E6688819F0B89700BB4FB8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = CentTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = YES; - PRODUCT_BUNDLE_IDENTIFIER = "com.encoredevlabs.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 92E6688919F0B89700BB4FB8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - INFOPLIST_FILE = CentTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_BUNDLE_IDENTIFIER = "com.encoredevlabs.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 924F92D6195F8338003DBB60 /* Build configuration list for PBXProject "Cent" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 924F92F0195F8338003DBB60 /* Debug */, - 924F92F1195F8338003DBB60 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 924F92F2195F8338003DBB60 /* Build configuration list for PBXNativeTarget "Cent" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 924F92F3195F8338003DBB60 /* Debug */, - 924F92F4195F8338003DBB60 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 92E6688719F0B89700BB4FB8 /* Build configuration list for PBXNativeTarget "CentTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 92E6688819F0B89700BB4FB8 /* Debug */, - 92E6688919F0B89700BB4FB8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 924F92D3195F8338003DBB60 /* Project object */; -} diff --git a/Cent/Cent.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Cent/Cent.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index b0b3b9f..0000000 --- a/Cent/Cent.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Cent/Cent.xcodeproj/xcshareddata/xcschemes/Cent.xcscheme b/Cent/Cent.xcodeproj/xcshareddata/xcschemes/Cent.xcscheme deleted file mode 100644 index fdd1e42..0000000 --- a/Cent/Cent.xcodeproj/xcshareddata/xcschemes/Cent.xcscheme +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Cent/Cent/Array.swift b/Cent/Cent/Array.swift deleted file mode 100644 index a10758d..0000000 --- a/Cent/Cent/Array.swift +++ /dev/null @@ -1,243 +0,0 @@ -// -// Array.swift -// Cent -// -// Created by Ankur Patel on 6/28/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import Foundation -import Dollar - -public extension Array { - - /// Creates an array of elements from the specified indexes, or keys, of the collection. - /// Indexes may be specified as individual arguments or as arrays of indexes. - /// - /// :param array The array to source from - /// :param indexes Get elements from these indexes - /// :return New array with elements from the indexes specified. - func at(indexes: Int...) -> [Element] { - return $.at(self, indexes: indexes) - } - - /// Cycles through the array n times passing each element into the callback function - /// - /// :param times Number of times to cycle through the array - /// :param callback function to call with the element - func cycle(times: Int, callback: (Element) -> U) { - $.cycle(self, times, callback: callback) - } - - /// Cycles through the array indefinetly passing each element into the callback function - /// - /// :param callback function to call with the element - func cycle(callback: (Element) -> U) { - $.cycle(self, callback: callback) - } - - /// For each item in the array invoke the callback by passing the elem - /// - /// :param callback The callback function to invoke that take an element - func eachWithIndex(callback: (Int, Element) -> ()) -> [Element] { - for (index, elem) in self.enumerate() { - callback(index, elem) - } - return self - } - - /// For each item in the array invoke the callback by passing the elem along with the index - /// - /// :param callback The callback function to invoke - func each(callback: (Element) -> ()) -> [Element] { - self.eachWithIndex { (index, elem) -> () in - callback(elem) - } - return self - } - - /// For each item in the array that meets the when conditon, invoke the callback by passing the elem - /// - /// :param callback The callback function to invoke - /// :param when The condition to check each element against - /// :return the array itself - func each(when when: (Element) -> Bool, callback: (Element) -> ()) -> [Element] { - return $.each(self, when: when, callback: callback); - } - - /// Checks if the given callback returns true value for all items in the array. - /// - /// :param array The array to check. - /// :param callback Check whether element value is true or false. - /// :return First element from the array. - func every(callback: (Element) -> Bool) -> Bool { - return $.every(self, callback: callback) - } - - /// Get element from an array at the given index which can be negative - /// to find elements from the end of the array - /// - /// :param index Can be positive or negative to find from end of the array - /// :param orElse Default value to use if index is out of bounds - /// :return Element fetched from the array or the default value passed in orElse - func fetch(index: Int, orElse: Element? = .None) -> Element! { - return $.fetch(self, index, orElse: orElse) - } - - /// This method is like find except that it returns the index of the first element - /// that passes the callback check. - /// - /// :param array The array to search for the element in. - /// :param callback Function used to figure out whether element is the same. - /// :return First element's index from the array found using the callback. - func findIndex(callback: (Element) -> Bool) -> Int? { - return $.findIndex(self, callback: callback) - } - - /// This method is like findIndex except that it iterates over elements of the array - /// from right to left. - /// - /// :param array The array to search for the element in. - /// :param callback Function used to figure out whether element is the same. - /// :return Last element's index from the array found using the callback. - func findLastIndex(callback: (Element) -> Bool) -> Int? { - return $.findLastIndex(self, callback: callback) - } - - /// Gets the first element in the array. - /// - /// :param array The array to wrap. - /// :return First element from the array. - func first() -> Element? { - return $.first(self) - } - - /// Flattens the array - /// - /// :return Flatten array of elements - func flatten() -> [Element] { - return $.flatten(self) - } - - /// Get element at index - /// - /// :param index The index in the array - /// :return Element at that index - func get(index: Int) -> Element! { - return self.fetch(index) - } - - /// Gets all but the last element or last n elements of an array. - /// - /// :param array The array to source from. - /// :param numElements The number of elements to ignore in the end. - /// :return Array of initial values. - func initial(numElements: Int? = 1) -> [Element] { - return $.initial(self, numElements: numElements!) - } - - /// Gets the last element from the array. - /// - /// :param array The array to source from. - /// :return Last element from the array. - func last() -> Element? { - return $.last(self) - } - - /// The opposite of initial this method gets all but the first element or first n elements of an array. - /// - /// :param array The array to source from. - /// :param numElements The number of elements to exclude from the beginning. - /// :return The rest of the elements. - func rest(numElements: Int? = 1) -> [Element] { - return $.rest(self, numElements: numElements!) - } - - /// Retrieves the minimum value in an array. - /// - /// :param array The array to source from. - /// :return Minimum value from array. - func min() -> T? { - return $.min(map { $0 as! T }) - } - - /// Retrieves the maximum value in an array. - /// - /// :param array The array to source from. - /// :return Maximum element in array. - func max() -> T? { - return $.max(map { $0 as! T }) - } - - /// Gets the index at which the first occurrence of value is found. - /// - /// :param value Value whose index needs to be found. - /// :return Index of the element otherwise returns nil if not found. - func indexOf(value: T) -> Int? { - return $.indexOf(map { $0 as! T }, value: value) - } - - /// Remove element from array - /// - /// :param value Value that is to be removed from array - /// :return Element at that index - mutating func remove(value: T) -> T? { - if let index = $.indexOf(map { $0 as! T }, value: value) { - return (removeAtIndex(index) as? T) - } else { - return .None - } - } - - /// Checks if a given value is present in the array. - /// - /// :param value The value to check. - /// :return Whether value is in the array. - func contains(value: T) -> Bool { - return $.contains(map { $0 as! T }, value: value) - } - -} - -extension Array { - - /// Return the result of repeatedly calling `combine` with an accumulated value initialized - /// to `initial` on each element of `self`, in turn with a corresponding index. - /// - /// :param initial the value to be accumulated - /// :param combine the combiner with the result, index, and current element - /// :return combined result - func reduceWithIndex(initial: T, @noescape combine: (T, Int, Array.Generator.Element) throws -> T) rethrows -> T { - var result = initial - for (index, element) in self.enumerate() { - result = try combine(result, index, element) - } - return result - } - -} - -/// Overloaded operator to appends another array to an array -/// -/// :return array with the element appended in the end -public func <<(inout left: [T], right: [T]) -> [T] { - left += right - return left -} - -/// Overloaded operator to append element to an array -/// -/// :return array with the element appended in the end -public func <<(inout array: [T], elem: T) -> [T] { - array.append(elem) - return array -} - -/// Overloaded operator to remove elements from first array -/// -/// :return array with the elements from second array removed -public func -(left: [T], right: [T]) -> [T] { - return $.difference(left, right) -} - - diff --git a/Cent/Cent/Cent.h b/Cent/Cent/Cent.h deleted file mode 100644 index 3ca1d45..0000000 --- a/Cent/Cent/Cent.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// Cent.h -// Cent -// -// Created by Ankur Patel on 6/28/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -#import - -//! Project version number for Cent. -FOUNDATION_EXPORT double CentVersionNumber; - -//! Project version string for Cent. -FOUNDATION_EXPORT const unsigned char CentVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/Cent/Cent/Date.swift b/Cent/Cent/Date.swift deleted file mode 100644 index cdad64a..0000000 --- a/Cent/Cent/Date.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// Date.swift -// Cent -// -// Created by Ankur Patel on 6/30/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import Foundation - -public extension NSDate { - - /// Returns a new Date given the year month and day - /// - /// :param year - /// :param month - /// :param day - /// :return Date - public class func from(year year: Int, month: Int, day: Int) -> NSDate? { - let c = NSDateComponents() - c.year = year - c.month = month - c.day = day - - if let gregorian = NSCalendar(identifier: NSCalendarIdentifierGregorian) { - return gregorian.dateFromComponents(c) - } else { - return .None - } - } - - /// Returns a new Date given the unix timestamp - /// - /// :param unix timestamp - /// :return Date - public class func from(unix unix: Double) -> NSDate { - return NSDate(timeIntervalSince1970: unix) - } - - /// Parses the date based on the format and return a new Date - /// - /// :param dateStr String version of the date - /// :param format By default it is year month day - /// :return Date - public class func parse(dateStr: String, format: String = "yyyy-MM-dd") -> NSDate { - let dateFmt = NSDateFormatter() - dateFmt.timeZone = NSTimeZone.defaultTimeZone() - dateFmt.dateFormat = format - return dateFmt.dateFromString(dateStr)! - } - - /// Returns the unix timestamp of the date passed in or - /// the current unix timestamp - /// - /// :param date - /// :return Double - public class func unix(date: NSDate = NSDate()) -> Double { - return date.timeIntervalSince1970 as Double - } -} - -public typealias Date = NSDate diff --git a/Cent/Cent/Dictionary.swift b/Cent/Cent/Dictionary.swift deleted file mode 100644 index f6cb51d..0000000 --- a/Cent/Cent/Dictionary.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// Dictionary.swift -// Cent -// -// Created by Ankur Patel on 6/30/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import Foundation -import Dollar - -public extension Dictionary { - /// Merges the dictionary with dictionaries passed. The latter dictionaries will override - /// values of the keys that are already set - /// - /// :param dictionaries A comma seperated list of dictionaries - mutating func merge(dictionaries: Dictionary...) { - for dict in dictionaries { - for (key, value) in dict { - self.updateValue(value as! Value, forKey: key as! Key) - } - } - } -} diff --git a/Cent/Cent/Int.swift b/Cent/Cent/Int.swift deleted file mode 100644 index a1d6a13..0000000 --- a/Cent/Cent/Int.swift +++ /dev/null @@ -1,274 +0,0 @@ -// -// Int.swift -// Cent -// -// Created by Ankur Patel on 6/30/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import Foundation -import Dollar - -public extension Int { - - /// Invoke a callback n times - /// - /// :param callback The function to invoke that accepts the index - public func times(callback: (Int) -> ()) { - (0.. ()) { - self.times { (index: Int) -> () in - function() - } - } - - - /// Check if it is even - /// - /// :return Bool whether int is even - public var isEven: Bool { - get { - return self % 2 == 0 - } - } - - /// Check if it is odd - /// - /// :return Bool whether int is odd - public var isOdd: Bool { - get { - return self % 2 == 1 - } - } - - /// Get ASCII character from integer - /// - /// :return Character represented for the given integer - public var char: Character { - get { - return Character(UnicodeScalar(self)) - } - } - - /// Splits the int into array of digits - /// - /// :return Bool whether int is odd - public func digits() -> [Int] { - var digits: [Int] = [] - var selfCopy = self - while selfCopy > 0 { - digits << (selfCopy % 10) - selfCopy = (selfCopy / 10) - } - return Array(digits.reverse()) - } - - /// Get the next int - /// - /// :return next int - public func next() -> Int { - return self + 1 - } - - /// Get the previous int - /// - /// :return previous int - public func prev() -> Int { - return self - 1 - } - - /// Invoke the callback from int up to and including limit - /// - /// :params limit the max value to iterate upto - /// :params callback to invoke - public func upTo(limit: Int, callback: () -> ()) { - (self...limit).each { callback() } - } - - /// Invoke the callback from int up to and including limit passing the index - /// - /// :params limit the max value to iterate upto - /// :params callback to invoke - public func upTo(limit: Int, callback: (Int) -> ()) { - (self...limit).eachWithIndex { callback($0) } - } - - /// Invoke the callback from int down to and including limit - /// - /// :params limit the min value to iterate upto - /// :params callback to invoke - public func downTo(limit: Int, callback: () -> ()) { - var selfCopy = self - while selfCopy-- >= limit { - callback() - } - } - - /// Invoke the callback from int down to and including limit passing the index - /// - /// :params limit the min value to iterate upto - /// :params callback to invoke - public func downTo(limit: Int, callback: (Int) -> ()) { - var selfCopy = self - while selfCopy >= limit { - callback(selfCopy--) - } - } - - /// GCD metod return greatest common denominator with number passed - /// - /// :param number - /// :return Greatest common denominator - public func gcd(n: Int) -> Int { - return $.gcd(self, n) - } - - /// LCM method return least common multiple with number passed - /// - /// :param number - /// :return Least common multiple - public func lcm(n: Int) -> Int { - return $.lcm(self, n) - } - - /// Returns random number from 0 upto but not including value of integer - /// - /// :return Random number - public func random() -> Int { - return $.random(self) - } - - /// Returns Factorial of integer - /// - /// :return factorial - public func factorial() -> Int { - return $.factorial(self) - } - - /// Returns true if i is in closed interval - /// - /// :param i to check if it is in interval - /// :param interval to check in - /// :return true if it is in interval otherwise false - public func isIn(interval: ClosedInterval) -> Bool { - return $.it(self, isIn: interval) - } - - /// Returns true if i is in half open interval - /// - /// :param i to check if it is in interval - /// :param interval to check in - /// :return true if it is in interval otherwise false - public func isIn(interval: HalfOpenInterval) -> Bool { - return $.it(self, isIn: interval) - } - - /// Returns true if i is in range - /// - /// :param i to check if it is in range - /// :param interval to check in - /// :return true if it is in interval otherwise false - public func isIn(interval: Range) -> Bool { - return $.it(self, isIn: interval) - } - - private func mathForUnit(unit: NSCalendarUnit) -> CalendarMath { - return CalendarMath(unit: unit, value: self) - } - - var seconds: CalendarMath { - return mathForUnit(.Second) - } - - var second: CalendarMath { - return seconds - } - - var minutes: CalendarMath { - return mathForUnit(.Minute) - } - - var minute: CalendarMath { - return minutes - } - - var hours: CalendarMath { - return mathForUnit(.Hour) - } - - var hour: CalendarMath { - return hours - } - - var days: CalendarMath { - return mathForUnit(.Day) - } - - var day: CalendarMath { - return days - } - - var weeks: CalendarMath { - return mathForUnit(.WeekOfYear) - } - - var week: CalendarMath { - return weeks - } - - var months: CalendarMath { - return mathForUnit(.Month) - } - - var month: CalendarMath { - return months - } - - var years: CalendarMath { - return mathForUnit(.Year) - } - - var year: CalendarMath { - return years - } - - struct CalendarMath { - private let unit: NSCalendarUnit - private let value: Int - private var calendar: NSCalendar { - return NSCalendar.autoupdatingCurrentCalendar() - } - - private init(unit: NSCalendarUnit, value: Int) { - self.unit = unit - self.value = value - } - - private func generateComponents(modifer: (Int) -> (Int) = (+)) -> NSDateComponents { - let components = NSDateComponents() - components.setValue(modifer(value), forComponent: unit) - return components - } - - public func from(date: NSDate) -> NSDate? { - return calendar.dateByAddingComponents(generateComponents(), toDate: date, options: []) - } - - public var fromNow: NSDate? { - return from(NSDate()) - } - - public func before(date: NSDate) -> NSDate? { - return calendar.dateByAddingComponents(generateComponents(-), toDate: date, options: []) - } - - public var ago: NSDate? { - return before(NSDate()) - } - } -} diff --git a/Cent/Cent/Range.swift b/Cent/Cent/Range.swift deleted file mode 100644 index f647a84..0000000 --- a/Cent/Cent/Range.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// Range.swift -// Cent -// -// Created by Ankur Patel on 6/30/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import Foundation -import Dollar - -public extension Range { - - /// For each index in the range invoke the callback by passing the item in range - /// - /// :param callback The callback function to invoke that take an element - func eachWithIndex(callback: (Element) -> ()) { - for index in self { - callback(index) - } - } - - /// For each index in the range invoke the callback - /// - /// :param callback The callback function to invoke - func each(callback: () -> ()) { - self.eachWithIndex { (T) -> () in - callback() - } - } - -} - -public func ==(left: Range, right: Range) -> Bool { - return left.startIndex == right.startIndex && left.endIndex == right.endIndex -} diff --git a/Cent/Cent/Regex.swift b/Cent/Cent/Regex.swift deleted file mode 100644 index 50b2c3b..0000000 --- a/Cent/Cent/Regex.swift +++ /dev/null @@ -1,116 +0,0 @@ -// -// Regex.swift -// Cent -// -// Created by Ankur Patel on 10/21/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import Foundation -import Dollar - -let RegexEscapePattern = "[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]" -let RegexPatternRegex = Regex(RegexEscapePattern) - -public class Regex { - - let expression: NSRegularExpression - let pattern: String - - public init(_ pattern: String) { - self.pattern = pattern - self.expression = try! NSRegularExpression(pattern: pattern, options: .CaseInsensitive) - } - - public func matches(testStr: String) -> [AnyObject] { - let matches = self.expression.matchesInString(testStr, options: [], range:NSMakeRange(0, testStr.characters.count)) - return matches - } - - public func rangeOfFirstMatch(testStr: String) -> NSRange { - return self.expression.rangeOfFirstMatchInString(testStr, options: [], range:NSMakeRange(0, testStr.characters.count)) - } - - public func test(testStr: String) -> Bool { - let matches = self.matches(testStr) - return matches.count > 0 - } - - public class func escapeStr(str: String) -> String { - let matches = RegexPatternRegex.matches(str) - var charArr = [Character](str.characters) - var strBuilder = [Character]() - var i = 0 - for match in matches { - let range = match.range - while i < range.location + range.length { - if i == range.location { - strBuilder << "\\" - } - strBuilder << charArr[i++] - } - } - while i < charArr.count { - strBuilder << charArr[i++] - } - return String(strBuilder) - } -} - -/// Useful regex patterns (mapped from lodash) -struct RegexHelper { - - /// Unicode character classes - static let astralRange = "\\ud800-\\udfff" - static let comboRange = "\\u0300-\\u036f\\ufe20-\\ufe23" - static let dingbatRange = "\\u2700-\\u27bf" - static let lowerRange = "a-z\\xdf-\\xf6\\xf8-\\xff" - static let mathOpRange = "\\xac\\xb1\\xd7\\xf7" - static let nonCharRange = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf" - static let quoteRange = "\\u2018\\u2019\\u201c\\u201d" - static let spaceRange = "\\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000" - static let upperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde" - static let varRange = "\\ufe0e\\ufe0f" - static let breakRange = mathOpRange + nonCharRange + quoteRange + spaceRange - - /// Unicode capture groups - static let astral = "[" + astralRange + "]" - static let breakGroup = "[" + breakRange + "]" - static let combo = "[" + comboRange + "]" - static let digits = "\\d+" - static let dingbat = "[" + dingbatRange + "]" - static let lower = "[" + lowerRange + "]" - static let misc = "[^" + astralRange + breakRange + digits + dingbatRange + lowerRange + upperRange + "]" - static let modifier = "(?:\\ud83c[\\udffb-\\udfff])" - static let nonAstral = "[^" + astralRange + "]" - static let regional = "(?:\\ud83c[\\udde6-\\uddff]){2}" - static let surrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]" - static let upper = "[" + upperRange + "]" - static let ZWJ = "\\u200d" - - /// Unicode regex composers - static let lowerMisc = "(?:" + lower + "|" + misc + ")" - static let upperMisc = "(?:" + upper + "|" + misc + ")" - static let optMod = modifier + "?" - static let optVar = "[" + varRange + "]" - static let optJoin = "(?:" + ZWJ + "(?:" + [nonAstral, regional, surrPair].joinWithSeparator("|") + ")" + optVar + optMod + ")*" - static let seq = optVar + optMod + optJoin - static let emoji = "(?:" + [dingbat, regional, surrPair].joinWithSeparator("|") + ")" + seq - static let symbol = "(?:" + [nonAstral + combo + "?", combo, regional, surrPair, astral].joinWithSeparator("|") + ")" - - /// Match non-compound words composed of alphanumeric characters - static let basicWord = "[a-zA-Z0-9]+" - - /// Match complex or compound words - static let complexWord = [ - upper + "?" + lower + "+(?=" + [breakGroup, upper, "$"].joinWithSeparator("|") + ")", - upperMisc + "+(?=" + [breakGroup, upper + lowerMisc, "$"].joinWithSeparator("|") + ")", - upper + "?" + lowerMisc + "+", - digits + "(?:" + lowerMisc + "+)?", - emoji - ].joinWithSeparator("|") - - /// Detect strings that need a more robust regexp to match words - static let hasComplexWord = "[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]" - -} diff --git a/Cent/Cent/String.swift b/Cent/Cent/String.swift deleted file mode 100644 index e625aa0..0000000 --- a/Cent/Cent/String.swift +++ /dev/null @@ -1,223 +0,0 @@ -// -// String.swift -// Cent -// -// Created by Ankur Patel on 6/30/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import Foundation -import Dollar - -public extension String { - - public var length: Int { - get { - return self.characters.count - } - } - - public var camelCase: String { - get { - return self.deburr().words().reduceWithIndex("") { (result, index, word) -> String in - let lowered = word.lowercaseString - return result + (index > 0 ? lowered.capitalizedString : lowered) - } - } - } - - public var kebabCase: String { - get { - return self.deburr().words().reduceWithIndex("", combine: { (result, index, word) -> String in - return result + (index > 0 ? "-" : "") + word.lowercaseString - }) - } - } - - public var snakeCase: String { - get { - return self.deburr().words().reduceWithIndex("", combine: { (result, index, word) -> String in - return result + (index > 0 ? "_" : "") + word.lowercaseString - }) - } - } - - public var startCase: String { - get { - return self.deburr().words().reduceWithIndex("", combine: { (result, index, word) -> String in - return result + (index > 0 ? " " : "") + word.capitalizedString - }) - } - } - - /// Get character at a subscript - /// - /// :param i Index for which the character is returned - /// :return Character at index i - public subscript(i: Int) -> Character? { - if let char = Array(self.characters).get(i) { - return char - } - return .None - } - - /// Get character at a subscript - /// - /// :param i Index for which the character is returned - /// :return Character at index i - public subscript(pattern: String) -> String? { - if let range = Regex(pattern).rangeOfFirstMatch(self).toRange() { - return self[range] - } - return .None - } - - /// Get substring using subscript notation and by passing a range - /// - /// :param range The range from which to start and end the substring - /// :return Substring - public subscript(range: Range) -> String { - let start = startIndex.advancedBy(range.startIndex) - let end = startIndex.advancedBy(range.endIndex) - return self.substringWithRange(Range(start: start, end: end)) - } - - /// Get the start index of Character - /// - /// :return start index of .None if not found - public func indexOf(char: Character) -> Int? { - return self.indexOf(char.description) - } - - /// Get the start index of string - /// - /// :return start index of .None if not found - public func indexOf(str: String) -> Int? { - return self.indexOfRegex(Regex.escapeStr(str)) - } - - /// Get the start index of regex pattern - /// - /// :return start index of .None if not found - public func indexOfRegex(pattern: String) -> Int? { - if let range = Regex(pattern).rangeOfFirstMatch(self).toRange() { - return range.startIndex - } - return .None - } - - /// Get an array from string split using the delimiter character - /// - /// :return Array of strings after spliting - public func split(delimiter: Character) -> [String] { - return self.componentsSeparatedByString(String(delimiter)) - } - - /// Remove leading whitespace characters - /// - /// :return String without leading whitespace - public func lstrip() -> String { - return self["[^\\s]+.*$"]! - } - - /// Remove trailing whitespace characters - /// - /// :return String without trailing whitespace - public func rstrip() -> String { - return self["^.*[^\\s]+"]! - } - - /// Remove leading and trailing whitespace characters - /// - /// :return String without leading or trailing whitespace - public func strip() -> String { - return self.stringByTrimmingCharactersInSet(.whitespaceCharacterSet()) - } -} - -extension String { - - /// Split string into array of 'words' - func words() -> [String] { - let hasComplexWordRegex = try! NSRegularExpression(pattern: RegexHelper.hasComplexWord, options: []) - let wordRange = NSMakeRange(0, self.characters.count) - let hasComplexWord = hasComplexWordRegex.rangeOfFirstMatchInString(self, options: [], range: wordRange) - let wordPattern = hasComplexWord.length > 0 ? RegexHelper.complexWord : RegexHelper.basicWord - let wordRegex = try! NSRegularExpression(pattern: wordPattern, options: []) - let matches = wordRegex.matchesInString(self, options: [], range: wordRange) - let words = matches.map { (result: NSTextCheckingResult) -> String in - if let range = self.rangeFromNSRange(result.range) { - return self.substringWithRange(range) - } else { - return "" - } - } - return words - } - - /// Strip string of accents and diacritics - func deburr() -> String { - let mutString = NSMutableString(string: self) - CFStringTransform(mutString, nil, kCFStringTransformStripCombiningMarks, false) - return mutString as String - } - - /// Converts an NSRange to a Swift friendly Range supporting Unicode - /// - /// :param nsRange the NSRange to be converted - /// :return A corresponding Range if possible - func rangeFromNSRange(nsRange : NSRange) -> Range? { - let from16 = utf16.startIndex.advancedBy(nsRange.location, limit: utf16.endIndex) - let to16 = from16.advancedBy(nsRange.length, limit: utf16.endIndex) - if let from = String.Index(from16, within: self), - let to = String.Index(to16, within: self) { - return from ..< to - } else { - return nil - } - } - -} - -public extension Character { - - /// Get int representation of character - /// - /// :return UInt32 that represents the given character - public var ord: UInt32 { - get { - let desc = self.description - return desc.unicodeScalars[desc.unicodeScalars.startIndex].value - } - } - - /// Convert character to string - /// - /// :return String representation of character - public var description: String { - get { - return String(self) - } - } -} - -infix operator =~ {} - -/// Regex match the string on the left with the string pattern on the right -/// -/// :return true if string matches the pattern otherwise false -public func =~(str: String, pattern: String) -> Bool { - return Regex(pattern).test(str) -} - -/// Concat the string to itself n times -/// -/// :return concatenated string -public func * (str: String, n: Int) -> String { - var stringBuilder = [String]() - n.times { - stringBuilder.append(str) - } - return stringBuilder.joinWithSeparator("") -} - diff --git a/Cent/CentTests/CentTests.swift b/Cent/CentTests/CentTests.swift deleted file mode 100644 index 8f01ab2..0000000 --- a/Cent/CentTests/CentTests.swift +++ /dev/null @@ -1,324 +0,0 @@ -// -// CentTests.swift -// CentTests -// -// Created by Ankur Patel on 10/16/14. -// Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved. -// - -import XCTest - -class CentTests: XCTestCase { - - override func setUp() { - super.setUp() - } - - override func tearDown() { - super.tearDown() - } - - /** - Array Test Cases - */ - - func testArrayEach() { - var arr: [String] = [] - let result = ["A", "B", "C"].each({ arr.append($0) }) - XCTAssertEqual(result, ["A", "B", "C"], "Return array itself") - XCTAssertEqual(arr.joinWithSeparator(""), "ABC", "Return string concatenated") - } - - func testArrayEachWhen() { - var arr: [String] = [] - let result = ["A", "B", "C"].each(when: { return $0 <= "B"}, callback: { arr.append($0) }); - XCTAssertEqual(result, ["A", "B", "C"], "Return array itself") - XCTAssertEqual(arr.joinWithSeparator(""), "AB", "Return string concatenated") - } - - func testArrayCycle() { - var result = "" - [1, 2, 3].cycle(2) { - print($0, separator: "", terminator: "", toStream: &result) - } - XCTAssertEqual("123123", result, "testCycle: Should return cycled pattern") - } - - func testArrayEvery(){ - let result = ["angry", "hungry"].every { (a: String) -> (Bool) in - a.hasSuffix("gry") - } - XCTAssertEqual(result, true, "testEvery: Should return true") - } - - func testArrayIndexOf() { - let array = ["foo", "spam", "bar", "eggs"] - XCTAssertEqual(array.indexOf("spam"), 1, "Should return correct index") - } - - func testArrayIndexOfReturnNill() { - XCTAssertNil(["foo", "spam", "bar", "eggs"].indexOf("NONE"), "Should return nill when element not found") - } - - func testArrayFetch(){ - let arr = [1, 2, 3, 4, 5, 6, 7, 8] - XCTAssertNil(arr.fetch(100),"Should return nill") - XCTAssertEqual(arr.fetch(100, orElse: 42), 42, "Should return orElse value") - XCTAssertEqual(arr.fetch(-1), 8, "Should return last element") - } - - func testArrayFindIndex(){ - let ind: Int? = ["foo", "bar", "spam", "eggs"].findIndex { - $0.length == 4 - } - XCTAssertEqual(2, ind!,"Should return correct index") - } - - func testArrayFindLastIndex() { - let ind: Int? = ["foo", "bar", "spam", "eggs"].findLastIndex { - $0.length == 4 - } - XCTAssertEqual(3, ind!,"Should return correct index") - } - - func testArrayFirst() { - XCTAssertEqual("foo", ["foo", "bar"].first(), "Should return first element") - } - - func testArrayFlatten() { - let unFlattened = ["foo", ["bar"], [["spam"]], [[["eggs"]]] ] - let flattened = unFlattened.flatten() - XCTAssertEqual(["foo", "bar", "spam", "eggs"], flattened, "Should return flattened array") - } - - func testArrayGet(){ - let element = ["foo", "bar"].get(0) - XCTAssertEqual("foo",element!, "Should return index element 0") - - let nothing = ["foo", "bar"].get(1000) - XCTAssertNil(nothing, "Should return nill") - } - - func testArrayInitial(){ - XCTAssertEqual(["foo", "bar", "spam"].initial(),["foo", "bar"], "Should return all but last") - XCTAssertEqual(["foo", "bar", "spam"].initial(2),["foo"], "Should return all but last 2 elements") - } - - func testArrayLast(){ - XCTAssertEqual(["foo", "bar"].last(),"bar", "Should return last element") - } - - func testArrayRest(){ - XCTAssertEqual(["foo", "bar", "spam"].rest(2),["spam"], "Should return all but first 2 element") - XCTAssertEqual(["foo", "bar", "spam"].rest(),["bar", "spam"], "Should return all but first element") - } - - func testArrayMin(){ - XCTAssertEqual([1, 0, 2, 3].min(),0, "Should return minimum") - } - - func testArrayMax(){ - XCTAssertEqual([1, 3, 0, 2].max(), 3, "Should return maximum") - } - - func testArrayRemove() { - var arr = ["A", "B", "C", "D", "E"] - arr.remove("B") - XCTAssertEqual(arr, ["A", "C", "D", "E"], "Test remove") - - arr.remove("Z") - XCTAssertEqual(arr, ["A", "C", "D", "E"], "Remove element that does not exist") - } - - func testArrayContains() { - let arr = ["A", "B", "C", "D", "E"] - XCTAssert(arr.contains("C"), "Test if array contains C") - XCTAssertFalse(arr.contains("Z"), "Test of failure") - } - - func testArrayReduceWithIndex() { - let str = ["A", "B", "C", "D", "E"].reduceWithIndex("") { (result, index, element) -> String in - result + element + "\(index)" - } - XCTAssertEqual(str, "A0B1C2D3E4", "Should reduce array to element followed by the index of the element") - } - - /** - String Test Cases - */ - - func testSubscript() { - XCTAssertEqual("Dollar and Cent"[0...5], "Dollar", "Return substring") - XCTAssertEqual("Dollar and Cent"[7..<10], "and", "Return substring") - } - - func testStringToWords() { - let str = "The Dukes... ruined my life... over a bet? For how much?" - let words = ["The", "Dukes", "ruined", "my", "life", "over", "a", "bet", "For", "how", "much"] - XCTAssertEqual(str.words(), words, "Should split the string into words ignoring puncuation") - } - - func testCompoundWordStringsToWords() { - let str = "DollarAndCent dollar-and-cent" - let words = ["Dollar", "And", "Cent", "dollar", "and", "cent"] - XCTAssertEqual(str.words(), words, "Should split compound strings into words") - } - - func testStringDeburr() { - let str = "My Göd! Thé Dûkęs àrè gôïng tò cõrnėr the entīre frózen ôrange jūice mårket!" - let match = "My God! The Dukes are going to corner the entire frozen orange juice market!" - XCTAssertEqual(str.deburr(), match, "Should remove string of all accents and diacritics") - } - - func contextCases(context: (testStrings: [String]) -> Void) { - let testStrs = [ - "I will give you <50> bucks", - "In Philàdèlphia, it is wõrth 50 bucks.", - "--1-dollar__", - "I believe we paid < 35000", - "\tMerryNEWYear! 😊", - "\nThis is *the* sports-watch of the '80s." - ] - context(testStrings: testStrs) - } - - func testCamelCase() { - contextCases { (testStrings) -> Void in - let camelCased = testStrings.map({ (str) -> String in - str.camelCase - }) - let matches = [ - "iWillGiveYou50Bucks", - "inPhiladelphiaItIsWorth50Bucks", - "1Dollar", - "iBelieveWePaid35000", - "merryNewYear", - "thisIsTheSportsWatchOfThe80S" - ] - XCTAssertEqual(camelCased, matches, "Should correctly camel case each string") - } - } - - func testKebabCase() { - contextCases { (testStrings) -> Void in - let kebabCase = testStrings.map({ (str) -> String in - str.kebabCase - }) - let matches = [ - "i-will-give-you-50-bucks", - "in-philadelphia-it-is-worth-50-bucks", - "1-dollar", - "i-believe-we-paid-35000", - "merry-new-year", - "this-is-the-sports-watch-of-the-80s" - ] - XCTAssertEqual(kebabCase, matches, "Should correctly kebab case each string") - } - } - - func testSnakeCase() { - contextCases { (testStrings) -> Void in - let snakeCase = testStrings.map({ (str) -> String in - str.snakeCase - }) - let matches = [ - "i_will_give_you_50_bucks", - "in_philadelphia_it_is_worth_50_bucks", - "1_dollar", - "i_believe_we_paid_35000", - "merry_new_year", - "this_is_the_sports_watch_of_the_80s" - ] - XCTAssertEqual(snakeCase, matches, "Should correctly snake case each string") - } - } - - func testStartCase() { - contextCases { (testStrings) -> Void in - let startCase = testStrings.map({ (str) -> String in - str.startCase - }) - let matches = [ - "I Will Give You 50 Bucks", - "In Philadelphia It Is Worth 50 Bucks", - "1 Dollar", - "I Believe We Paid 35000", - "Merry New Year", - "This Is The Sports Watch Of The 80S" - ] - XCTAssertEqual(startCase, matches, "Should correctly start case each string") - } - } - - /** - Regex Test Cases - */ - - func testRegex() { - XCTAssertEqual("Dollar and Cent" =~ "and", true, "Should pattern match with regex string") - XCTAssertEqual("Dollar and Cent" =~ "and Cent$", true, "Should pattern match with regex string") - XCTAssertEqual("Dollar and Cent" =~ "\\sand\\s", true, "Should pattern match with regex string") - XCTAssertEqual("Dollar and Cent" =~ "and Cent\\s+", false, "Should pattern match with regex string") - } - - /** - Int Test Cases - */ - - func testDateMath() { - struct TestDate { - let unit: NSCalendarUnit - let singleMath: Int.CalendarMath - let multipleMath: Int.CalendarMath - } - - let calendar = NSCalendar.autoupdatingCurrentCalendar() - let multiple = 2 - - let tests = [ - TestDate(unit: .Second, singleMath: 1.second, multipleMath: multiple.seconds), - TestDate(unit: .Minute, singleMath: 1.minute, multipleMath: multiple.minutes), - TestDate(unit: .Hour, singleMath: 1.hour, multipleMath: multiple.hours), - TestDate(unit: .Day, singleMath: 1.day, multipleMath: multiple.days), - TestDate(unit: .WeekOfYear, singleMath: 1.week, multipleMath: multiple.weeks), - TestDate(unit: .Month, singleMath: 1.month, multipleMath: multiple.months), - TestDate(unit: .Year, singleMath: 1.year, multipleMath: multiple.years) - ] - - tests.each { (test) -> () in - func equalIsh(lhs: NSDate!, rhs: NSDate!) -> Bool { - return round(lhs.timeIntervalSinceNow) == round(rhs.timeIntervalSinceNow) - } - - let components = NSDateComponents() - components.setValue(1, forComponent: test.unit) - - XCTAssert(equalIsh(test.singleMath.fromNow, rhs: calendar.dateByAddingComponents(components, toDate: NSDate(), options: [])), "formNow single units are equal.") - components.setValue(-1, forComponent: test.unit) - XCTAssert(equalIsh(test.singleMath.ago, rhs: calendar.dateByAddingComponents(components, toDate: NSDate(), options: [])), "ago single units are equal.") - - components.setValue(multiple, forComponent: test.unit) - XCTAssert(equalIsh(test.multipleMath.fromNow, rhs: calendar.dateByAddingComponents(components, toDate: NSDate(), options: [])), "formNow multiple units are equal.") - components.setValue(-multiple, forComponent: test.unit) - XCTAssert(equalIsh(test.multipleMath.ago, rhs: calendar.dateByAddingComponents(components, toDate: NSDate(), options: [])), "ago multiple units are equal.") - } - } - - /** - Dictionary Test Cases - */ - - func testDictionaryMerge() { - let eastCoastStateCapitals = ["New York": "Albany", "Maryland":"Annapolis", "Connecticut":"Hartford" ] - let westCoastStateCapitals = ["California": "Sacremento", "Washington":"Olympia"] - var usStateCapitals: Dictionary = [:] - usStateCapitals.merge(eastCoastStateCapitals, westCoastStateCapitals) - XCTAssertEqual(usStateCapitals, ["New York": "Albany", "Maryland":"Annapolis", "Connecticut":"Hartford" ,"California": "Sacremento", "Washington":"Olympia"]) - } - - func testArrayDifference() { - let arr = ["B", "A", "C", "E", "D"] - XCTAssertEqual(arr - ["C"], ["B", "A", "E", "D"], "Test removes C") - XCTAssertEqual(arr - ["E", "C"], ["B", "A", "D"], "Test removes C and E") - } -} diff --git a/Cent/README.md b/Cent/README.md deleted file mode 100644 index c0273f9..0000000 --- a/Cent/README.md +++ /dev/null @@ -1,732 +0,0 @@ -# Cent Usage # - -## Array Extensions ## - -### `<< elem: Element -> [Element]` - -Overloaded operator to append element to an array or append elements from another array into the first array. Return array with the element appended in the end. - -```swift -var array = [1, 2, 3] -array << 4 -=> [1, 2, 3, 4] -array << [5, 6] -=> [1, 2, 3, 4, 5, 6] -``` - -### `at(indexes: Int...) -> [Element]` - -Creates an array of elements from the specified indexes, or keys, of the collection. - -```swift -let array = ["foo", "spam", "bar", "eggs"] -let some = array.at(1, 3) -=> ["spam", "eggs"] -``` - -### `each(callback: (Element) -> ()) -> [Element]` - -For each item in the array invoke the callback by passing the elem - -```swift -let array = ["foo", "spam", "bar", "eggs"] -array.each { - print($0) -} -=> ["foo", "spam", "bar", "eggs"] -``` - -### `eachWithIndex(callback: (Int, Element) -> ()) -> [Element]` - -For each item in the array invoke the callback by passing the elem along with the index - -```swift -let array = ["foo", "spam", "bar", "eggs"] -array.each { (index, elem) - print("\(index) - \(elem)") -} -=> ["foo", "spam", "bar", "eggs"] -``` - -### `cycle(times: Int, callback: (Element) -> U)` - -Cycles through the array definetly or indefinetly passing each element into the callback function. The second parameter is to specify how many times to cycle through the array. If left out it will cycle indefinetly. - -```swift -[1, 2, 3].cycle(2) { - print($0) -} -// Prints the following -123123 - -[1, 2, 3].cycle { - print($0) -} -// Cycles in an infinite loop -``` - -### `every(callback: (Element) -> Bool) -> Bool` - -Checks if the given callback returns true value for all items in the array. - -```swift -["angry", "hungry"].every { (a: String) -> (Bool) in - a.hasSuffix("gry") -} -=> true -``` - -### `indexOf(value: T) -> Int` - -Gets the index at which the first occurrence of value is found. - -```swift -let array = ["foo", "spam", "bar", "eggs"] -array.indexOf("spam") -=> 1 -array.indexOf("None") -=> nil -``` - -### `fetch(index: Int, orElse: T? = .None) -> T!` - -Get element from an array at the given index which can be negative to find elements from the end of the array. A default value can be returned if indexing out of bounds. - - -```swift -let arr = [1, 2, 3, 4, 5, 6, 7, 8] -arr.fetch(100) -=> nil - -arr.fetch(100, orElse: 42) -=> 42 - -arr.fetch(-1) -=> 8 -``` - -### `findIndex(callback: (Element) -> Bool) -> Int?` - -This method is like find except that it returns the index of the first element that passes the callback check. - -```swift -let ind: int? = ["foo", "bar", "spam", "eggs"].findIndex { - $0.length == 4 -} -ind! == 2 -=> true -``` - -### `findLastIndex(callback: (Element) -> Bool) -> Int?` - -This method is like findIndex except that it iterates over elements of the array from right to left. - -```swift -let ind: int? = ["foo", "bar", "spam", "eggs"].findLastIndex { - $0.length == 4 -} -ind! == 3 -=> true -``` - -### `first() -> Element?` - -Gets the first element in the array. - -```swift -let first = ["foo", "bar"].first() -=> "foo" -``` - -### `flatten() -> [Element]` - -Flattens a nested array of any depth. - -```swift -let unFlattened = ["foo", ["bar"], [["spam"]], [[["eggs"]]] ] -let flattened = unFlattened.flatten() -=> ["foo", "bar", "spam", "eggs"] -``` - -### `get(index: Int) -> Element?` - -Get element at index - -```swift -let element = ["foo", "bar"].get(0) -element! -=> "foo" - -let nothing = ["foo", "bar"].get(1000) -=> nil -``` - -### `initial(numElements: Int? = 1) -> [Element]` - -Gets all but the last element or last n elements of an array. - -```swift -let initial = ["foo", "bar", "spam"].initial(2) -=> ["foo"] -``` - -### `last() -> Element?` - -Gets the last element from the array. - -```swift -let last = ["foo", "bar"].last() -=> "bar" -``` - -### `rest(numElements: Int? = 1) -> [Element]` - -The opposite of initial this method gets all but the first element or first n elements of an array. - -```swift -let rest = ["foo", "bar", "spam"].rest(2) -=> ["spam"] -``` - -### `min() -> T?` - -Retrieves the minimum value in an array. - -```swift -let min = [ 0, 1, 2 ].min() -=> 0 -``` - -### `max() -> T?` - -Retrieves the maximum value in an array. - -```swift -let max = [ 0, 1, 2].max() -=> 2 -``` - -### `remove(value: T) -> T?` - -Remove element from array - -```swift -var arr = ["A", "B", "C", "D", "E"] -arr.remove("B") -=> ["A", "C", "D", "E"] -``` - -### `contains(value: T) -> Bool` - -Checks if a given value is present in the array. - -```swift -var arr = ["A", "B", "C", "D", "E"] -arr.contains("C") -=> true -arr.contains("Z") -=> false -``` - - -## Character Extensions ## - -### `"A".description -> String` - -Get string description of Character - -```swift -let ch: Character = "A" -let str = ch.description -=> "A" -``` - -### `"A".ord -> Int` - -Get int representation of character - -```swift -Character("A").ord -=> 65 -``` - - -## Date Extensions ## - -### `Date.from(#year: Int, month: Int, day: Int) -> NSDate` - -Returns a new Date given the year month and day - -```swift -let date = Date.from(2014, 1, 1) -=> "Jan 1, 2014, 12:00 AM" -``` - -### `Date.from(#unix: Double) -> NSDate` - -Returns a new Date given the unix timestamp (timeIntervalSince1970) - -```swift -let date = Date.from(unix: 1_388_552_400.0) -=> "Jan 1, 2014, 12:00 AM" -``` - -### `Date.parse(dateStr: String, format: String = "yyyy-MM-dd") -> NSDate` - -Parses the date based on the format and return a new Date - -```swift -let parsedDate = Date.parse("2014-01-01", format: "yyyy-MM-dd") -=> "Jan 1, 2014, 12:00 AM" -``` - -### `Date.unix(date: NSDate = NSDate()) -> Double` - -Returns the unix timestamp of the date passed in or the current unix timestamp - -```swift -let currentUnix = Date.unix() -=> 1,388,552,400.0 - -var otherNSDate = Date() -let otherUnix = Date.unix(otherDate) -=> 1,388,552,400.0 -``` - -### `Int.hour.fromNow` et al. - -Use the following syntax to calculate dates and times based on the user's current calendar. - -```swift -1.day.ago -=> "Apr 10, 2015, 11:51 AM" -4.hours.fromNow -=> "Apr 11, 2015, 3:51 PM" -``` - -## Dictionary Extensions ## - -### `merge(dictionaries: Dictionary...)` - -Merges the dictionary with dictionaries passed. The latter dictionaries will override values of the keys that are already set - -```swift -var dic = ["foo": "bar"] -let anotherDic = ["foo": "baz", "spam": "eggs"] -dic.merge(anotherDic) -=> ["foo": "baz", "spam": "eggs"] -``` - -## Int Extensions ## - -### `times(callback: (Int) -> ())` - -Invoke a callback n times with callback that takes index - -```swift -5.times { print("Na") } -=> "NaNaNaNaNa" -``` - -### `times (function: () -> ())` - -Invoke a callback n times - -```swift -5.times { (a: Int) -> () in print("\(a) ") } -=> 0 1 2 3 4 -``` - -### `char -> Character` - -Get ASCII character from integer - -```swift -65.char -=> "A" -``` - -### `isEven` - -Check if int is even - -```swift -2.isEven -=> true - -1.isEven -=> false -``` - -### `isOdd` - -Check if int is odd - -```swift -3.isOdd -=> true - -2.isOdd -=> false -``` - -### `digits() -> [Int]` - -Splits the int into array of digits - -```swift -4208.digits() -=> [4, 2, 0, 8] -``` - -### `lcm() -> Int` - -LCM method return least common multiple with number passed - -```swift -3.lcm(10) -=> 30 - -3.lcm(9) -=> 9 -``` - -### `gcd() -> Int` - -GCD method return greatest common denominator with number passed - -```swift -3.gcd(10) -=> 1 - -3.gcd(9) -=> 3 -``` - -### `random() -> Int` - -Returns random number from 0 upto but not including value of integer - -```swift -3.random() -=> 2 - -3.random() -=> 1 -``` - -### `factorial() -> Int` - -Returns factorial of integer - -```swift -3.factorial() -=> 6 - -0.factorial() -=> 1 -``` - -### `isIn(interval) -> Bool` - -Returns true if i is in interval or range - -```swift -5.isIn(1...10) -=> true - -10.isIn(1..<10) -=> false -``` - -### `next() -> Int` - -Get the next int - -```swift -10.next() -=> 11 -``` - -### `prev() -> Int` - -Get the previous int - -```swift -10.prev() -=> 9 -``` - -### `upTo(limit: Int, callback: () -> ())` - -Invoke the callback from int up to and including limit - -```swift -3.upTo(5) { - print("Hi") -} -Prints "HiHiHi" -``` - -### `downTo(limit: Int, callback: () -> ())` - -Invoke the callback from int down to and including limit - -```swift -3.upTo(0) { - print("Hi") -} -Prints "HiHiHiHi" -``` - -## String Extensions ## - -### `.length` - -Get the length of the string - -```swift -"Hello".length -=> 5 -``` - -### `.camelCase` - -Get the camel case representation of the string - -```swift -"__Dollar and cent-- dollarANDCent".camelCase -=> "dollarAndCentDollarAndCent" -``` - -### `.kebabCase` - -Get the kebab case representation of the string - -```swift -"__Dollar and cent-- dollarANDCent".kebabCase -=> "dollar-and-cent-dollar-and-cent" -``` - -### `.snakeCase` - -Get the snake case representation of the string - -```swift -"__Dollar and cent-- dollarANDCent".snakeCase -=> "dollar_and_cent_dollar_and_cent" -``` - -### `.startCase` - -Get the start case representation of the string - -```swift -"__Dollar and cent-- dollarANDCent".startCase -=> "Dollar And Cent Dollar And Cent" -``` - -### `=~ str: String -> Bool` - -Does a regex match of whether regex string on the right is matches the string on the left - -```swift -"Dollar" =~ "oll" -=> true -``` - -### `* n: Int -> String` - -Get string concatenated `n` times - -```swift -"Hi Swift! " * 3 -=> "Hi Swift! Hi Swift! Hi Swift! " -``` - -### `[i: Int] -> Character?` - -Get character at a subscript - -```swift -"Hello World"[6] == "W" -=> true - -"Hi"[5] -=> nil -``` - -### `[str: String] -> String?` - -Returns the substring based on the first regex match passed in the subscript - -```swift -let proj = "Dollar and Cent" -proj["^.+[^and Cent]"] -=> {Some: "Dollar"} -``` - - -### `[r: Range] -> String` - -Get substring using subscript notation and by passing a range - -```swift -"Hello World"[0..<5] == "Hello" -=> true -``` - -### `indexOf(char: Character) -> Int?` - -Get the start index of character - -```swift -"hello world".indexOf(Character("o"))! -=> 4 -``` - - -### `indexOf(str: String) -> Int?` - -Get the start index of string - -```swift -"hello world".indexOf("llo")! -=> 2 - -"hello world".indexOf("illo") -=> nil -``` - -### `indexOf(pattern: String) -> Int?` - -Get the start index of regex pattern inside the string - -```swift -"hello world".indexOf(".llo")! -=> 1 -``` - -### `split(delimiter: Character) -> [String]` - -Get an array from string split using the delimiter character - -```swift -"Hello World".split(" ") -=> ["Hello", "World"] -``` - -### `lstring() -> String` - -Get string without leading spaces - -```swift -let leadingSpace = " Hello" -leadingSpace.lstrip() -=> "Hello" -``` - -### `rstring() -> String` - -Get string without trailing spaces - -```swift -let trailingSpace = "Hello " -trailingSpace.rstrip() -=> "Hello" -``` - -### `strip() -> String` - -Get string without leading or trailing spaces - -```swift -let spaces = " Hello " -spaces.strip() -=> "Hello" -``` - -## Regex ## - -### `init` - -Init with regex pattern as string - -```swift -Regex.init("^Hello.World$") // Regex that matches "Hello World" -``` - -### `matches(testStr: String) -> [AnyObject]` - -Return matches based on String passed. - -```swift -let re = Regex.init("^Hello.World$") -re.matches("Hello World") -``` - -### `test(testStr: String) -> Bool` - -```swift -let re = Regex.init("^Hello.World$") -re.test("Hello World") -=> true - -re.test("Str") -=> false -``` - -### `escapeStr(str: String) -> String` - -Escape string with regex characters - -```swift -Regex.escape("Hello.World") -=> "Hello\.World" -``` - -## Range Extensions ## - -### equals - `==` - -Check the equality of two ranges - -```swift -(1...5) == (1...5) -=> true - -(1..<5) == (1...5) -=> false -``` - -### `eachWithIndex(callback: (T) -> ())` - -For each index in the range invoke the callback by passing the item in range - -```swift -(1...5).eachWithIndex { (a: Int) -> () in print("\(a)") } -=> 12345 -``` - -### `each(callback: () -> ())` - -For each index in the range invoke the callback - -```swift -(1...5).each { print("Na") } -=> "NaNaNaNaNa" -``` - -# Contributing # -If you are interested in contributing checkout [CONTRIBUTING.md](https://github.com/ankurp/Dollar.swift/blob/master/CONTRIBUTING.md) - -# Roadmap # - -* Add more extention functions to the Cent library -* Benchmark and improve performance if applicable - -# Dollar or Cent # -If you are interested only in pure functional programming `import Dollar` otherwise `import Cent` which includes extensions for certain object type such as Array for now but more will be added. - - -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ankurp/dollar.swift/trend.png)](https://bitdeli.com/free "Bitdeli Badge") diff --git a/Dollar.podspec b/Dollar.podspec index ced2b21..7463dec 100644 --- a/Dollar.podspec +++ b/Dollar.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = "Dollar" - s.version = "4.1.0" + s.version = "5.0.0" s.summary = "A functional tool-belt for Swift Language" - s.homepage = "https://github.com/ankurp/Dollar.swift" + s.homepage = "https://github.com/ankurp/Dollar" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "Ankur Patel" => "ankur.patel@ymail.com" } - s.source = { :git => "https://github.com/ankurp/Dollar.swift.git", :tag => "#{s.version}" } - s.source_files = "Dollar/Dollar/*.{h,swift}" + s.source = { :git => "https://github.com/ankurp/Dollar.git", :tag => "#{s.version}" } + s.source_files = "Sources/*.{h,swift}" s.ios.deployment_target = "8.0" s.osx.deployment_target = "10.10" s.requires_arc = true diff --git a/Dollar/Dollar.xcodeproj/project.pbxproj b/Dollar.xcodeproj/project.pbxproj similarity index 81% rename from Dollar/Dollar.xcodeproj/project.pbxproj rename to Dollar.xcodeproj/project.pbxproj index 59521fb..6aae5ee 100644 --- a/Dollar/Dollar.xcodeproj/project.pbxproj +++ b/Dollar.xcodeproj/project.pbxproj @@ -7,10 +7,12 @@ objects = { /* Begin PBXBuildFile section */ - 9252FCD21A0F26F6002E85A4 /* AutoCurry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9252FCD11A0F26F6002E85A4 /* AutoCurry.swift */; }; + 92180C3B1C70F155003BA0E3 /* AutoCurry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92180C381C70F155003BA0E3 /* AutoCurry.swift */; }; + 92180C3D1C70F155003BA0E3 /* Dollar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92180C3A1C70F155003BA0E3 /* Dollar.swift */; }; + 92180C461C70F2B2003BA0E3 /* Dollar.h in Headers */ = {isa = PBXBuildFile; fileRef = 92180C391C70F155003BA0E3 /* Dollar.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 92180C501C70F337003BA0E3 /* Dollar.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 92180C4A1C70F337003BA0E3 /* Dollar.podspec */; }; + 92180C561C70F8A1003BA0E3 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 92180C4B1C70F337003BA0E3 /* LICENSE */; }; 925CB1E11A3FDCA4004F1319 /* Dollar.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = 92E0D03C19467C67002ACC3D /* Dollar.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 92E0D04219467C67002ACC3D /* Dollar.h in Headers */ = {isa = PBXBuildFile; fileRef = 92E0D04119467C67002ACC3D /* Dollar.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 92E0D05919467CA2002ACC3D /* Dollar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92E0D05819467CA2002ACC3D /* Dollar.swift */; }; 92E6687A19F09D2A00BB4FB8 /* CarExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0419C8411948BEC600B947B3 /* CarExample.swift */; }; 92E6687B19F09D2A00BB4FB8 /* DollarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92E0D04E19467C67002ACC3D /* DollarTests.swift */; }; 92E6687C19F09D3000BB4FB8 /* Dollar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92E0D03C19467C67002ACC3D /* Dollar.framework */; }; @@ -42,15 +44,21 @@ /* Begin PBXFileReference section */ 0419C8411948BEC600B947B3 /* CarExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CarExample.swift; sourceTree = ""; }; - 9252FCD11A0F26F6002E85A4 /* AutoCurry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutoCurry.swift; sourceTree = ""; }; + 92180C381C70F155003BA0E3 /* AutoCurry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AutoCurry.swift; path = Sources/AutoCurry.swift; sourceTree = SOURCE_ROOT; }; + 92180C391C70F155003BA0E3 /* Dollar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Dollar.h; path = Sources/Dollar.h; sourceTree = SOURCE_ROOT; }; + 92180C3A1C70F155003BA0E3 /* Dollar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Dollar.swift; path = Sources/Dollar.swift; sourceTree = SOURCE_ROOT; }; + 92180C401C70F184003BA0E3 /* auto_curry.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; name = auto_curry.rb; path = scripts/auto_curry.rb; sourceTree = SOURCE_ROOT; }; + 92180C421C70F1BE003BA0E3 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Sources/Info.plist; sourceTree = SOURCE_ROOT; }; + 92180C471C70F337003BA0E3 /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = ""; }; + 92180C481C70F337003BA0E3 /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .travis.yml; sourceTree = ""; }; + 92180C491C70F337003BA0E3 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = ""; }; + 92180C4A1C70F337003BA0E3 /* Dollar.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Dollar.podspec; sourceTree = ""; }; + 92180C4B1C70F337003BA0E3 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; + 92180C4C1C70F337003BA0E3 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 92E0D03C19467C67002ACC3D /* Dollar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Dollar.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 92E0D04019467C67002ACC3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 92E0D04119467C67002ACC3D /* Dollar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Dollar.h; sourceTree = ""; }; 92E0D04D19467C67002ACC3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 92E0D04E19467C67002ACC3D /* DollarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DollarTests.swift; sourceTree = ""; }; - 92E0D05819467CA2002ACC3D /* Dollar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dollar.swift; sourceTree = ""; }; 92E6686F19F09C6400BB4FB8 /* DollarTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DollarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 92F1389C1A0F28C000B72258 /* gen_auto_curry.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = gen_auto_curry.rb; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -78,6 +86,12 @@ 92E0D03E19467C67002ACC3D /* Dollar */, 92E0D04B19467C67002ACC3D /* DollarTests */, 92E0D03D19467C67002ACC3D /* Products */, + 92180C4A1C70F337003BA0E3 /* Dollar.podspec */, + 92180C491C70F337003BA0E3 /* CONTRIBUTING.md */, + 92180C4C1C70F337003BA0E3 /* README.md */, + 92180C4B1C70F337003BA0E3 /* LICENSE */, + 92180C471C70F337003BA0E3 /* .gitignore */, + 92180C481C70F337003BA0E3 /* .travis.yml */, ); sourceTree = ""; }; @@ -93,9 +107,9 @@ 92E0D03E19467C67002ACC3D /* Dollar */ = { isa = PBXGroup; children = ( - 92E0D04119467C67002ACC3D /* Dollar.h */, - 92E0D05819467CA2002ACC3D /* Dollar.swift */, - 9252FCD11A0F26F6002E85A4 /* AutoCurry.swift */, + 92180C381C70F155003BA0E3 /* AutoCurry.swift */, + 92180C391C70F155003BA0E3 /* Dollar.h */, + 92180C3A1C70F155003BA0E3 /* Dollar.swift */, 92F138971A0F283400B72258 /* Pre Build Script */, 92E0D03F19467C67002ACC3D /* Supporting Files */, ); @@ -105,7 +119,7 @@ 92E0D03F19467C67002ACC3D /* Supporting Files */ = { isa = PBXGroup; children = ( - 92E0D04019467C67002ACC3D /* Info.plist */, + 92180C421C70F1BE003BA0E3 /* Info.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -131,7 +145,7 @@ 92F138971A0F283400B72258 /* Pre Build Script */ = { isa = PBXGroup; children = ( - 92F1389C1A0F28C000B72258 /* gen_auto_curry.rb */, + 92180C401C70F184003BA0E3 /* auto_curry.rb */, ); name = "Pre Build Script"; sourceTree = ""; @@ -143,7 +157,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 92E0D04219467C67002ACC3D /* Dollar.h in Headers */, + 92180C461C70F2B2003BA0E3 /* Dollar.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -195,7 +209,7 @@ isa = PBXProject; attributes = { LastSwiftMigration = 0700; - LastSwiftUpdateCheck = 0700; + LastSwiftUpdateCheck = 0720; LastUpgradeCheck = 0700; ORGANIZATIONNAME = "Encore Dev Labs LLC"; TargetAttributes = { @@ -230,6 +244,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 92180C561C70F8A1003BA0E3 /* LICENSE in Resources */, + 92180C501C70F337003BA0E3 /* Dollar.podspec in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -256,7 +272,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/bash; - shellScript = "ruby \"${PROJECT_DIR}/gen_auto_curry.rb\"\n"; + shellScript = "ruby \"${PROJECT_DIR}/scripts/auto_curry.rb\"\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -265,8 +281,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9252FCD21A0F26F6002E85A4 /* AutoCurry.swift in Sources */, - 92E0D05919467CA2002ACC3D /* Dollar.swift in Sources */, + 92180C3B1C70F155003BA0E3 /* AutoCurry.swift in Sources */, + 92180C3D1C70F155003BA0E3 /* Dollar.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -390,7 +406,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; - INFOPLIST_FILE = Dollar/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.encoredevlabs.${PRODUCT_NAME:rfc1034identifier}"; @@ -412,7 +428,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; - INFOPLIST_FILE = Dollar/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.encoredevlabs.${PRODUCT_NAME:rfc1034identifier}"; @@ -424,6 +440,7 @@ 92E6687619F09C6400BB4FB8 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", @@ -444,6 +461,7 @@ 92E6687719F09C6400BB4FB8 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", diff --git a/Dollar/Dollar.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Dollar.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from Dollar/Dollar.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Dollar.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/Dollar/Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/18CD9413-8F71-45A7-8CAB-C12948969500.plist b/Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/18CD9413-8F71-45A7-8CAB-C12948969500.plist similarity index 100% rename from Dollar/Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/18CD9413-8F71-45A7-8CAB-C12948969500.plist rename to Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/18CD9413-8F71-45A7-8CAB-C12948969500.plist diff --git a/Dollar/Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/Info.plist b/Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/Info.plist similarity index 100% rename from Dollar/Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/Info.plist rename to Dollar.xcodeproj/xcshareddata/xcbaselines/92E6686E19F09C6400BB4FB8.xcbaseline/Info.plist diff --git a/Dollar/Dollar.xcodeproj/xcshareddata/xcschemes/Dollar.xcscheme b/Dollar.xcodeproj/xcshareddata/xcschemes/Dollar.xcscheme similarity index 100% rename from Dollar/Dollar.xcodeproj/xcshareddata/xcschemes/Dollar.xcscheme rename to Dollar.xcodeproj/xcshareddata/xcschemes/Dollar.xcscheme diff --git a/Dollar.xcworkspace/contents.xcworkspacedata b/Dollar.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index db370fc..0000000 --- a/Dollar.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/Dollar.xcworkspace/xcshareddata/Dollar.xccheckout b/Dollar.xcworkspace/xcshareddata/Dollar.xccheckout deleted file mode 100644 index d12f61c..0000000 --- a/Dollar.xcworkspace/xcshareddata/Dollar.xccheckout +++ /dev/null @@ -1,41 +0,0 @@ - - - - - IDESourceControlProjectFavoriteDictionaryKey - - IDESourceControlProjectIdentifier - CB5DCBA1-7772-46D1-8369-17612859F819 - IDESourceControlProjectName - Dollar - IDESourceControlProjectOriginsDictionary - - 4E2F5E824C021282D3F5789E108FCDC580F66A19 - https://github.com/pNre/Dollar.swift.git - - IDESourceControlProjectPath - Dollar.xcworkspace - IDESourceControlProjectRelativeInstallPathDictionary - - 4E2F5E824C021282D3F5789E108FCDC580F66A19 - .. - - IDESourceControlProjectURL - https://github.com/pNre/Dollar.swift.git - IDESourceControlProjectVersion - 111 - IDESourceControlProjectWCCIdentifier - 4E2F5E824C021282D3F5789E108FCDC580F66A19 - IDESourceControlProjectWCConfigurations - - - IDESourceControlRepositoryExtensionIdentifierKey - public.vcs.git - IDESourceControlWCCIdentifierKey - 4E2F5E824C021282D3F5789E108FCDC580F66A19 - IDESourceControlWCCName - Dollar.swift - - - - diff --git a/Dollar/Dollar/Info.plist b/Dollar/Dollar/Info.plist deleted file mode 100644 index 9784803..0000000 --- a/Dollar/Dollar/Info.plist +++ /dev/null @@ -1,28 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - ${CURRENT_PROJECT_VERSION} - NSHumanReadableCopyright - Copyright © 2014 Encore Dev Labs LLC. All rights reserved. - NSPrincipalClass - - - diff --git a/Dollar/DollarTests/Info.plist b/Dollar/DollarTests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/Dollar/DollarTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/Dollar/README.md b/Dollar/README.md deleted file mode 100644 index d8297cd..0000000 --- a/Dollar/README.md +++ /dev/null @@ -1,1059 +0,0 @@ -# Dollar Usage # - -## Array ## - -### at - `$.at` - -Creates an array of elements from the specified indexes, or keys, of the collection. Indexes may be specified as individual arguments or as arrays of indexes. - -```swift -$.at(["ant", "bat", "cat", "dog", "egg"], indexes: 0, 2, 4) -=> ["ant", "cat", "egg"] -``` - -### chunk - `$.chunk` - -Creates an array of elements split into groups the length of size. If array can’t be split evenly, the final chunk will be the remaining elements. - -```swift -$.chunk([1, 2, 3, 4], size: 2) -=> [[1, 2], [3, 4]] - -$.chunk([1, 2, 3, 4], size: 3) -=> [[1, 2, 3], [4]] -``` - -### compact - `$.compact` - -Creates an array with all nil values removed. - -```swift -$.compact([3, nil, 4, 5]) -=> [3, 4, 5] - -$.compact([nil, nil]) as NSObject[] -=> [] -``` - -### contains - `$.contains` - -Checks if a given value is present in the array. - -```swift -$.contains([1, 2, 3, 1, 2, 3], value: 2) -=> true - -$.contains([1, 2, 3, 1, 2, 3], value: 10) -=> false -``` - -### cycle - `$.cycle` - -Cycles through the array definetly or indefinetly passing each element into the callback function. The second parameter is to specify how many times to cycle through the array. If left out it will cycle indefinetly. - -```swift -$.cycle([1, 2, 3], 2) { - print($0) -} -// Prints the following -123123 -``` - -### difference - `$.difference` - -Creates an array excluding all values of the provided arrays - -```swift -$.difference([1, 2, 3, 4, 5], [5, 2, 10]) -=> [1, 3, 4] -``` - -### each - `$.each` - -Passes each element in the array to the callback - -```swift -$.each(["A", "B"]) { - print("Value \($0)") -} -=> ["A", "B"] - -$.each(["A", "B"]) { (index, elem) in - print("\(index) - \(elem)") -} -=> ["A", "B"] -``` - -### every - `$.every` - -Checks if the given callback returns true value for all items in the array. - -```swift -$.every([1, 2, 3, 4], callback: { $0 < 20 }) -=> true - -$.every([1, 2, 3, 4]) { $0 == 1 } -=> false -``` - -### factorial `$.factorial` - -Returns factorial of integer - -```swift -$.factorial(3) -=> 6 - -$.factorial(0) -=> 1 -``` - -### fetch - `$.fetch` - -Get element from an array at the given index which can be negative to find elements from the end of the array. A default value can be returned if indexing out of bounds. - - -```swift -let arr = [1, 2, 3, 4, 5, 6, 7, 8] -$.fetch(arr, 100) -=> nil - -$.fetch(arr, 100, orElse: 42) -=> 42 - -$.fetch(arr, -1) -=> 8 -``` - -### fill - `$.fill` - -Fills elements of array with value from start up to, but not including, end. This method mutates array. - -```swift -var arr = Array(count: 5, repeatedValue: 1) -$.fill(&arr, withElem: 42) -=> [42, 42, 42, 42, 42] - -var arr = Array(count: 5, repeatedValue: 1) -$.fill(&arr, withElem: 42, startIndex: 1, endIndex: 3) -=> [1, 42, 42, 42, 1] -``` - - -### find - `$.find` - -Iterates over elements of an array and returning the first element that the callback returns true for. - -```swift -$.find([1, 2, 3, 4], callback: { $0 == 2 }) -=> 2 - -$.find([1, 2, 3, 4]) { $0 == 10 } -=> nil -``` - -### findIndex - `$.findIndex` - -This method is like find except that it returns the index of the first element that passes the callback check. - -```swift -let arr = [["age": 36], ["age": 40], ["age": 1]] -let result = $.findIndex(arr) { $0["age"] < 20 } -result -=> 2 -``` - -### findLastIndex - `$.findLastIndex` - -This method is like findIndex except that it iterates over elements of the array from right to left. - -```swift -let arr = [["age": 36], ["age": 40], ["age": 1]] -let result = $.findLastIndex(arr) { $0["age"] > 30 } -result -=> 1 -``` - -### first - `$.first(array: AnyObject[])` - -Gets the first element in the array. - -```swift -$.first([1, 2, 3, 4]) -=> 1 - -$.first([]) -=> nil -``` - -### second - `$.second(array: AnyObject[])` - -Gets the second element in the array. - -```swift -$.second([1, 2, 3, 4]) -=> 2 - -$.second([1]) -=> nil - -$.second([]) -=> nil -``` - -### flatMap - `$.flatMap` - -Maps a function that converts elements to a list and then concatenates them. - -```swift -let values = [2, 3, 4, 5, 6, 7] -$.flatMap(values) { [$0, $0] } -=> [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7] -``` - -### flatMap - `$.flatMap` - -Maps a function that converts a type to an Optional over an Optional, and then returns a single-level Optional. - - -```swift -let url = NSURL(string: "https://apple.com/swift") -$.flatMap(url) { $0.lastPathComponent } -=> Optional("swift") -``` - -*Note*: This is the same behavior as Optional chaining. -The code above translates to -```swift -NSURL(string: "https://apple.com/swift/")?.lastPathComponent -=> Optional("swift") -``` - -### flatten - `$.flatten` - -Flattens a nested array of any depth. - -```swift -$.flatten([[3], 4, 5]) as Int[] -=> [3, 4, 5] - -$.flatten([[3], "Hello", 5]) as NSObject[] -=> [3, "Hello", 5] - -$.flatten([[[3], 4], 5]) as Int[] -=> [3, 4, 5] -``` - -### frequencies - `$.frequencies` -This method returns a dictionary of values in an array mapping to the total number of occurrences in the array. If passed a function it returns a frequency table of the results of the given function on the arrays elements. - -```swift -$.frequencies(["a", "a", "b", "c", "a", "b"]) -=> ["a": 3, "b": 2, "c": 1] - -$.frequencies([1, 2, 3, 4, 5]) { $0 % 2 == 0 } -=> [false: 3, true: 2] -``` - -### gcd `$.gcd` - -GCD function return greatest common denominator with number passed - -```swift -$.gcd(3, 10) -=> 1 - -$.gcd(3, 9) -=> 3 -``` - -### indexOf - `$.indexOf` - -Gets the index at which the first occurrence of value is found. - -```swift -$.indexOf([1, 2, 3, 1, 2, 3], value: 2) -=> 1 - -$.indexOf(["A", "B", "C"], value: "B") -=> 1 - -$.indexOf([3, 4, 5], value: 5) -=> 2 - -$.indexOf([3, 4, 5], value: 3) -=> 0 - -$.indexOf([3, 4, 5], value: 2) -=> nil -``` - -### initial - `$.initial` - -Gets all but the last element or last n elements of an array. - -```swift -$.initial([3, 4, 5]) -=> [3, 4] - -$.initial([3, 4, 5], numElements: 2) -=> [3] -``` - -### intersection - `$.intersection` - -Creates an array of unique values present in all provided arrays. - -```swift -$.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]) -=> [1, 2] -``` - -### it-isIn `$.it(i: T, isIn range: Range)` - -Returns true if i is in interval or range - -```swift -$.it("c", isIn: "a"..."z") -=> true - -$.it("z", isIn: "a"..<"z") -=> false - -$.it(1, isIn: -1.0...10.0) -=> true -``` - -### last - `$.last` - -Gets the last element from the array. - -```swift -$.last([3, 4, 5]) -=> 5 -``` - -### lastIndexOf - `$.lastIndexOf` - -Gets the index at which the last occurrence of value is found. - -```swift -$.lastIndexOf([1, 2, 3, 1, 2, 3], value: 2) -=> 4 -``` - -### lcm `$.lcm` - -LCM method return least common multiple with number passed - -```swift -$.lcm(3, 10) -=> 30 - -$.lcm(3, 9) -=> 9 -``` - -### rest - `$.rest` - -The opposite of initial this method gets all but the first element or first n elements of an array. - -```swift -$.rest([3, 4, 5]) -=> [4, 5] - -$.rest([3, 4, 5], numElements: 2) -=> [5] -``` - -### map - `$.map` - -Maps each element to new value based on the map function passed - -```swift -$.map([1, 2, 3, 4]) { - $0 * 2 -} -=> [2, 4, 6, 8] -``` - -### min - `$.min` - -Retrieves the minimum value in an array. - -```swift -$.min([2, 1, 2, 3, 4]) -=> 1 -``` - -### max - `$.max` - -Retrieves the maximum value in an array. - -```swift -$.max([1, 2, 3, 4, 2, 1]) -=> 4 -``` - -### pluck - `$.pluck` - -Retrieves the value of a specified property from all elements in the array. - -```swift -let arr = [["age": 20], ["age": 30], ["age": 40]] -$.pluck(arr, value: "age") -=> [20, 30, 40] -``` - -### pull - `$.pull` - -Removes all provided values from the given array. - -```swift -$.pull([3, 4, 5, 3, 5], values: 3, 5) -=> [4] - -$.pull([3, 4, 5, 3, 5], values: 4) -=> [3, 5, 3, 5] - -$.pull([3, 4, 5, 3, 5], values: 3, 4, 5) -=> [] -``` - -### pullAt - `$.pullAt` - -Removes all provided values from the given array at the given indices - -```swift -let arr = [10, 20, 30, 40, 50] -$.pullAt(arr, indices: 1, 2, 3) -``` - -### range - `$.range` - -Creates an array of numbers (positive and/or negative) progressing from start up to but not including end. - -```swift -$.range(4) -=> [0, 1, 2, 3] - -$.range(from: 1, to: 5) -=> [1, 2, 3, 4] - -$.range(from: 0, to: 20, incrementBy: 5) -=> [0, 5, 10, 15] - -$.range(from: 1, through: 5) -=> [1, 2, 3, 4, 5] - -$.range(from: 0, through: 20, incrementBy: 5) -=> [0, 5, 10, 15, 20] -``` - -### reduce - `$.reduce` - -Reduce function that will resolve to one value after performing combine function on all elements - -```swift -$.reduce([1, 2, 3], initial: 0) { (total, element) in - total + element -} -=> 6 -``` - -### sample - `$.sample` - -Returns a sample item from the array - -```swift -let arr : Int[] = [2, 1, 2, 3, 4] -$.contains(arr, value: $.sample(arr)) -=> true -``` - -### sequence - `$.sequence` - -Creates an array of an arbitrary sequence. Especially useful with builtin ranges. - -```swift -$.sequence(0..4) -=> [0, 1, 2, 3] - -$.sequence(-2.0..2.0) -=> [-2.0, -1.0, 0.0, 1.0] - -$.sequence((0..20).by(5)) -=> [0, 5, 10, 15] - -$.sequence("abc") -=> ["a", "b", "c"] -``` -### remove - `$.remove` - -Removes an element from array. -```swift -$.remove(["A", "B", "C", "D"], value: "B") -=> ["A", "C", "D"] -``` - -### remove - `$.remove` - -Removes all elements from an array that the `callback` returns true. - -```swift -let result = $.remove([1, 2, 3, 4, 5, 6]) { - $0 == 2 || $0 == 3 -} -result -=> [1, 4, 5, 6] -``` - -### shuffle - `$.shuffle` - -Shuffles and returns the new shuffled array - -```swift -let result = $.shuffle([1, 2, 3, 4, 5, 6]) -result -=> [4, 1, 3, 5, 6, 2] -``` - -### size - `$.size` - -Returns size of the array - -```swift -_.size(["a", "b", "c") -=> 3 -``` - -### sortedIndex - `$.sortedIndex` - -Gives the smallest index at which a value should be inserted into a given the array is sorted. - -```swift -$.sortedIndex([3, 4, 6, 10], value: 5) -=> 2 - -$.sortedIndex([10, 20, 30, 50], value: 40) -=> 3 -``` - -### union - `$.union` - -Creates an array of unique values, in order, of the provided arrays. - -```swift -$.union([1, 2, 3], [5, 2, 1, 4], [2, 1]) -=> [1, 2, 3, 5, 4] -``` - -### merge - `$.merge` - -Creates an array of all values, including duplicates, of the arrays in the order they are provided. - -```swift -let arr = [1, 5] -let arr2 = [2, 4] -let arr3 = [5, 6] -let result = $.merge(arr, arr2, arr3) -result -=> [1, 5, 2, 4, 5, 6] -``` - -### uniq - `$.uniq` - -Creates a duplicate-value-free version of an array. - -```swift -$.uniq([1, 2, 1, 3, 1]) -=> [1, 2, 3] - -$.uniq([1, 2.5, 3, 1.5, 2, 3.5]) { - floor($0) -} -=> [1, 2.5, 3] -``` - -### without - `$.without` - -Creates an array excluding all provided values. - -```swift -$.without([3, 4, 5, 3, 5], values: 3, 5) -=> [4] - -$.without([3, 4, 5, 3, 5], values: 4) -=> [3, 5, 3, 5] - -$.without([3, 4, 5, 3, 5], values: 3, 4, 5) -=> [] -``` - -### xor - `$.xor` - -Creates an array that is the symmetric difference of the provided arrays. - -```swift -$.xor([1, 2, 3], [5, 2, 1, 4]) -=> [3, 4, 5] -``` - -### zip - `$.zip` - -Creates an array of grouped elements, the first of which contains the first elements of the given arrays. - -```swift -$.zip(["fred", "barney"], [30, 40], [true, false]) as [NSObject] -=> [["fred", 30, true], ["barney", 40, false]] -``` - -### zipObject - `$.zipObject` - -Creates an object composed from arrays of keys and values. - -```swift -$.zipObject(["fred", "barney"], values: [30, 40]) -=> ["fred": 30, "barney": 40] -``` - -### partition - `$.partition` - -Produces an array of arrays, each containing n elements, each offset by step. Stops after a partition is less than n length. - -```swift -let arr = [1, 2, 3, 4, 5] -$.partition(arr, n: 2) -=> [[1, 2], [3, 4]] - -$.partition(arr, n: 4, step: 1) -=> [[1, 2, 3, 4], [2, 3, 4, 5]] - -$.partition(arr, n: 4, step: 1, pad: nil) -=> [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5]] - -$.partition(arr, n: 4, step: 1, pad: [6, 7, 8]) -=> [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]] -``` - -### partitionAll - `$.partitionAll` - -Produces an array of arrays, each containing n elements, each offset by step. Continues after a partition is less than n length. - -```swift -$.partitionAll([1, 2, 3, 4, 5], n:4, step: 1) -=> [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5], [4, 5], [5]] -``` - -### partitionBy - `$.partitionBy` - -Applies a function to each element in array, splitting it each time the function returns a new value. - -```swift -$.partitionBy([1, 2, 3, 4, 5]) { $0 % 2 == 0 } -=> [[1], [2, 4], [3, 5], [6]] - -$.partitionBy([1, 7, 3, 6, 10, 12]) { $0 % 3 } -=> [[1, 7], [3, 6], [10], [12]] -``` - -## Dictionary ## - -### keys - `$.keys` - -Creates an array of keys given a dictionary. - -```swift -$.keys(["Dog": 1, "Cat": 2]) -=> ["Dog", "Cat"] -``` - -### values - `$.values` - -Creates an array of values given a dictionary - -```swift -$.values(["Dog": 1, "Cat": 2]) -=> [1, 2] -``` - -### merge - `$.merge` - -Merges all of the dictionaries together and the latter dictionary overrides the value at a given key - -```swift -let dict: Dictionary = ["Dog": 1, "Cat": 2] -let dict2: Dictionary = ["Cow": 3] -let dict3: Dictionary = ["Sheep": 4] -$.merge(dict, dict2, dict3) -=> ["Dog": 1, "Cat": 2, "Cow": 3, "Sheep": 4] -``` - -### pick - `$.pick` - -Creates a shallow clone of a dictionary composed of the specified keys. - -```swift -$.pick(["Dog": 1, "Cat": 2, "Cow": 3], keys: "Dog", "Cow") -=> ["Dog": 1, "Cow": 3] -``` - -### omit - `$.omit` - -Creates a shallow clone of a dictionary excluding the specified keys. - -```swift -$.omit(["Dog": 1, "Cat": 2, "Cow": 3], keys: "Cat", "Dog") -=> ["Cow": 3, "Sheep": 4] -``` - -## Object ## - -### tap - `$.tap` - -Invokes interceptor with the object and then returns object. - -```swift -var beatle = Car(name: "Fusca") -$.tap(beatle, {$0.name = "Beatle"}).color = "Blue" -``` - -## Function ## - -### after - `$.after` - -Creates a function that executes passed function only after being called n times. - -```swift -var saves = ["profile", "settings"]; -let asyncSave = { (function: () -> ()?) in - function() - // Saving right away for testing - // but in real world would be async -} -var isDone = false -var completeCallback = $.after(saves.count) { - isDone = true -} -for elem in saves { - asyncSave(completeCallback) -} -isDone -=> true -``` - -### bind - `$.bind` - -Creates a function that, when called, invokes func with the binding of arguments provided. - -```swift -let helloWorldFunc = $.bind({(T...) in - T[0] + " " + T[1] + " from " + T[2] -}, "Hello", "World", "Swift") -helloWorldFunc() -=> "Hello World from Swift" -``` - -### compose - `$.compose` - -Compose two or more functions where the return value of the first function is passed into the next function. Useful when chaining functions and returns a function that can be called with variadic argument values or an array of values as input - -```swift -let double = { (params: Int...) -> [Int] in - return $.map(params) { $0 * 2 } -} -let subtractTen = { (params: Int...) -> [Int] in - return $.map(params) { $0 - 10 } -} -let doubleSubtractTen = $.compose(double, subtractTen) -doubleSubtractTen(5, 6, 7) -=> [0, 2, 4] - -let f = $.compose({ (arr: [Int]) -> [Int] in - $.map(arr) { $0 + 1 } -}, { (arr: [Int]) -> [Int] in - $.map(arr) { $0 * 2 } -}) -f([1, 2]) -=> [4, 6] -``` - -### curry - `$.curry` - -Returns a function which when invoked either executes the function returning its result, if all function arguments have been provided, or returns another function that accepts one more argument of the remaining function arguments until all arguments are supplied. This is useful for making partial function as seen in these examples. - -```swift -func adder(x: Int, y: Int, z: Int) -> Int { -return x + y + z -} - -let curriedAdder = $.curry(adder) -let addTenAnd = curriedAdder(10) -let addThirtyAnd = addTenAnd(20) -addThirtyAnd(1) -=> 31 - -addThirtyAnd(50) -=> 80 - -addTenAnd(10)(10) -=> 30 -``` - -### id - `$.id` - -The identify function which simply returns the argument its given. - -```swift -$.id("Hello World from Swift") -=> "Hello World from Swift" -``` - -### memoize - `$.memoize` - -Returns a memoized function to improve performance by caching recursive function values. - -```swift -var times = 0 // to test memoization - -let fibMemo = $.memoize { (fib: (Int -> Int), val: Int) -> Int in - times += 1 - return val == 1 || val == 0 ? 1 : fib(val - 1) + fib(val - 2) -} - -let x = fibMemo(5) -times -=> 6 - -times = 0 -let y = fibMemo(5) -times -=> 0 - -times = 0 -let z = fibMemo(6) -times -=> 1 -``` - -### noop - `$.noop` - -A no-operation function. - -```swift -$.noop() -=> nil -``` - -### now - `$.now` - -Gets the number of seconds that have elapsed since the Unix epoch (1 January 1970 00:00:00 UTC). - -```swift -$.now() -=> 1431911564.292577 -``` - -### once - `$.once` - -Get a wrapper function that executes the passed function only once. Useful for getting shared config or creating singleton objects. - -```swift -func createConfig() -> [String: String] { - var i = 1 - return [ - "App ID": "\(i++)", - "URL": "https://someurl" - ] -} - -let getConfig = $.once(createConfig) -getConfig() -=> ["App ID": "1", "URL": "https://someurl"] - -getConfig() -=> ["App ID": "1", "URL": "https://someurl"] -``` - -### partial - `$.partial` - -Creates a function that, when called, invokes func with any additional partial arguments prepended to those provided to the new function. - -```swift -let partialFunc = $.partial({(T...) in - T[0] + " " + T[1] + " from " + T[2] -}, "Hello") -partialFunc("World", "Swift") -=> "Hello World from Swift" -``` - -### times - `$.times` - -Call a function n times and also passes the index. If a value is returned in the function then the times method will return an array of those values. - -```swift -let fun = $.bind({ (names: String...) -> String in - let people = $.join(names, separator: " from ") - return "Hello \(people)" - }, "Ankur", "Swift") -$.times(2, function: fun) as String[] -=> ["Hello Ankur from Swift", "Hello Ankur from Swift"] -``` - -## Chaining ## - -**`$.chain(...)`** - -### `any` - -Returns true if callback function returns true for at least one element in the array - -```swift -var chain = $.chain([1, 2, 3]) -chain.any({ ($0 as Int) < 2 }) -=> true -``` - -### `all` - -Returns true if callback function returns true for all elements in the array - -```swift -var chain = $.chain([1, 2, 3]) -chain.all({ ($0 as Int) < 10 }) -=> true -``` - -### `each` - -Passes each element value to the callback function - -```swift -var chain = $.chain(["Hello", "World"]) -var strBuilder = "" -chain.each({ strBuilder += ($0 as String) }).value -strBuilder -=> "HelloWorld" -``` - -### `filter` - -Filters the arrary to elements for which the callback function returns true - -```swift -var chain = $.chain([1, 2, 3, 4]) -chain.filter({ ($0 as Int) < 3 }).value -=> [1, 2] -``` - -### `first` - -Returns the first element in the array and terminates the chain - -```swift -var chain = $.chain([1, 2, 3, 4]) -chain.first() -=> 1 -``` - -### `second` - -Returns the second element in the array and terminates the chain - -```swift -var chain = $.chain([1, 2, 3, 4]) -chain.second() -=> 2 -``` - -### `third` - -Returns the third element in the array and terminates the chain - -```swift -var chain = $.chain([1, 2, 3, 4]) -chain.third() -=> 3 -``` - -### `flatten` - -Flattens a nested array of any depth. - -```swift -var chain = $.chain([[1, [2]], [3], 4]) -chain.flatten().value -=> [1, 2, 3, 4] -``` - -### `initial` - -Gets all but the last element or last n elements of an array. - -```swift -var chain = $.chain([1, 2, 3, 4]) -chain.initial(2).value -=> [1, 2] -``` - -### `map` - -Maps each element to the new value returned in the callback function - -```swift -var chain = $.chain([1, 2, 3, 4]) -chain.map({ ($0 as Int) * 2 }).value -=> [2, 4, 6, 8] -``` - -### `size` - -Returns size of the array and terminates the chain - -```swift -var chain = $.chain([1, 2, 3, 4]) -chain.map({ ($0 as Int) * 2 }).size() -=> 4 -``` - -### `slice` - -Slices the array based on the start and end position. If an end position is not specified it will slice till the end of the array. - -```swift -var chain = $.chain([1, 2, 3, 4, 5, 6, 7]) -chain.slice(2, end: 4).value -=> [3, 4] -``` - -### `value` - -Returns the value after evaluating all callbacks - -```swift -var chain = $.chain([1, 2, 3, 4, 5, 6, 7]) -chain.value -=> [1, 2, 3, 4, 5, 6, 7] -``` - -**Chaining more than one method** - -```swift -$.chain([[1, 2], 3, [[4], 5]]) - .initial() - .flatten() - .first() -=> 1 - -$.chain([1, 2, 3, 4, 5]) - .filter { $0 % 1 == 0 } - .map { $0 * 2 } - .all {$0 < 10} -=> false - -$.chain([1, 2, 3, 4, 5]) - .map({ $0 * 2 }) - .flatten() - .initial(2).value -=> [2, 4, 6] -``` diff --git a/Dollar/DollarTests/CarExample.swift b/DollarTests/CarExample.swift similarity index 100% rename from Dollar/DollarTests/CarExample.swift rename to DollarTests/CarExample.swift diff --git a/Dollar/DollarTests/DollarTests.swift b/DollarTests/DollarTests.swift similarity index 100% rename from Dollar/DollarTests/DollarTests.swift rename to DollarTests/DollarTests.swift diff --git a/Cent/CentTests/Info.plist b/DollarTests/Info.plist similarity index 100% rename from Cent/CentTests/Info.plist rename to DollarTests/Info.plist diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..c753239 --- /dev/null +++ b/Package.swift @@ -0,0 +1,3 @@ +import PackageDescription + +let package = Package(name: "Dollar") diff --git a/README.md b/README.md index 9467426..d54af5f 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,22 @@ -Dollar and Cent [![Build Status](https://travis-ci.org/ankurp/Dollar.swift.svg?branch=master)](https://travis-ci.org/ankurp/Dollar.swift) ![CocoaPods](https://img.shields.io/cocoapods/v/Dollar.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +Dollar [![Build Status](https://travis-ci.org/ankurp/Dollar.swift.svg?branch=master)](https://travis-ci.org/ankurp/Dollar.swift) ![CocoaPods](https://img.shields.io/cocoapods/v/Dollar.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) =========== -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ankurp/Dollar.swift?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ankurp/Dollar?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) Dollar is a Swift library that provides useful functional programming helper methods without extending any built in objects. It is similar to [Lo-Dash](https://lodash.com) or [Underscore.js](http://underscorejs.org) in Javascript. -Cent is a library that extends certain Swift object types using the extension feature and gives its two cents to Swift language. +Cent is a library that extends certain Swift object types using the extension feature and gives its two cents to Swift language. It is now moved into a seperate repo to support `carthage` and upcoming `Swift Package Manager` ## Contents ## - [Setup](#setup) - [Demo App](#demo-app) - [API Documentation](http://www.dollarswift.org) -- [Dollar](https://github.com/ankurp/Dollar.swift/tree/master/Dollar#dollar-usage) - - [Usage](#dollar-usage) - - [Array](#array) - - [Dictionary](#dictionary) - - [Object](#object) - - [Function](#function) - - [Chaining](#chaining) -- [Cent](https://github.com/ankurp/Dollar.swift/tree/master/Cent#cent-usage) - - [Usage](#cent-usage) - - [Array](#array-extensions) - - [Date](#date-extensions) - - [Dictionary](#dictionary-extensions) - - [Int](#int-extensions) - - [String](#string-extensions) - - [Range](#range-extensions) +- [Usage](#dollar-usage) + - [Array](#array) + - [Dictionary](#dictionary) + - [Object](#object) + - [Function](#function) + - [Chaining](#chaining) - [Contributing](#contributing) - [Roadmap](#roadmap) - [Dollar or Cent?](#dollar-or-cent) @@ -42,8 +33,8 @@ Add `pod 'Dollar'` to your `Podfile` and run `pod install`. Add `use_frameworks! ## Using `git submodule` -1. If you are using git then add Dollar as a submodule using `git submodule add https://github.com/ankurp/Dollar.swift.git`. If not using git download the project using `git clone https://github.com/ankurp/Dollar.swift.git` in your project folder. -2. Open the Dollar.swift folder. Drag Dollar.xcodeproj, inside the Dollar folder, into the file navigator of your Xcode project. +1. If you are using git then add Dollar as a submodule using `git submodule add https://github.com/ankurp/Dollar.git`. If not using git download the project using `git clone https://github.com/ankurp/Dollar.git` in your project folder. +2. Open the `Dollar` folder. Drag Dollar.xcodeproj, inside the Dollar folder, into the file navigator of your Xcode project. 3. In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar. 4. In the tab bar at the top of that window, open the "Build Phases" panel. 5. Expand the "Link Binary with Libraries" group, and add Dollar.framework. @@ -64,7 +55,7 @@ Using ## Communication ## -- If you **need help**, use [gitter.im](https://gitter.im/ankurp/Dollar.swift) or post a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/dollar.swift) with tag 'dollar.swift. +- If you **need help**, use [gitter.im](https://gitter.im/ankurp/Dollar) or post a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/dollar.swift) with tag 'dollar.swift. - If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/dollar.swift). - If you **found a bug**, open an issue. - If you **have a feature request**, open an issue. @@ -1850,7 +1841,7 @@ For each index in the range invoke the callback ``` # Contributing # -If you are interested in contributing checkout [CONTRIBUTING.md](https://github.com/ankurp/Dollar.swift/blob/master/CONTRIBUTING.md) +If you are interested in contributing checkout [CONTRIBUTING.md](https://github.com/ankurp/Dollar/blob/master/CONTRIBUTING.md) # Roadmap # diff --git a/Dollar/Dollar/AutoCurry.swift b/Sources/AutoCurry.swift similarity index 100% rename from Dollar/Dollar/AutoCurry.swift rename to Sources/AutoCurry.swift diff --git a/Dollar/Dollar/Dollar.h b/Sources/Dollar.h similarity index 100% rename from Dollar/Dollar/Dollar.h rename to Sources/Dollar.h diff --git a/Dollar/Dollar/Dollar.swift b/Sources/Dollar.swift similarity index 100% rename from Dollar/Dollar/Dollar.swift rename to Sources/Dollar.swift diff --git a/Cent/Cent/Info.plist b/Sources/Info.plist similarity index 100% rename from Cent/Cent/Info.plist rename to Sources/Info.plist diff --git a/Try.playground/Documentation/intro.html b/Try.playground/Documentation/intro.html deleted file mode 100644 index eed2d08..0000000 --- a/Try.playground/Documentation/intro.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - -
-
-
-

- Open the workspace file and open Try.playground from the Project Navigator on the left of XCode as the standalone playground will not recogninze the framework import. -

-
-
-
- - diff --git a/Try.playground/Documentation/main.css b/Try.playground/Documentation/main.css deleted file mode 100644 index ae21ba7..0000000 --- a/Try.playground/Documentation/main.css +++ /dev/null @@ -1,6 +0,0 @@ -body { - background-color: rgba(0, 0, 0, 0.8); - color: white; - font-family: Helvetica,Arial,sans-serif; - margin-left: 15px; -} \ No newline at end of file diff --git a/Try.playground/contents.xcplayground b/Try.playground/contents.xcplayground deleted file mode 100644 index 8ab43e4..0000000 --- a/Try.playground/contents.xcplayground +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Try.playground/section-2.swift b/Try.playground/section-2.swift deleted file mode 100644 index a36937b..0000000 --- a/Try.playground/section-2.swift +++ /dev/null @@ -1,4 +0,0 @@ -import Dollar -import Cent - - diff --git a/Try.playground/timeline.xctimeline b/Try.playground/timeline.xctimeline deleted file mode 100644 index aeef21f..0000000 --- a/Try.playground/timeline.xctimeline +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/Dollar/gen_auto_curry.rb b/scripts/auto_curry.rb similarity index 90% rename from Dollar/gen_auto_curry.rb rename to scripts/auto_curry.rb index b08c2d9..ae94f6a 100644 --- a/Dollar/gen_auto_curry.rb +++ b/scripts/auto_curry.rb @@ -21,6 +21,6 @@ def curry_generator(n) "}" ].join("\n\n") -File.open("#{File.dirname(__FILE__)}/Dollar/AutoCurry.swift", "w") do |file| +File.open("#{File.dirname(__FILE__)}/../Sources/AutoCurry.swift", "w") do |file| file.write(funcs) end