Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7daeb0518 | |||
| 9b6c798a17 | |||
| 959f4f0eb1 | |||
| 040aadd65f | |||
| b6a99e3ffe | |||
| 20d4d7e7c4 | |||
| a8a69e4570 | |||
| cea6cb0952 | |||
| fae6eb2617 | |||
| 0e3030af48 | |||
| 9a255de350 | |||
| ca1fc87240 | |||
| dff7877e06 | |||
| 32ec1a11ce | |||
| 4d8f31303a | |||
| b4da0afe8b | |||
| 34e3aa1c95 | |||
| 0ec1461200 | |||
| 3706b45822 | |||
| 2438623b7c | |||
| af69193370 | |||
| 20c169a7b8 | |||
| 87efd44e09 | |||
| e7bba55479 | |||
| 4dcdf588ee | |||
| 4065061d25 | |||
| 60ffb98742 | |||
| d70db906df | |||
| 30bb351de2 | |||
| 0022833380 |
+6
-6
@@ -1,13 +1,13 @@
|
||||
language: objective-c
|
||||
osx_image: xcode8
|
||||
|
||||
xcode_project: OrderedDictionary.xcodeproj
|
||||
xcode_scheme: OrderedDictionary-iOS
|
||||
xcode_sdk: iphonesimulator
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
xcode_project: OrderedDictionary.xcodeproj
|
||||
xcode_scheme: OrderedDictionary-iOS
|
||||
osx_image: xcode7
|
||||
xcode_sdk: iphonesimulator
|
||||
|
||||
script:
|
||||
- xcodebuild clean build test -project OrderedDictionary.xcodeproj -scheme OrderedDictionary-iOS -destination "platform=iOS Simulator,name=iPhone 6,OS=9.0"
|
||||
- xcodebuild clean build test -project OrderedDictionary.xcodeproj -scheme OrderedDictionary-iOS -destination "platform=iOS Simulator,name=iPhone 6s,OS=10.0"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Lukas Kubanek
|
||||
Copyright (c) 2015-2016 Lukas Kubanek
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -60,11 +60,11 @@
|
||||
803F9CD21B92324C002F728F /* OrderedDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrderedDictionary.h; sourceTree = "<group>"; };
|
||||
803F9CD41B92324C002F728F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
803F9CD71B9232EE002F728F /* OrderedDictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderedDictionary.swift; sourceTree = "<group>"; };
|
||||
803F9CEF1B925B1C002F728F /* OrderedDictionary-OSX-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "OrderedDictionary-OSX-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
803F9CEF1B925B1C002F728F /* OrderedDictionary_Mac_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OrderedDictionary_Mac_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
803F9CFC1B925B4C002F728F /* OrderedDictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderedDictionaryTests.swift; sourceTree = "<group>"; };
|
||||
803F9CFE1B925B56002F728F /* Info-Tests.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-Tests.plist"; sourceTree = "<group>"; };
|
||||
806097631B92F20400DB20CF /* OrderedDictionary.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OrderedDictionary.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
806097711B92F44F00DB20CF /* OrderedDictionary-iOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "OrderedDictionary-iOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
806097711B92F44F00DB20CF /* OrderedDictionary_iOS_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OrderedDictionary_iOS_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
80F94F181B926A60000A96E7 /* OrderedDictionary.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = OrderedDictionary.playground; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@@ -106,8 +106,8 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
803F9CD11B92324C002F728F /* Sources */,
|
||||
803F9CFB1B925B4C002F728F /* Tests */,
|
||||
80F94F171B926A60000A96E7 /* Playgrounds */,
|
||||
803F9CFB1B925B4C002F728F /* Tests */,
|
||||
803F9CD31B92324C002F728F /* Supporting Files */,
|
||||
803F9CC71B923207002F728F /* Products */,
|
||||
);
|
||||
@@ -117,9 +117,9 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
803F9CC61B923207002F728F /* OrderedDictionary.framework */,
|
||||
803F9CEF1B925B1C002F728F /* OrderedDictionary-OSX-Tests.xctest */,
|
||||
803F9CEF1B925B1C002F728F /* OrderedDictionary_Mac_Tests.xctest */,
|
||||
806097631B92F20400DB20CF /* OrderedDictionary.framework */,
|
||||
806097711B92F44F00DB20CF /* OrderedDictionary-iOS-Tests.xctest */,
|
||||
806097711B92F44F00DB20CF /* OrderedDictionary_iOS_Tests.xctest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
@@ -180,9 +180,9 @@
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
803F9CC51B923207002F728F /* OrderedDictionary-OSX */ = {
|
||||
803F9CC51B923207002F728F /* OrderedDictionary-Mac */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 803F9CCE1B923207002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-OSX" */;
|
||||
buildConfigurationList = 803F9CCE1B923207002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-Mac" */;
|
||||
buildPhases = (
|
||||
803F9CC11B923207002F728F /* Sources */,
|
||||
803F9CC21B923207002F728F /* Frameworks */,
|
||||
@@ -193,14 +193,14 @@
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "OrderedDictionary-OSX";
|
||||
name = "OrderedDictionary-Mac";
|
||||
productName = OrderedDictionary;
|
||||
productReference = 803F9CC61B923207002F728F /* OrderedDictionary.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
803F9CEE1B925B1C002F728F /* OrderedDictionary-OSX-Tests */ = {
|
||||
803F9CEE1B925B1C002F728F /* OrderedDictionary-Mac-Tests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 803F9CF71B925B1C002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-OSX-Tests" */;
|
||||
buildConfigurationList = 803F9CF71B925B1C002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-Mac-Tests" */;
|
||||
buildPhases = (
|
||||
803F9CEB1B925B1C002F728F /* Sources */,
|
||||
803F9CEC1B925B1C002F728F /* Frameworks */,
|
||||
@@ -212,9 +212,9 @@
|
||||
dependencies = (
|
||||
803F9CF61B925B1C002F728F /* PBXTargetDependency */,
|
||||
);
|
||||
name = "OrderedDictionary-OSX-Tests";
|
||||
name = "OrderedDictionary-Mac-Tests";
|
||||
productName = OrderedDictionaryTests;
|
||||
productReference = 803F9CEF1B925B1C002F728F /* OrderedDictionary-OSX-Tests.xctest */;
|
||||
productReference = 803F9CEF1B925B1C002F728F /* OrderedDictionary_Mac_Tests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
806097621B92F20400DB20CF /* OrderedDictionary-iOS */ = {
|
||||
@@ -251,7 +251,7 @@
|
||||
);
|
||||
name = "OrderedDictionary-iOS-Tests";
|
||||
productName = "OrderedDictionary-iOS-Tests";
|
||||
productReference = 806097711B92F44F00DB20CF /* OrderedDictionary-iOS-Tests.xctest */;
|
||||
productReference = 806097711B92F44F00DB20CF /* OrderedDictionary_iOS_Tests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
@@ -261,20 +261,23 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0700;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Lukas Kubanek";
|
||||
TargetAttributes = {
|
||||
803F9CC51B923207002F728F = {
|
||||
CreatedOnToolsVersion = 7.0;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
803F9CEE1B925B1C002F728F = {
|
||||
CreatedOnToolsVersion = 7.0;
|
||||
};
|
||||
806097621B92F20400DB20CF = {
|
||||
CreatedOnToolsVersion = 7.0;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
806097701B92F44F00DB20CF = {
|
||||
CreatedOnToolsVersion = 7.0;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -290,8 +293,8 @@
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
803F9CC51B923207002F728F /* OrderedDictionary-OSX */,
|
||||
803F9CEE1B925B1C002F728F /* OrderedDictionary-OSX-Tests */,
|
||||
803F9CC51B923207002F728F /* OrderedDictionary-Mac */,
|
||||
803F9CEE1B925B1C002F728F /* OrderedDictionary-Mac-Tests */,
|
||||
806097621B92F20400DB20CF /* OrderedDictionary-iOS */,
|
||||
806097701B92F44F00DB20CF /* OrderedDictionary-iOS-Tests */,
|
||||
);
|
||||
@@ -367,7 +370,7 @@
|
||||
/* Begin PBXTargetDependency section */
|
||||
803F9CF61B925B1C002F728F /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 803F9CC51B923207002F728F /* OrderedDictionary-OSX */;
|
||||
target = 803F9CC51B923207002F728F /* OrderedDictionary-Mac */;
|
||||
targetProxy = 803F9CF51B925B1C002F728F /* PBXContainerItemProxy */;
|
||||
};
|
||||
806097781B92F44F00DB20CF /* PBXTargetDependency */ = {
|
||||
@@ -391,8 +394,10 @@
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
@@ -414,6 +419,7 @@
|
||||
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;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
@@ -437,8 +443,10 @@
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
@@ -454,9 +462,11 @@
|
||||
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;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
@@ -465,6 +475,7 @@
|
||||
803F9CCF1B923207002F728F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
@@ -481,12 +492,14 @@
|
||||
PRODUCT_NAME = OrderedDictionary;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 2.3;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
803F9CD01B923207002F728F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
@@ -502,6 +515,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionary;
|
||||
PRODUCT_NAME = OrderedDictionary;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@@ -513,7 +527,7 @@
|
||||
INFOPLIST_FILE = "Supporting Files/Info-Tests.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionaryTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -525,26 +539,29 @@
|
||||
INFOPLIST_FILE = "Supporting Files/Info-Tests.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionaryTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
806097691B92F20400DB20CF /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = "Supporting Files/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionary;
|
||||
PRODUCT_NAME = OrderedDictionary;
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Debug;
|
||||
@@ -552,19 +569,22 @@
|
||||
8060976A1B92F20400DB20CF /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = "Supporting Files/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionary;
|
||||
PRODUCT_NAME = OrderedDictionary;
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 2.3;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
@@ -578,8 +598,9 @@
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.lukaskubanek.OrderedDictionary-iOS-Tests";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_VERSION = 2.3;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -591,8 +612,9 @@
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.lukaskubanek.OrderedDictionary-iOS-Tests";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_VERSION = 2.3;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
@@ -609,7 +631,7 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
803F9CCE1B923207002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-OSX" */ = {
|
||||
803F9CCE1B923207002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-Mac" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
803F9CCF1B923207002F728F /* Debug */,
|
||||
@@ -618,7 +640,7 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
803F9CF71B925B1C002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-OSX-Tests" */ = {
|
||||
803F9CF71B925B1C002F728F /* Build configuration list for PBXNativeTarget "OrderedDictionary-Mac-Tests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
803F9CF81B925B1C002F728F /* Debug */,
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0700"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -16,7 +16,7 @@
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "803F9CC51B923207002F728F"
|
||||
BuildableName = "OrderedDictionary.framework"
|
||||
BlueprintName = "OrderedDictionary-OSX"
|
||||
BlueprintName = "OrderedDictionary-Mac"
|
||||
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
@@ -34,8 +34,8 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "803F9CEE1B925B1C002F728F"
|
||||
BuildableName = "OrderedDictionary-OSX-Tests.xctest"
|
||||
BlueprintName = "OrderedDictionary-OSX-Tests"
|
||||
BuildableName = "OrderedDictionary_Mac_Tests.xctest"
|
||||
BlueprintName = "OrderedDictionary-Mac-Tests"
|
||||
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
@@ -45,7 +45,7 @@
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "803F9CC51B923207002F728F"
|
||||
BuildableName = "OrderedDictionary.framework"
|
||||
BlueprintName = "OrderedDictionary-OSX"
|
||||
BlueprintName = "OrderedDictionary-Mac"
|
||||
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
@@ -67,7 +67,7 @@
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "803F9CC51B923207002F728F"
|
||||
BuildableName = "OrderedDictionary.framework"
|
||||
BlueprintName = "OrderedDictionary-OSX"
|
||||
BlueprintName = "OrderedDictionary-Mac"
|
||||
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
@@ -85,7 +85,7 @@
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "803F9CC51B923207002F728F"
|
||||
BuildableName = "OrderedDictionary.framework"
|
||||
BlueprintName = "OrderedDictionary-OSX"
|
||||
BlueprintName = "OrderedDictionary-Mac"
|
||||
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0700"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -34,7 +34,7 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "806097701B92F44F00DB20CF"
|
||||
BuildableName = "OrderedDictionary-iOS-Tests.xctest"
|
||||
BuildableName = "OrderedDictionary_iOS_Tests.xctest"
|
||||
BlueprintName = "OrderedDictionary-iOS-Tests"
|
||||
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
|
||||
</BuildableReference>
|
||||
|
||||
@@ -1,87 +1,129 @@
|
||||
// Import the framework
|
||||
import OrderedDictionary
|
||||
|
||||
////
|
||||
// Initialize an ordered dictionary using an array of key-value pairs
|
||||
////
|
||||
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("A", 1),
|
||||
("B", 2),
|
||||
("C", 3),
|
||||
("D", 4)
|
||||
]
|
||||
// ======================================================= //
|
||||
// CONSTRUCTION
|
||||
// ======================================================= //
|
||||
|
||||
// Construct an ordered dictionary using a dictionary literal
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
|
||||
print(orderedDictionary) // => [A: 1, B: 2, C: 3, D: 4]
|
||||
|
||||
////
|
||||
// Loop through the contents
|
||||
////
|
||||
// ======================================================= //
|
||||
// LOOPING
|
||||
// ======================================================= //
|
||||
|
||||
for (index, (key, value)) in orderedDictionary.enumerate() {
|
||||
print("\(index): (\(key): \(value))")
|
||||
// Loop through the ordered dictionary
|
||||
for (key, value) in orderedDictionary {
|
||||
print("[\(key): \(value)]") // => [A: 1], => [B: 2], => [C: 3], => [D: 4]
|
||||
}
|
||||
|
||||
// => 0: (A: 1)
|
||||
// => 1: (B: 2)
|
||||
// => 2: (C: 3)
|
||||
// => 3: (D: 4)
|
||||
// Loop through the ordered dictionary with an additional index
|
||||
for (index, (key, value)) in orderedDictionary.enumerate() {
|
||||
print("(\(index): [\(key): \(value)])") // => (0: [A: 1]), => (1: [B: 2]), => (2: [C: 3]), => (3: [D: 4])
|
||||
}
|
||||
|
||||
////
|
||||
// Modify the values by setting the value for key
|
||||
////
|
||||
// ======================================================= //
|
||||
// ACCESSING CONTENT
|
||||
// ======================================================= //
|
||||
|
||||
// Access the value for an existing key using subscript
|
||||
print(orderedDictionary["A"]) // => Optional(1)
|
||||
|
||||
// Access the value for a non-existent key
|
||||
print(orderedDictionary["X"]) // => nil
|
||||
|
||||
// Access the value for a key using method
|
||||
print(orderedDictionary.valueForKey("A")) // => Optional(1)
|
||||
|
||||
// Access the value for a non-existent key
|
||||
print(orderedDictionary.valueForKey("X")) // => nil
|
||||
|
||||
// Access the key-value pair (element) at an existing index
|
||||
print(orderedDictionary[2]) // => ("C", 3)
|
||||
|
||||
// Access the key-value pair (element) at a non-existent index
|
||||
//print(orderedDictionary[10]) // => fatal error
|
||||
|
||||
// Get the index for an existing key
|
||||
print(orderedDictionary.indexForKey("D")) // => Optional(3)
|
||||
|
||||
// ======================================================= //
|
||||
// MODIFYING CONTENT USING KEYS
|
||||
// ======================================================= //
|
||||
|
||||
// Modify the value for an existing key using subscript
|
||||
orderedDictionary["A"] = 100
|
||||
orderedDictionary["E"] = 5
|
||||
orderedDictionary["B"] = nil
|
||||
orderedDictionary.updateValue(42, forKey: "D")
|
||||
print(orderedDictionary["A"]) // => Optional(100)
|
||||
|
||||
// Modify the value for an existing key using method
|
||||
orderedDictionary.updateValue(42, forKey: "D")
|
||||
print(orderedDictionary["D"]) // => Optional(42)
|
||||
|
||||
// Set a value for an non-existent key
|
||||
orderedDictionary["E"] = 5
|
||||
print(orderedDictionary) // => [A: 100, B: 2, C: 3, D: 42, E: 5]
|
||||
|
||||
// Set nil value for an existing key
|
||||
orderedDictionary["B"] = nil
|
||||
print(orderedDictionary["B"]) // => nil
|
||||
print(orderedDictionary) // => [A: 100, C: 3, D: 42, E: 5]
|
||||
|
||||
print(orderedDictionary["A"]) // => Optional(100)
|
||||
print(orderedDictionary["B"]) // => nil
|
||||
print(orderedDictionary["C"]) // => Optional(3)
|
||||
print(orderedDictionary["D"]) // => Optional(42)
|
||||
print(orderedDictionary["E"]) // => Optional(5)
|
||||
|
||||
////
|
||||
// Modify the values by setting the element for index
|
||||
////
|
||||
// ======================================================= //
|
||||
// MODIFYING CONTENT USING INDEXES
|
||||
// ======================================================= //
|
||||
|
||||
// Modify the existing element at index using subscript
|
||||
orderedDictionary[2] = ("F", 235)
|
||||
orderedDictionary.updateElement(("K", 12), atIndex: 1)
|
||||
orderedDictionary.removeAtIndex(0)
|
||||
print(orderedDictionary[2]) // => ("F", 235)
|
||||
print(orderedDictionary) // => [A: 100, C: 3, F: 235, E: 5]
|
||||
|
||||
print(orderedDictionary) // => [K: 12, F: 235, E: 5]
|
||||
// Modify the existing element at index using method
|
||||
let previousElement = orderedDictionary.updateElement(("K", 12), atIndex: 1)
|
||||
print(orderedDictionary[1]) // => ("K", 12)
|
||||
print(previousElement) // => Optional("C", 3)
|
||||
print(orderedDictionary) // => [A: 100, K: 12, F: 235, E: 5]
|
||||
|
||||
print(orderedDictionary[0]) // => ("K", 12)
|
||||
print(orderedDictionary[1]) // => ("F", 235)
|
||||
print(orderedDictionary[2]) // => ("E", 5)
|
||||
// print(orderedDictionary[3]) // => fatal error
|
||||
// Set an element to a non-existent index
|
||||
//orderedDictionary[100] = ("L", 0) // => fatal error
|
||||
|
||||
print(orderedDictionary.indexForKey("K")) // => Optional(0)
|
||||
print(orderedDictionary.indexForKey("F")) // => Optional(1)
|
||||
print(orderedDictionary.indexForKey("E")) // => Optional(2)
|
||||
print(orderedDictionary.indexForKey("A")) // => nil
|
||||
print(orderedDictionary.indexForKey("C")) // => nil
|
||||
// ======================================================= //
|
||||
// SORTING
|
||||
// ======================================================= //
|
||||
|
||||
////
|
||||
// Sorting
|
||||
////
|
||||
|
||||
var sortingOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("E", 4),
|
||||
("G", 3),
|
||||
("A", 3),
|
||||
("D", 1),
|
||||
("B", 4)
|
||||
]
|
||||
|
||||
sortingOrderedDictionary.sortInPlace { (item1, item2) in
|
||||
if item1.1 == item2.1 {
|
||||
return item1.0 < item2.0
|
||||
// Sort the ordered dictionary using a closure
|
||||
orderedDictionary.sortInPlace { (element1: (key: String, value: Int), element2: (key: String, value: Int)) -> Bool in
|
||||
if element1.value == element2.value {
|
||||
return element1.key < element2.key
|
||||
} else {
|
||||
return item1.1 < item2.1
|
||||
return element1.value < element2.value
|
||||
}
|
||||
}
|
||||
print(orderedDictionary) // => [E: 5, K: 12, A: 100, F: 235]
|
||||
|
||||
print(sortingOrderedDictionary) // => [D: 1, A: 3, G: 3, B: 4, E: 4]
|
||||
// ======================================================= //
|
||||
// REMOVING CONTENT
|
||||
// ======================================================= //
|
||||
|
||||
// Remove value for an existing key
|
||||
let removedValue = orderedDictionary.removeValueForKey("F")
|
||||
print(removedValue) // => Optional(235)
|
||||
print(orderedDictionary["F"]) // => nil
|
||||
print(orderedDictionary) // => [E: 5, K: 12, A: 100]
|
||||
|
||||
// Remove value for a non-existent key
|
||||
orderedDictionary.removeValueForKey("X")
|
||||
print(orderedDictionary) // => [E: 5, K: 12, A: 100]
|
||||
|
||||
// Remove element at an existing index
|
||||
let removedElement = orderedDictionary.removeAtIndex(1)
|
||||
print(removedElement) // => Optional((K, 12))
|
||||
print(orderedDictionary) // => [E: 5, A: 100]
|
||||
|
||||
// Remove element at a non-existent index
|
||||
orderedDictionary.removeAtIndex(42)
|
||||
print(orderedDictionary) // => [E: 5, A: 100]
|
||||
|
||||
// Remove all elements
|
||||
orderedDictionary.removeAll()
|
||||
print(orderedDictionary) // => [:]
|
||||
|
||||
@@ -2,121 +2,45 @@
|
||||
|
||||
[![][image-1]][1] [![][image-2]][2] [![][image-3]][3] ![][image-4] [![][image-5]][4] [![][image-6]][5]
|
||||
|
||||
This is a lightweight implementation of an ordered dictionary data structure in Swift packed into a µframework.
|
||||
**OrderedDictionary** is a lightweight implementation of an ordered dictionary data structure in Swift.
|
||||
|
||||
`OrderedDictionary` is an immutable generic collection which combines the features of `Dictionary` and `Array`. Like `Dictionary` it stores key-value pairs and maps the keys to values. Additionally these pairs are sorted by zero-based integer index like in `Array`. The `OrderedDictionary` provides similar APIs to the collections from the Swift standard library, allows accessing the content by keys or indexes and sorting.
|
||||
The `OrderedDictionary` structure is an immutable generic collection which combines the features of `Dictionary` and `Array` from the Swift standard library. Like `Dictionary` it stores key-value pairs and maps each key to a value. Like `Array` it stores those pairs sorted and accessible by a zero-based integer index.
|
||||
|
||||
Internally `OrderedDictionary` uses a backing store composed of an instance of `Dictionary` for storing the key-value pairs and an instance of `Array` for managing the ordered keys.
|
||||
`OrderedDictionary` provides similar APIs like collections in the Swift standard library. This includes accessing contents by keys or indexes, inserting and removing elements, iterating, sorting etc.
|
||||
|
||||
Internally `OrderedDictionary` uses a backing store composed of an instance of `Dictionary` for storing the key-value pairs and an instance of `Array` for managing the ordered keys. This means it is not the most performant implementation possible, but it gets its job done by reusing most functionality from the Swift standard library.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Swift 2.0+
|
||||
- Xcode 7.0+
|
||||
- Swift 2.3
|
||||
- Xcode 8
|
||||
- iOS 8.0+ / OS X 10.10+
|
||||
|
||||
## Installation
|
||||
|
||||
This library is distributed as a Swift framework and can be integrated into your project in following ways:
|
||||
|
||||
### Carthage
|
||||
|
||||
The easiest way to integrate this framework in your project is to use [Carthage](https://github.com/Carthage/Carthage/).
|
||||
The easiest way is to use the package manager [Carthage][6].
|
||||
|
||||
1. Add `github "lukaskubanek/OrderedDictionary" ~> 0.4` to your `Cartfile`.
|
||||
1. Add `github "lukaskubanek/OrderedDictionary"` to your `Cartfile`.
|
||||
2. Run `carthage bootstrap`.
|
||||
3. Drag either the `OrderedDictionary.xcodeproj` or the `LoremSwiftum.framework` into your project/workspace and link your target against the `OrderedDictionary.framework`.
|
||||
4. Make sure the framework [gets copied](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to your application bundle.
|
||||
3. Drag either the `OrderedDictionary.xcodeproj` or the `OrderedDictionary.framework` into your project/workspace and link your target against the `OrderedDictionary.framework`.
|
||||
4. Make sure the framework [gets copied][7] to your application bundle.
|
||||
5. Import the framework using `import OrderedDictionary`.
|
||||
|
||||
### Submodules
|
||||
### Submodule & Xcode Project
|
||||
|
||||
Another option for integrating this framework is to use [Git submodules](http://git-scm.com/book/en/v2/Git-Tools-Submodules).
|
||||
Another option is to use [Git submodules][8] and integrating the Xcode project `OrderedDictionary.xcodeproj` directly to your Xcode workspace.
|
||||
|
||||
## Example Usage
|
||||
## Usage
|
||||
|
||||
Initialization:
|
||||
For the usage of this library please refer to the [example playground][9].
|
||||
|
||||
```swift
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("A", 1),
|
||||
("B", 2),
|
||||
("C", 3),
|
||||
("D", 4)
|
||||
]
|
||||
## Changelog
|
||||
|
||||
print(orderedDictionary) // => [A: 1, B: 2, C: 3, D: 4]
|
||||
```
|
||||
|
||||
Looping throug the contents:
|
||||
|
||||
```swift
|
||||
for (index, (key, value)) in orderedDictionary.enumerate() {
|
||||
print("\(index): (\(key): \(value))")
|
||||
}
|
||||
|
||||
// => 0: (A: 1)
|
||||
// => 1: (B: 2)
|
||||
// => 2: (C: 3)
|
||||
// => 3: (D: 4)
|
||||
```
|
||||
|
||||
Modifying the values by setting the value for key:
|
||||
|
||||
```swift
|
||||
orderedDictionary["A"] = 100
|
||||
orderedDictionary["E"] = 5
|
||||
orderedDictionary["B"] = nil
|
||||
orderedDictionary.updateValue(42, forKey: "D")
|
||||
|
||||
print(orderedDictionary) // => [A: 100, C: 3, D: 42, E: 5]
|
||||
|
||||
print(orderedDictionary["A"]) // => Optional(100)
|
||||
print(orderedDictionary["B"]) // => nil
|
||||
print(orderedDictionary["C"]) // => Optional(3)
|
||||
print(orderedDictionary["D"]) // => Optional(42)
|
||||
print(orderedDictionary["E"]) // => Optional(5)
|
||||
```
|
||||
|
||||
Modifying the values by setting the element for index:
|
||||
|
||||
```swift
|
||||
orderedDictionary[2] = ("F", 235)
|
||||
orderedDictionary.updateElement(("K", 12), atIndex: 1)
|
||||
orderedDictionary.removeAtIndex(0)
|
||||
|
||||
print(orderedDictionary) // => [K: 12, F: 235, E: 5]
|
||||
|
||||
print(orderedDictionary[0]) // => ("K", 12)
|
||||
print(orderedDictionary[1]) // => ("F", 235)
|
||||
print(orderedDictionary[2]) // => ("E", 5)
|
||||
// print(orderedDictionary[3]) // => fatal error
|
||||
|
||||
print(orderedDictionary.indexForKey("K")) // => Optional(0)
|
||||
print(orderedDictionary.indexForKey("F")) // => Optional(1)
|
||||
print(orderedDictionary.indexForKey("E")) // => Optional(2)
|
||||
print(orderedDictionary.indexForKey("A")) // => nil
|
||||
print(orderedDictionary.indexForKey("C")) // => nil
|
||||
```
|
||||
|
||||
Sorting:
|
||||
|
||||
```swift
|
||||
var sortingOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("E", 4),
|
||||
("G", 3),
|
||||
("A", 3),
|
||||
("D", 1),
|
||||
("B", 4)
|
||||
]
|
||||
|
||||
sortingOrderedDictionary.sortInPlace { (item1, item2) in
|
||||
if item1.1 == item2.1 {
|
||||
return item1.0 < item2.0
|
||||
} else {
|
||||
return item1.1 < item2.1
|
||||
}
|
||||
}
|
||||
|
||||
print(sortingOrderedDictionary) // => [D: 1, A: 3, G: 3, B: 4, E: 4]
|
||||
|
||||
```
|
||||
The changelog is managed on the [GitHub releases page][10].
|
||||
|
||||
## Author
|
||||
|
||||
@@ -124,25 +48,25 @@ Lukas Kubanek // [lukaskubanek.com][11] // [@kubanekl][12]
|
||||
|
||||
## License
|
||||
|
||||
`OrderedDictionary` is released under the [MIT License][13].
|
||||
**OrderedDictionary** is provided under the [MIT License][13].
|
||||
|
||||
[1]: https://travis-ci.org/lukaskubanek/OrderedDictionary
|
||||
[2]: https://github.com/lukaskubanek/OrderedDictionary/releases
|
||||
[3]: https://developer.apple.com/swift/
|
||||
[4]: https://github.com/Carthage/Carthage
|
||||
[5]: LICENSE.md
|
||||
[6]: https://github.com/Carthage/Carthage/
|
||||
[7]: https://developer.apple.com/swift/
|
||||
[8]: https://github.com/lukaskubanek/OrderedDictionary/releases
|
||||
[9]: https://developer.apple.com/swift/
|
||||
[10]: https://github.com/Carthage/Carthage
|
||||
[6]: https://github.com/Carthage/Carthage
|
||||
[7]: https://github.com/Carthage/Carthage#adding-frameworks-to-an-application
|
||||
[8]: http://git-scm.com/book/en/v2/Git-Tools-Submodules
|
||||
[9]: Playgrounds/OrderedDictionary.playground/Contents.swift
|
||||
[10]: https://github.com/lukaskubanek/OrderedDictionary/releases
|
||||
[11]: http://lukaskubanek.com
|
||||
[12]: https://twitter.com/kubanekl
|
||||
[13]: LICENSE.md
|
||||
|
||||
[image-1]: https://img.shields.io/travis/lukaskubanek/OrderedDictionary.svg?style=flat-square
|
||||
[image-1]: https://img.shields.io/travis/lukaskubanek/OrderedDictionary.svg?style=flat-square "Build"
|
||||
[image-2]: https://img.shields.io/github/release/lukaskubanek/OrderedDictionary.svg?style=flat-square
|
||||
[image-3]: https://img.shields.io/badge/Swift-2.0-orange.svg?style=flat-square
|
||||
[image-4]: https://img.shields.io/badge/platform-OS_X%20&_iOS-yellowgreen.svg?style=flat-square
|
||||
[image-3]: https://img.shields.io/badge/Swift-2.3-orange.svg?style=flat-square "Swift 2.2"
|
||||
[image-4]: https://img.shields.io/badge/platform-macOS/iOS-yellowgreen.svg?style=flat-square "Platform: OS X, iOS"
|
||||
[image-5]: https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square "Carthage compatible"
|
||||
[image-6]: https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat-square "License"
|
||||
[image-6]: https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat-square "License: MIT"
|
||||
@@ -5,6 +5,3 @@
|
||||
// Created by Lukas Kubanek on 29/08/15.
|
||||
// Copyright © 2015 Lukas Kubanek. All rights reserved.
|
||||
//
|
||||
|
||||
extern double OrderedDictionaryVersionNumber;
|
||||
extern const unsigned char OrderedDictionaryVersionString[];
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// Copyright © 2015 Lukas Kubanek. All rights reserved.
|
||||
//
|
||||
|
||||
public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, ArrayLiteralConvertible, CustomStringConvertible {
|
||||
public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType {
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Type Aliases
|
||||
@@ -23,15 +23,11 @@ public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, Ar
|
||||
public init() {}
|
||||
|
||||
public init(elements: [Element]) {
|
||||
for element in elements {
|
||||
self[element.0] = element.1
|
||||
for (key, value) in elements {
|
||||
self[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
public init(arrayLiteral elements: Element...) {
|
||||
self.init(elements: elements)
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Accessing Keys & Values
|
||||
// ======================================================= //
|
||||
@@ -50,7 +46,7 @@ public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, Ar
|
||||
|
||||
public subscript(key: Key) -> Value? {
|
||||
get {
|
||||
return _keysToValues[key]
|
||||
return valueForKey(key)
|
||||
}
|
||||
set(newValue) {
|
||||
if let newValue = newValue {
|
||||
@@ -65,6 +61,10 @@ public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, Ar
|
||||
return _orderedKeys.contains(key)
|
||||
}
|
||||
|
||||
public func valueForKey(key: Key) -> Value? {
|
||||
return _keysToValues[key]
|
||||
}
|
||||
|
||||
public mutating func updateValue(value: Value, forKey key: Key) -> Value? {
|
||||
if _orderedKeys.contains(key) {
|
||||
guard let currentValue = _keysToValues[key] else {
|
||||
@@ -148,7 +148,7 @@ public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, Ar
|
||||
fatalError("OrderedDictionary index out of range")
|
||||
}
|
||||
|
||||
let (key, value) = (newElement.0, newElement.1)
|
||||
let (key, value) = newElement
|
||||
|
||||
let adjustedIndex: Int
|
||||
let currentValue: Value?
|
||||
@@ -175,7 +175,7 @@ public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, Ar
|
||||
fatalError("OrderedDictionary index out of range")
|
||||
}
|
||||
|
||||
let (newKey, newValue) = (element.0, element.1)
|
||||
let (newKey, newValue) = element
|
||||
|
||||
_orderedKeys[index] = newKey
|
||||
_keysToValues[newKey] = newValue
|
||||
@@ -195,49 +195,9 @@ public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, Ar
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Description
|
||||
// MARK: - CollectionType Conformance
|
||||
// ======================================================= //
|
||||
|
||||
public var description: String {
|
||||
let content = map({ "\($0.0): \($0.1)" }).joinWithSeparator(", ")
|
||||
return "[\(content)]"
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Backing Store
|
||||
// ======================================================= //
|
||||
|
||||
/// The backing store for the ordered keys.
|
||||
private var _orderedKeys = [Key]()
|
||||
|
||||
/// The backing store for the mapping of keys to values.
|
||||
private var _keysToValues = [Key: Value]()
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - SequenceType & Indexable Conformance
|
||||
// ======================================================= //
|
||||
|
||||
public func generate() -> AnyGenerator<Element> {
|
||||
var nextIndex = 0
|
||||
let lastIndex = self.count
|
||||
|
||||
return anyGenerator {
|
||||
guard nextIndex < lastIndex else { return nil }
|
||||
|
||||
let nextKey = self._orderedKeys[nextIndex]
|
||||
|
||||
guard let nextValue = self._keysToValues[nextKey] else {
|
||||
fatalError("Inconsistency error occured in OrderedDictionary")
|
||||
}
|
||||
|
||||
let element = (nextKey, nextValue)
|
||||
|
||||
nextIndex++
|
||||
|
||||
return element
|
||||
}
|
||||
}
|
||||
|
||||
public var startIndex: Index {
|
||||
return _orderedKeys.startIndex
|
||||
}
|
||||
@@ -246,6 +206,79 @@ public struct OrderedDictionary<Key: Hashable, Value>: MutableCollectionType, Ar
|
||||
return _orderedKeys.endIndex
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Internal Backing Store
|
||||
// ======================================================= //
|
||||
|
||||
/// The backing store for the ordered keys.
|
||||
private var _orderedKeys = [Key]()
|
||||
|
||||
/// The backing store for the mapping of keys to values.
|
||||
private var _keysToValues = [Key: Value]()
|
||||
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Initializations from Literals
|
||||
// ======================================================= //
|
||||
|
||||
extension OrderedDictionary: ArrayLiteralConvertible {
|
||||
|
||||
public init(arrayLiteral elements: Element...) {
|
||||
self.init(elements: elements)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension OrderedDictionary: DictionaryLiteralConvertible {
|
||||
|
||||
public init(dictionaryLiteral elements: Element...) {
|
||||
self.init(elements: elements)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Description
|
||||
// ======================================================= //
|
||||
|
||||
extension OrderedDictionary: CustomStringConvertible, CustomDebugStringConvertible {
|
||||
|
||||
public var description: String {
|
||||
return constructDescription(debug: false)
|
||||
}
|
||||
|
||||
public var debugDescription: String {
|
||||
return constructDescription(debug: true)
|
||||
}
|
||||
|
||||
private func constructDescription(debug debug: Bool) -> String {
|
||||
// The implementation of the description is inspired by zwaldowski's implementation of the ordered dictionary.
|
||||
// See http://bit.ly/1VL4JUR
|
||||
|
||||
if isEmpty { return "[:]" }
|
||||
|
||||
func descriptionForItem(item: Any) -> String {
|
||||
var description = ""
|
||||
|
||||
if debug {
|
||||
debugPrint(item, separator: "", terminator: "", toStream: &description)
|
||||
} else {
|
||||
print(item, separator: "", terminator: "", toStream: &description)
|
||||
}
|
||||
|
||||
return description
|
||||
}
|
||||
|
||||
let bodyComponents = map({ (key: Key, value: Value) -> String in
|
||||
return descriptionForItem(key) + ": " + descriptionForItem(value)
|
||||
})
|
||||
|
||||
let body = bodyComponents.joinWithSeparator(", ")
|
||||
|
||||
return "[\(body)]"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public func == <Key: Equatable, Value: Equatable>(lhs: OrderedDictionary<Key, Value>, rhs: OrderedDictionary<Key, Value>) -> Bool {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.1</string>
|
||||
<string>0.5</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
+158
-135
@@ -11,63 +11,125 @@ import OrderedDictionary
|
||||
|
||||
class OrderedDictionaryTests: XCTestCase {
|
||||
|
||||
var orderedDictionary: OrderedDictionary<String, Int>!
|
||||
// ======================================================= //
|
||||
// MARK: - Initialization
|
||||
// ======================================================= //
|
||||
|
||||
override func setUp() {
|
||||
orderedDictionary = [
|
||||
("A", 1),
|
||||
("B", 2),
|
||||
("C", 3)
|
||||
]
|
||||
func testInitializationUsingArrayLiteral() {
|
||||
let expected = OrderedDictionary<String, Int>(elements: [("A", 1), ("B", 2), ("C", 3)])
|
||||
let actual: OrderedDictionary<String, Int> = [("A", 1), ("B", 2), ("C", 3)]
|
||||
|
||||
XCTAssertTrue(expected == actual)
|
||||
}
|
||||
|
||||
func testInitializationUsingDictionaryLiteral() {
|
||||
let expected = OrderedDictionary<String, Int>(elements: [("A", 1), ("B", 2), ("C", 3)])
|
||||
let actual: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
XCTAssertTrue(expected == actual)
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Content
|
||||
// MARK: - Description
|
||||
// ======================================================= //
|
||||
|
||||
func testInitializedContent() {
|
||||
struct DescribedValue: CustomStringConvertible, CustomDebugStringConvertible {
|
||||
init(_ value: Int) { self.value = value }
|
||||
let value: Int
|
||||
var description: String { return "\(value)" }
|
||||
var debugDescription: String { return "debug(\(value))" }
|
||||
}
|
||||
|
||||
func testDescription() {
|
||||
let expected = "[A: 1, B: 2, C: 3]"
|
||||
|
||||
let orderedDictionary: OrderedDictionary<String, DescribedValue> = ["A": DescribedValue(1), "B": DescribedValue(2), "C": DescribedValue(3)]
|
||||
let actual = orderedDictionary.description
|
||||
|
||||
XCTAssertEqual(expected, actual)
|
||||
}
|
||||
|
||||
func testDebugDescription() {
|
||||
let expected = "[\"A\": debug(1), \"B\": debug(2), \"C\": debug(3)]"
|
||||
|
||||
let orderedDictionary: OrderedDictionary<String, DescribedValue> = ["A": DescribedValue(1), "B": DescribedValue(2), "C": DescribedValue(3)]
|
||||
let actual = orderedDictionary.debugDescription
|
||||
|
||||
XCTAssertEqual(expected, actual)
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Content Access
|
||||
// ======================================================= //
|
||||
|
||||
func testAccessingContent() {
|
||||
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
XCTAssertEqual(orderedDictionary.count, 3)
|
||||
|
||||
XCTAssertEqual(orderedDictionary["A"], 1)
|
||||
XCTAssertEqual(orderedDictionary.valueForKey("A"), 1)
|
||||
XCTAssertEqual(orderedDictionary.indexForKey("A"), 0)
|
||||
XCTAssertTrue(orderedDictionary.containsKey("A"))
|
||||
XCTAssertTrue(orderedDictionary[0] == ("A", 1))
|
||||
|
||||
XCTAssertEqual(orderedDictionary["B"], 2)
|
||||
XCTAssertEqual(orderedDictionary.valueForKey("B"), 2)
|
||||
XCTAssertEqual(orderedDictionary.indexForKey("B"), 1)
|
||||
XCTAssertTrue(orderedDictionary.containsKey("B"))
|
||||
XCTAssertTrue(orderedDictionary[1] == ("B", 2))
|
||||
|
||||
XCTAssertEqual(orderedDictionary["C"], 3)
|
||||
XCTAssertEqual(orderedDictionary.valueForKey("C"), 3)
|
||||
XCTAssertEqual(orderedDictionary.indexForKey("C"), 2)
|
||||
XCTAssertTrue(orderedDictionary.containsKey("C"))
|
||||
XCTAssertTrue(orderedDictionary[2] == ("C", 3))
|
||||
}
|
||||
|
||||
func testInitializationUsingPairs() {
|
||||
let elements = [
|
||||
("A", 1),
|
||||
("B", 2),
|
||||
("C", 3)
|
||||
]
|
||||
func testGenerator() {
|
||||
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
var generator = orderedDictionary.generate()
|
||||
|
||||
XCTAssertTrue(OrderedDictionary(elements: elements) == orderedDictionary)
|
||||
}
|
||||
|
||||
func testElementsGenerator() {
|
||||
for entry in orderedDictionary.enumerate() {
|
||||
XCTAssertEqual(orderedDictionary[entry.index].0, entry.element.0)
|
||||
XCTAssertEqual(orderedDictionary[entry.index].1, entry.element.1)
|
||||
let indexes = [0, 1, 2]
|
||||
var indexesGenerator = indexes.generate()
|
||||
|
||||
while let (actualKey, actualValue) = generator.next() {
|
||||
let index = indexesGenerator.next()
|
||||
let (expectedKey, expectedValue) = orderedDictionary[index!]
|
||||
|
||||
XCTAssertEqual(expectedKey, actualKey)
|
||||
XCTAssertEqual(expectedValue, actualValue)
|
||||
}
|
||||
|
||||
XCTAssertNil(generator.next())
|
||||
XCTAssertNil(indexesGenerator.next())
|
||||
}
|
||||
|
||||
func testOrderedKeysAndValues() {
|
||||
XCTAssertEqual(orderedDictionary.orderedKeys, ["A", "B", "C"])
|
||||
XCTAssertEqual(orderedDictionary.orderedValues, [1, 2, 3])
|
||||
func testOrderedKeys() {
|
||||
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
let expected = ["A", "B", "C"]
|
||||
let actual = orderedDictionary.orderedKeys
|
||||
|
||||
XCTAssertEqual(expected, actual)
|
||||
}
|
||||
|
||||
func testOrderedValues() {
|
||||
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
let expected = [1, 2, 3]
|
||||
let actual = orderedDictionary.orderedValues
|
||||
|
||||
XCTAssertEqual(expected, actual)
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Key-based Modifications
|
||||
// MARK: - Content Modifications
|
||||
// ======================================================= //
|
||||
|
||||
func testKeyBasedSubscript() {
|
||||
func testKeyBasedModifications() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
orderedDictionary["A"] = 5
|
||||
orderedDictionary["D"] = 10
|
||||
orderedDictionary["B"] = nil
|
||||
@@ -91,117 +153,90 @@ class OrderedDictionaryTests: XCTestCase {
|
||||
XCTAssertTrue(orderedDictionary.containsKey("D"))
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Index-based Modifications
|
||||
// ======================================================= //
|
||||
|
||||
func testIndexBasedSubscriptForRetrievingValues() {
|
||||
let elementAtIndex0 = orderedDictionary[0]
|
||||
XCTAssertEqual(elementAtIndex0.0, "A")
|
||||
XCTAssertEqual(elementAtIndex0.1, 1)
|
||||
func testIndexBasedModifications() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
let elementAtIndex1 = orderedDictionary[1]
|
||||
XCTAssertEqual(elementAtIndex1.0, "B")
|
||||
XCTAssertEqual(elementAtIndex1.1, 2)
|
||||
|
||||
let elementAtIndex2 = orderedDictionary[2]
|
||||
XCTAssertEqual(elementAtIndex2.0, "C")
|
||||
XCTAssertEqual(elementAtIndex2.1, 3)
|
||||
}
|
||||
|
||||
func testIndexBasedSubscriptForSettingValues() {
|
||||
orderedDictionary[0] = ("F", 10)
|
||||
orderedDictionary[1] = ("B", 5)
|
||||
|
||||
let elementAtIndex0 = orderedDictionary[0]
|
||||
XCTAssertEqual(elementAtIndex0.0, "F")
|
||||
XCTAssertEqual(elementAtIndex0.1, 10)
|
||||
|
||||
let elementAtIndex1 = orderedDictionary[1]
|
||||
XCTAssertEqual(elementAtIndex1.0, "B")
|
||||
XCTAssertEqual(elementAtIndex1.1, 5)
|
||||
|
||||
let elementAtIndex2 = orderedDictionary[2]
|
||||
XCTAssertEqual(elementAtIndex2.0, "C")
|
||||
XCTAssertEqual(elementAtIndex2.1, 3)
|
||||
XCTAssertEqual(orderedDictionary.count, 3)
|
||||
XCTAssertTrue(orderedDictionary[0] == ("F", 10))
|
||||
XCTAssertTrue(orderedDictionary[1] == ("B", 5))
|
||||
XCTAssertTrue(orderedDictionary[2] == ("C", 3))
|
||||
}
|
||||
|
||||
func testRetrievingElementAtNonExistentIndex() {
|
||||
XCTAssertNil(orderedDictionary.elementAtIndex(10))
|
||||
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
XCTAssertNil(orderedDictionary.elementAtIndex(42))
|
||||
}
|
||||
|
||||
func testIndexBasedInsertionsOfElementsWithDistinctKeys() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
orderedDictionary.insertElement(("T", 15), atIndex: 0)
|
||||
orderedDictionary.insertElement(("U", 16), atIndex: 2)
|
||||
orderedDictionary.insertElement(("V", 17), atIndex: 5)
|
||||
orderedDictionary.insertElement(("W", 18), atIndex: 2)
|
||||
|
||||
let XCTAssertEqualedOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("T", 15),
|
||||
("A", 1),
|
||||
("W", 18),
|
||||
("U", 16),
|
||||
("B", 2),
|
||||
("C", 3),
|
||||
("V", 17)
|
||||
]
|
||||
let expected: OrderedDictionary<String, Int> = ["T": 15, "A": 1, "W": 18, "U": 16, "B": 2, "C": 3, "V": 17]
|
||||
let actual = orderedDictionary
|
||||
|
||||
XCTAssertTrue(orderedDictionary == XCTAssertEqualedOrderedDictionary)
|
||||
XCTAssertTrue(expected == actual)
|
||||
}
|
||||
|
||||
func testIndexBasedInsertionOfElementWithSameKeyBeforeItsCurrentIndex() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
let previousValue = orderedDictionary.insertElement(("B", 5), atIndex: 0)
|
||||
|
||||
let expectedOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("B", 5),
|
||||
("A", 1),
|
||||
("C", 3)
|
||||
]
|
||||
|
||||
XCTAssertEqual(orderedDictionary.count, 3)
|
||||
XCTAssertTrue(orderedDictionary == expectedOrderedDictionary)
|
||||
XCTAssertEqual(previousValue, 2)
|
||||
|
||||
let expected: OrderedDictionary<String, Int> = ["B": 5, "A": 1, "C": 3]
|
||||
let actual = orderedDictionary
|
||||
|
||||
XCTAssertTrue(expected == actual)
|
||||
}
|
||||
|
||||
func testIndexBasedInsertionOfElementWithSameKeyAtItsCurrentIndex() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
let previousValue = orderedDictionary.insertElement(("B", 5), atIndex: 1)
|
||||
|
||||
let expectedOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("A", 1),
|
||||
("B", 5),
|
||||
("C", 3)
|
||||
]
|
||||
|
||||
XCTAssertEqual(orderedDictionary.count, 3)
|
||||
XCTAssertTrue(orderedDictionary == expectedOrderedDictionary)
|
||||
XCTAssertEqual(previousValue, 2)
|
||||
|
||||
let expected: OrderedDictionary<String, Int> = ["A": 1, "B": 5, "C": 3]
|
||||
let actual = orderedDictionary
|
||||
|
||||
XCTAssertTrue(expected == actual)
|
||||
}
|
||||
|
||||
func testIndexBasedInsertionOfElementWithSameKeyAfterItsCurrentIndex() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
let previousValue = orderedDictionary.insertElement(("B", 5), atIndex: 3)
|
||||
|
||||
let expectedOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("A", 1),
|
||||
("C", 3),
|
||||
("B", 5)
|
||||
]
|
||||
|
||||
XCTAssertEqual(orderedDictionary.count, 3)
|
||||
XCTAssertTrue(orderedDictionary == expectedOrderedDictionary)
|
||||
XCTAssertEqual(previousValue, 2)
|
||||
|
||||
let expected: OrderedDictionary<String, Int> = ["A": 1, "C": 3, "B": 5]
|
||||
let actual = orderedDictionary
|
||||
|
||||
XCTAssertTrue(expected == actual)
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Removal
|
||||
// MARK: - Content Removal
|
||||
// ======================================================= //
|
||||
|
||||
func testRemoveAll() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
orderedDictionary.removeAll()
|
||||
|
||||
XCTAssertEqual(orderedDictionary.count, 0)
|
||||
}
|
||||
|
||||
func testRemovalForKey() {
|
||||
func testKeyBasedRemoval() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
|
||||
|
||||
let removedValue1 = orderedDictionary.removeValueForKey("A")
|
||||
let removedValue2 = orderedDictionary.removeValueForKey("K")
|
||||
|
||||
@@ -218,27 +253,31 @@ class OrderedDictionaryTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(orderedDictionary["C"], 3)
|
||||
XCTAssertEqual(orderedDictionary.indexForKey("C"), 1)
|
||||
|
||||
}
|
||||
|
||||
func testRemovalAtIndex() {
|
||||
let removedElement1 = orderedDictionary.removeAtIndex(1)
|
||||
let removedElement2 = orderedDictionary.removeAtIndex(0)
|
||||
let removedElement3 = orderedDictionary.removeAtIndex(5)
|
||||
func testIndexBasedRemoval() {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
|
||||
|
||||
XCTAssertEqual(removedElement1?.0, "B")
|
||||
XCTAssertEqual(removedElement1?.1, 2)
|
||||
let (expectedKey1, expectedValue1) = ("A", 1)
|
||||
let (actualKey1, actualValue1) = orderedDictionary.removeAtIndex(0)!
|
||||
|
||||
XCTAssertEqual(removedElement2?.0, "A")
|
||||
XCTAssertEqual(removedElement2?.1, 1)
|
||||
XCTAssertEqual(expectedKey1, actualKey1)
|
||||
XCTAssertEqual(expectedValue1, actualValue1)
|
||||
|
||||
XCTAssertNil(removedElement3)
|
||||
let (expectedKey2, expectedValue2) = ("D", 4)
|
||||
let (actualKey2, actualValue2) = orderedDictionary.removeAtIndex(2)!
|
||||
|
||||
XCTAssertEqual(orderedDictionary.count, 1)
|
||||
XCTAssertEqual(expectedKey2, actualKey2)
|
||||
XCTAssertEqual(expectedValue2, actualValue2)
|
||||
|
||||
let elementAtIndex0 = orderedDictionary[0]
|
||||
XCTAssertEqual(elementAtIndex0.0, "C")
|
||||
XCTAssertEqual(elementAtIndex0.1, 3)
|
||||
let nonExistentElement = orderedDictionary.removeAtIndex(42)
|
||||
|
||||
XCTAssertNil(nonExistentElement)
|
||||
|
||||
let expected: OrderedDictionary<String, Int> = ["B": 2, "C": 3]
|
||||
let actual = orderedDictionary
|
||||
|
||||
XCTAssertTrue(expected == actual)
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
@@ -246,39 +285,23 @@ class OrderedDictionaryTests: XCTestCase {
|
||||
// ======================================================= //
|
||||
|
||||
func testSortingInPlace() {
|
||||
var testOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("E", 4),
|
||||
("G", 3),
|
||||
("A", 3),
|
||||
("D", 1),
|
||||
("B", 4)
|
||||
]
|
||||
|
||||
testOrderedDictionary.sortInPlace { (item1, item2) in
|
||||
if item1.1 == item2.1 {
|
||||
return item1.0 < item2.0
|
||||
} else {
|
||||
return item1.1 < item2.1
|
||||
let actual: OrderedDictionary<String, Int> = {
|
||||
var orderedDictionary: OrderedDictionary<String, Int> = ["E": 4, "G": 3, "A": 3, "D": 1, "B": 4]
|
||||
|
||||
orderedDictionary.sortInPlace { (element1: (key: String, value: Int), element2: (key: String, value: Int)) in
|
||||
if element1.value == element2.value {
|
||||
return element1.key < element2.key
|
||||
} else {
|
||||
return element1.value < element2.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return orderedDictionary
|
||||
}()
|
||||
|
||||
let expectedOrderedDictionary: OrderedDictionary<String, Int> = [
|
||||
("D", 1),
|
||||
("A", 3),
|
||||
("G", 3),
|
||||
("B", 4),
|
||||
("E", 4)
|
||||
]
|
||||
let expected: OrderedDictionary<String, Int> = ["D": 1, "A": 3, "G": 3, "B": 4, "E": 4]
|
||||
|
||||
XCTAssertTrue(testOrderedDictionary == expectedOrderedDictionary)
|
||||
XCTAssertTrue(actual == expected)
|
||||
}
|
||||
|
||||
// ======================================================= //
|
||||
// MARK: - Description
|
||||
// ======================================================= //
|
||||
|
||||
func testDescription() {
|
||||
XCTAssertEqual(orderedDictionary.description, "[A: 1, B: 2, C: 3]")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user