├── .gitignore ├── ANKeyValue-1.png ├── ANKeyValue-2.png ├── ANKeyValue-3.png ├── ANKeyValue.xcodeproj └── project.pbxproj ├── ANKeyValue ├── ANKeyValue │ ├── AESCrypt │ │ ├── AESCrypt.h │ │ ├── AESCrypt.m │ │ ├── NSData+Base64.h │ │ ├── NSData+Base64.m │ │ ├── NSData+CommonCrypto.h │ │ ├── NSData+CommonCrypto.m │ │ ├── NSString+Base64.h │ │ └── NSString+Base64.m │ ├── ANKeyValueData.h │ ├── ANKeyValueData.m │ ├── ANKeyValueStrategy.h │ ├── ANKeyValueStrategy.m │ ├── ANKeyValueTable.h │ ├── ANKeyValueTable.m │ ├── AutoCoding │ │ ├── AutoCoding.h │ │ └── AutoCoding.m │ ├── Memory │ │ ├── ANMemoryPage.h │ │ └── ANMemoryPage.m │ ├── Persistent │ │ ├── ANPersistentData.h │ │ ├── ANPersistentData.m │ │ ├── ANPersistentStrategy.h │ │ └── ANPersistentStrategy.m │ └── Protocol │ │ ├── ANKeyValueProtocol.h │ │ ├── NSData+ANKeyValue.h │ │ ├── NSData+ANKeyValue.m │ │ ├── NSString+ANKeyValue.h │ │ ├── NSString+ANKeyValue.m │ │ ├── UIImage+ANKeyValue.h │ │ └── UIImage+ANKeyValue.m ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── ConcurrentViewController.h ├── ConcurrentViewController.m ├── ConcurrentViewController.xib ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── PerformanceViewController.h ├── PerformanceViewController.m ├── PerformanceViewController.xib ├── SetDemoItem.h ├── SetDemoItem.m ├── SetDemoViewController.h ├── SetDemoViewController.m ├── SetDemoViewController.xib ├── TableHelper.h ├── TableHelper.m ├── ViewController.h ├── ViewController.m ├── main.m └── test.png ├── ANKeyValueTests ├── ANKeyValueTests.m └── Info.plist ├── LICENSE.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /ANKeyValue-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringOx/ANKeyValue/3b8e8fb92f11777a9769eb93b8e921d1749b9d1e/ANKeyValue-1.png -------------------------------------------------------------------------------- /ANKeyValue-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringOx/ANKeyValue/3b8e8fb92f11777a9769eb93b8e921d1749b9d1e/ANKeyValue-2.png -------------------------------------------------------------------------------- /ANKeyValue-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringOx/ANKeyValue/3b8e8fb92f11777a9769eb93b8e921d1749b9d1e/ANKeyValue-3.png -------------------------------------------------------------------------------- /ANKeyValue.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 469C5B5F1E7E707300B97F52 /* ANMemoryPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 469C5B5E1E7E707300B97F52 /* ANMemoryPage.m */; }; 11 | 469C5B601E7E707300B97F52 /* ANMemoryPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 469C5B5E1E7E707300B97F52 /* ANMemoryPage.m */; }; 12 | 469C5B761E7E9BAB00B97F52 /* SetDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 469C5B751E7E9BAB00B97F52 /* SetDemoViewController.xib */; }; 13 | 469C5B771E7E9BAB00B97F52 /* SetDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 469C5B751E7E9BAB00B97F52 /* SetDemoViewController.xib */; }; 14 | 540685A71B27332F00EFD96B /* AutoCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685A61B27332F00EFD96B /* AutoCoding.m */; }; 15 | 540685A81B27332F00EFD96B /* AutoCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685A61B27332F00EFD96B /* AutoCoding.m */; }; 16 | 540685E11B274E2000EFD96B /* AESCrypt.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685D61B274E2000EFD96B /* AESCrypt.m */; }; 17 | 540685E21B274E2000EFD96B /* AESCrypt.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685D61B274E2000EFD96B /* AESCrypt.m */; }; 18 | 540685E51B274E2000EFD96B /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685D91B274E2000EFD96B /* NSData+Base64.m */; }; 19 | 540685E61B274E2000EFD96B /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685D91B274E2000EFD96B /* NSData+Base64.m */; }; 20 | 540685E71B274E2000EFD96B /* NSData+CommonCrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685DB1B274E2000EFD96B /* NSData+CommonCrypto.m */; }; 21 | 540685E81B274E2000EFD96B /* NSData+CommonCrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685DB1B274E2000EFD96B /* NSData+CommonCrypto.m */; }; 22 | 540685E91B274E2000EFD96B /* NSString+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685DD1B274E2000EFD96B /* NSString+Base64.m */; }; 23 | 540685EA1B274E2000EFD96B /* NSString+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685DD1B274E2000EFD96B /* NSString+Base64.m */; }; 24 | 540685EF1B28A03A00EFD96B /* SetDemoItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 540685EE1B28A03A00EFD96B /* SetDemoItem.m */; }; 25 | 5454CA441A5A5C3B00FBE041 /* ANPersistentData.m in Sources */ = {isa = PBXBuildFile; fileRef = 5454CA411A5A5C3B00FBE041 /* ANPersistentData.m */; }; 26 | 5454CA451A5A5C3B00FBE041 /* ANPersistentData.m in Sources */ = {isa = PBXBuildFile; fileRef = 5454CA411A5A5C3B00FBE041 /* ANPersistentData.m */; }; 27 | 5454CA461A5A5C3B00FBE041 /* ANPersistentStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 5454CA431A5A5C3B00FBE041 /* ANPersistentStrategy.m */; }; 28 | 5454CA471A5A5C3B00FBE041 /* ANPersistentStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 5454CA431A5A5C3B00FBE041 /* ANPersistentStrategy.m */; }; 29 | 5454CA4A1A5C354100FBE041 /* test.png in Resources */ = {isa = PBXBuildFile; fileRef = 5454CA491A5C354100FBE041 /* test.png */; }; 30 | 5454CA4B1A5C354100FBE041 /* test.png in Resources */ = {isa = PBXBuildFile; fileRef = 5454CA491A5C354100FBE041 /* test.png */; }; 31 | 5454CA531A62DA2400FBE041 /* SetDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5454CA511A62DA2400FBE041 /* SetDemoViewController.m */; }; 32 | 54747A1D1AC0DB2D006B1404 /* ConcurrentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 54747A1B1AC0DB2D006B1404 /* ConcurrentViewController.m */; }; 33 | 54747A1E1AC0DB2D006B1404 /* ConcurrentViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54747A1C1AC0DB2D006B1404 /* ConcurrentViewController.xib */; }; 34 | 54854DC91B121E870089A443 /* NSData+ANKeyValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 54854DC41B121E870089A443 /* NSData+ANKeyValue.m */; }; 35 | 54854DCA1B121E870089A443 /* NSData+ANKeyValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 54854DC41B121E870089A443 /* NSData+ANKeyValue.m */; }; 36 | 54854DCB1B121E870089A443 /* NSString+ANKeyValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 54854DC61B121E870089A443 /* NSString+ANKeyValue.m */; }; 37 | 54854DCC1B121E870089A443 /* NSString+ANKeyValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 54854DC61B121E870089A443 /* NSString+ANKeyValue.m */; }; 38 | 54854DCD1B121E870089A443 /* UIImage+ANKeyValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 54854DC81B121E870089A443 /* UIImage+ANKeyValue.m */; }; 39 | 54854DCE1B121E870089A443 /* UIImage+ANKeyValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 54854DC81B121E870089A443 /* UIImage+ANKeyValue.m */; }; 40 | 54927B771A72B01800E00047 /* PerformanceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 54927B751A72B01800E00047 /* PerformanceViewController.m */; }; 41 | 54927B791A72B01800E00047 /* PerformanceViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54927B761A72B01800E00047 /* PerformanceViewController.xib */; }; 42 | 54D21B301A4A83FB0065052D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B2F1A4A83FB0065052D /* main.m */; }; 43 | 54D21B331A4A83FB0065052D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B321A4A83FB0065052D /* AppDelegate.m */; }; 44 | 54D21B361A4A83FB0065052D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B351A4A83FB0065052D /* ViewController.m */; }; 45 | 54D21B391A4A83FB0065052D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 54D21B371A4A83FB0065052D /* Main.storyboard */; }; 46 | 54D21B3B1A4A83FB0065052D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 54D21B3A1A4A83FB0065052D /* Images.xcassets */; }; 47 | 54D21B3E1A4A83FB0065052D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54D21B3C1A4A83FB0065052D /* LaunchScreen.xib */; }; 48 | 54D21B4A1A4A83FB0065052D /* ANKeyValueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B491A4A83FB0065052D /* ANKeyValueTests.m */; }; 49 | 54D21B621A4A84380065052D /* ANKeyValueData.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B571A4A84380065052D /* ANKeyValueData.m */; }; 50 | 54D21B631A4A84380065052D /* ANKeyValueData.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B571A4A84380065052D /* ANKeyValueData.m */; }; 51 | 54D21B641A4A84380065052D /* ANKeyValueTable.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B591A4A84380065052D /* ANKeyValueTable.m */; }; 52 | 54D21B651A4A84380065052D /* ANKeyValueTable.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B591A4A84380065052D /* ANKeyValueTable.m */; }; 53 | 54D21B661A4A84380065052D /* ANKeyValueStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B5B1A4A84380065052D /* ANKeyValueStrategy.m */; }; 54 | 54D21B671A4A84380065052D /* ANKeyValueStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D21B5B1A4A84380065052D /* ANKeyValueStrategy.m */; }; 55 | 54DE7AE81B70868300A2417C /* TableHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 54DE7AE71B70868300A2417C /* TableHelper.m */; }; 56 | /* End PBXBuildFile section */ 57 | 58 | /* Begin PBXContainerItemProxy section */ 59 | 54D21B441A4A83FB0065052D /* PBXContainerItemProxy */ = { 60 | isa = PBXContainerItemProxy; 61 | containerPortal = 54D21B221A4A83FB0065052D /* Project object */; 62 | proxyType = 1; 63 | remoteGlobalIDString = 54D21B291A4A83FB0065052D; 64 | remoteInfo = ANKeyValue; 65 | }; 66 | /* End PBXContainerItemProxy section */ 67 | 68 | /* Begin PBXFileReference section */ 69 | 469C5B5D1E7E707300B97F52 /* ANMemoryPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANMemoryPage.h; sourceTree = ""; }; 70 | 469C5B5E1E7E707300B97F52 /* ANMemoryPage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANMemoryPage.m; sourceTree = ""; }; 71 | 469C5B751E7E9BAB00B97F52 /* SetDemoViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SetDemoViewController.xib; sourceTree = ""; }; 72 | 540685A51B27332F00EFD96B /* AutoCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoCoding.h; sourceTree = ""; }; 73 | 540685A61B27332F00EFD96B /* AutoCoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AutoCoding.m; sourceTree = ""; }; 74 | 540685D51B274E2000EFD96B /* AESCrypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AESCrypt.h; sourceTree = ""; }; 75 | 540685D61B274E2000EFD96B /* AESCrypt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AESCrypt.m; sourceTree = ""; }; 76 | 540685D81B274E2000EFD96B /* NSData+Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Base64.h"; sourceTree = ""; }; 77 | 540685D91B274E2000EFD96B /* NSData+Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Base64.m"; sourceTree = ""; }; 78 | 540685DA1B274E2000EFD96B /* NSData+CommonCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+CommonCrypto.h"; sourceTree = ""; }; 79 | 540685DB1B274E2000EFD96B /* NSData+CommonCrypto.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+CommonCrypto.m"; sourceTree = ""; }; 80 | 540685DC1B274E2000EFD96B /* NSString+Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Base64.h"; sourceTree = ""; }; 81 | 540685DD1B274E2000EFD96B /* NSString+Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Base64.m"; sourceTree = ""; }; 82 | 540685ED1B28A03A00EFD96B /* SetDemoItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SetDemoItem.h; sourceTree = ""; }; 83 | 540685EE1B28A03A00EFD96B /* SetDemoItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SetDemoItem.m; sourceTree = ""; }; 84 | 5454CA401A5A5C3B00FBE041 /* ANPersistentData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANPersistentData.h; sourceTree = ""; }; 85 | 5454CA411A5A5C3B00FBE041 /* ANPersistentData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANPersistentData.m; sourceTree = ""; }; 86 | 5454CA421A5A5C3B00FBE041 /* ANPersistentStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANPersistentStrategy.h; sourceTree = ""; }; 87 | 5454CA431A5A5C3B00FBE041 /* ANPersistentStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANPersistentStrategy.m; sourceTree = ""; }; 88 | 5454CA491A5C354100FBE041 /* test.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = test.png; sourceTree = ""; }; 89 | 5454CA501A62DA2400FBE041 /* SetDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SetDemoViewController.h; sourceTree = ""; }; 90 | 5454CA511A62DA2400FBE041 /* SetDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SetDemoViewController.m; sourceTree = ""; }; 91 | 54747A1A1AC0DB2D006B1404 /* ConcurrentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcurrentViewController.h; sourceTree = ""; }; 92 | 54747A1B1AC0DB2D006B1404 /* ConcurrentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcurrentViewController.m; sourceTree = ""; }; 93 | 54747A1C1AC0DB2D006B1404 /* ConcurrentViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ConcurrentViewController.xib; sourceTree = ""; }; 94 | 54854DC21B121E870089A443 /* ANKeyValueProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKeyValueProtocol.h; sourceTree = ""; }; 95 | 54854DC31B121E870089A443 /* NSData+ANKeyValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+ANKeyValue.h"; sourceTree = ""; }; 96 | 54854DC41B121E870089A443 /* NSData+ANKeyValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+ANKeyValue.m"; sourceTree = ""; }; 97 | 54854DC51B121E870089A443 /* NSString+ANKeyValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+ANKeyValue.h"; sourceTree = ""; }; 98 | 54854DC61B121E870089A443 /* NSString+ANKeyValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+ANKeyValue.m"; sourceTree = ""; }; 99 | 54854DC71B121E870089A443 /* UIImage+ANKeyValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ANKeyValue.h"; sourceTree = ""; }; 100 | 54854DC81B121E870089A443 /* UIImage+ANKeyValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ANKeyValue.m"; sourceTree = ""; }; 101 | 54927B741A72B01800E00047 /* PerformanceViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceViewController.h; sourceTree = ""; }; 102 | 54927B751A72B01800E00047 /* PerformanceViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PerformanceViewController.m; sourceTree = ""; }; 103 | 54927B761A72B01800E00047 /* PerformanceViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PerformanceViewController.xib; sourceTree = ""; }; 104 | 54D21B2A1A4A83FB0065052D /* ANKeyValue.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ANKeyValue.app; sourceTree = BUILT_PRODUCTS_DIR; }; 105 | 54D21B2E1A4A83FB0065052D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 106 | 54D21B2F1A4A83FB0065052D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 107 | 54D21B311A4A83FB0065052D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 108 | 54D21B321A4A83FB0065052D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 109 | 54D21B341A4A83FB0065052D /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 110 | 54D21B351A4A83FB0065052D /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 111 | 54D21B381A4A83FB0065052D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 112 | 54D21B3A1A4A83FB0065052D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 113 | 54D21B3D1A4A83FB0065052D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 114 | 54D21B431A4A83FB0065052D /* ANKeyValueTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ANKeyValueTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 115 | 54D21B481A4A83FB0065052D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 116 | 54D21B491A4A83FB0065052D /* ANKeyValueTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ANKeyValueTests.m; sourceTree = ""; }; 117 | 54D21B561A4A84380065052D /* ANKeyValueData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKeyValueData.h; sourceTree = ""; }; 118 | 54D21B571A4A84380065052D /* ANKeyValueData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKeyValueData.m; sourceTree = ""; }; 119 | 54D21B581A4A84380065052D /* ANKeyValueTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKeyValueTable.h; sourceTree = ""; }; 120 | 54D21B591A4A84380065052D /* ANKeyValueTable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKeyValueTable.m; sourceTree = ""; }; 121 | 54D21B5A1A4A84380065052D /* ANKeyValueStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKeyValueStrategy.h; sourceTree = ""; }; 122 | 54D21B5B1A4A84380065052D /* ANKeyValueStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKeyValueStrategy.m; sourceTree = ""; }; 123 | 54DE7AE61B70868300A2417C /* TableHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableHelper.h; sourceTree = ""; }; 124 | 54DE7AE71B70868300A2417C /* TableHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableHelper.m; sourceTree = ""; }; 125 | /* End PBXFileReference section */ 126 | 127 | /* Begin PBXFrameworksBuildPhase section */ 128 | 54D21B271A4A83FB0065052D /* Frameworks */ = { 129 | isa = PBXFrameworksBuildPhase; 130 | buildActionMask = 2147483647; 131 | files = ( 132 | ); 133 | runOnlyForDeploymentPostprocessing = 0; 134 | }; 135 | 54D21B401A4A83FB0065052D /* Frameworks */ = { 136 | isa = PBXFrameworksBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXFrameworksBuildPhase section */ 143 | 144 | /* Begin PBXGroup section */ 145 | 469C5B5C1E7E707300B97F52 /* Memory */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | 469C5B5D1E7E707300B97F52 /* ANMemoryPage.h */, 149 | 469C5B5E1E7E707300B97F52 /* ANMemoryPage.m */, 150 | ); 151 | path = Memory; 152 | sourceTree = ""; 153 | }; 154 | 540685A41B27332F00EFD96B /* AutoCoding */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | 540685A51B27332F00EFD96B /* AutoCoding.h */, 158 | 540685A61B27332F00EFD96B /* AutoCoding.m */, 159 | ); 160 | path = AutoCoding; 161 | sourceTree = ""; 162 | }; 163 | 540685D31B274E2000EFD96B /* AESCrypt */ = { 164 | isa = PBXGroup; 165 | children = ( 166 | 540685D51B274E2000EFD96B /* AESCrypt.h */, 167 | 540685D61B274E2000EFD96B /* AESCrypt.m */, 168 | 540685D81B274E2000EFD96B /* NSData+Base64.h */, 169 | 540685D91B274E2000EFD96B /* NSData+Base64.m */, 170 | 540685DC1B274E2000EFD96B /* NSString+Base64.h */, 171 | 540685DD1B274E2000EFD96B /* NSString+Base64.m */, 172 | 540685DA1B274E2000EFD96B /* NSData+CommonCrypto.h */, 173 | 540685DB1B274E2000EFD96B /* NSData+CommonCrypto.m */, 174 | ); 175 | path = AESCrypt; 176 | sourceTree = ""; 177 | }; 178 | 5454CA3F1A5A5C3B00FBE041 /* Persistent */ = { 179 | isa = PBXGroup; 180 | children = ( 181 | 5454CA401A5A5C3B00FBE041 /* ANPersistentData.h */, 182 | 5454CA411A5A5C3B00FBE041 /* ANPersistentData.m */, 183 | 5454CA421A5A5C3B00FBE041 /* ANPersistentStrategy.h */, 184 | 5454CA431A5A5C3B00FBE041 /* ANPersistentStrategy.m */, 185 | ); 186 | path = Persistent; 187 | sourceTree = ""; 188 | }; 189 | 54854DC11B121E870089A443 /* Protocol */ = { 190 | isa = PBXGroup; 191 | children = ( 192 | 54854DC21B121E870089A443 /* ANKeyValueProtocol.h */, 193 | 54854DC31B121E870089A443 /* NSData+ANKeyValue.h */, 194 | 54854DC41B121E870089A443 /* NSData+ANKeyValue.m */, 195 | 54854DC51B121E870089A443 /* NSString+ANKeyValue.h */, 196 | 54854DC61B121E870089A443 /* NSString+ANKeyValue.m */, 197 | 54854DC71B121E870089A443 /* UIImage+ANKeyValue.h */, 198 | 54854DC81B121E870089A443 /* UIImage+ANKeyValue.m */, 199 | ); 200 | path = Protocol; 201 | sourceTree = ""; 202 | }; 203 | 54D21B211A4A83FB0065052D = { 204 | isa = PBXGroup; 205 | children = ( 206 | 54D21B2C1A4A83FB0065052D /* ANKeyValue */, 207 | 54D21B461A4A83FB0065052D /* ANKeyValueTests */, 208 | 54D21B2B1A4A83FB0065052D /* Products */, 209 | ); 210 | sourceTree = ""; 211 | }; 212 | 54D21B2B1A4A83FB0065052D /* Products */ = { 213 | isa = PBXGroup; 214 | children = ( 215 | 54D21B2A1A4A83FB0065052D /* ANKeyValue.app */, 216 | 54D21B431A4A83FB0065052D /* ANKeyValueTests.xctest */, 217 | ); 218 | name = Products; 219 | sourceTree = ""; 220 | }; 221 | 54D21B2C1A4A83FB0065052D /* ANKeyValue */ = { 222 | isa = PBXGroup; 223 | children = ( 224 | 54D21B311A4A83FB0065052D /* AppDelegate.h */, 225 | 54D21B321A4A83FB0065052D /* AppDelegate.m */, 226 | 54DE7AE61B70868300A2417C /* TableHelper.h */, 227 | 54DE7AE71B70868300A2417C /* TableHelper.m */, 228 | 540685ED1B28A03A00EFD96B /* SetDemoItem.h */, 229 | 540685EE1B28A03A00EFD96B /* SetDemoItem.m */, 230 | 54D21B341A4A83FB0065052D /* ViewController.h */, 231 | 54D21B351A4A83FB0065052D /* ViewController.m */, 232 | 5454CA501A62DA2400FBE041 /* SetDemoViewController.h */, 233 | 5454CA511A62DA2400FBE041 /* SetDemoViewController.m */, 234 | 469C5B751E7E9BAB00B97F52 /* SetDemoViewController.xib */, 235 | 54927B741A72B01800E00047 /* PerformanceViewController.h */, 236 | 54927B751A72B01800E00047 /* PerformanceViewController.m */, 237 | 54927B761A72B01800E00047 /* PerformanceViewController.xib */, 238 | 54747A1A1AC0DB2D006B1404 /* ConcurrentViewController.h */, 239 | 54747A1B1AC0DB2D006B1404 /* ConcurrentViewController.m */, 240 | 54747A1C1AC0DB2D006B1404 /* ConcurrentViewController.xib */, 241 | 54D21B531A4A84380065052D /* ANKeyValue */, 242 | 54D21B371A4A83FB0065052D /* Main.storyboard */, 243 | 54D21B3A1A4A83FB0065052D /* Images.xcassets */, 244 | 54D21B3C1A4A83FB0065052D /* LaunchScreen.xib */, 245 | 54D21B2D1A4A83FB0065052D /* Supporting Files */, 246 | ); 247 | path = ANKeyValue; 248 | sourceTree = ""; 249 | }; 250 | 54D21B2D1A4A83FB0065052D /* Supporting Files */ = { 251 | isa = PBXGroup; 252 | children = ( 253 | 5454CA491A5C354100FBE041 /* test.png */, 254 | 54D21B2E1A4A83FB0065052D /* Info.plist */, 255 | 54D21B2F1A4A83FB0065052D /* main.m */, 256 | ); 257 | name = "Supporting Files"; 258 | sourceTree = ""; 259 | }; 260 | 54D21B461A4A83FB0065052D /* ANKeyValueTests */ = { 261 | isa = PBXGroup; 262 | children = ( 263 | 54D21B491A4A83FB0065052D /* ANKeyValueTests.m */, 264 | 54D21B471A4A83FB0065052D /* Supporting Files */, 265 | ); 266 | path = ANKeyValueTests; 267 | sourceTree = ""; 268 | }; 269 | 54D21B471A4A83FB0065052D /* Supporting Files */ = { 270 | isa = PBXGroup; 271 | children = ( 272 | 54D21B481A4A83FB0065052D /* Info.plist */, 273 | ); 274 | name = "Supporting Files"; 275 | sourceTree = ""; 276 | }; 277 | 54D21B531A4A84380065052D /* ANKeyValue */ = { 278 | isa = PBXGroup; 279 | children = ( 280 | 54D21B581A4A84380065052D /* ANKeyValueTable.h */, 281 | 54D21B591A4A84380065052D /* ANKeyValueTable.m */, 282 | 54D21B561A4A84380065052D /* ANKeyValueData.h */, 283 | 54D21B571A4A84380065052D /* ANKeyValueData.m */, 284 | 54D21B5A1A4A84380065052D /* ANKeyValueStrategy.h */, 285 | 54D21B5B1A4A84380065052D /* ANKeyValueStrategy.m */, 286 | 54854DC11B121E870089A443 /* Protocol */, 287 | 469C5B5C1E7E707300B97F52 /* Memory */, 288 | 5454CA3F1A5A5C3B00FBE041 /* Persistent */, 289 | 540685D31B274E2000EFD96B /* AESCrypt */, 290 | 540685A41B27332F00EFD96B /* AutoCoding */, 291 | ); 292 | path = ANKeyValue; 293 | sourceTree = ""; 294 | }; 295 | /* End PBXGroup section */ 296 | 297 | /* Begin PBXNativeTarget section */ 298 | 54D21B291A4A83FB0065052D /* ANKeyValue */ = { 299 | isa = PBXNativeTarget; 300 | buildConfigurationList = 54D21B4D1A4A83FB0065052D /* Build configuration list for PBXNativeTarget "ANKeyValue" */; 301 | buildPhases = ( 302 | 54D21B261A4A83FB0065052D /* Sources */, 303 | 54D21B271A4A83FB0065052D /* Frameworks */, 304 | 54D21B281A4A83FB0065052D /* Resources */, 305 | ); 306 | buildRules = ( 307 | ); 308 | dependencies = ( 309 | ); 310 | name = ANKeyValue; 311 | productName = ANKeyValue; 312 | productReference = 54D21B2A1A4A83FB0065052D /* ANKeyValue.app */; 313 | productType = "com.apple.product-type.application"; 314 | }; 315 | 54D21B421A4A83FB0065052D /* ANKeyValueTests */ = { 316 | isa = PBXNativeTarget; 317 | buildConfigurationList = 54D21B501A4A83FB0065052D /* Build configuration list for PBXNativeTarget "ANKeyValueTests" */; 318 | buildPhases = ( 319 | 54D21B3F1A4A83FB0065052D /* Sources */, 320 | 54D21B401A4A83FB0065052D /* Frameworks */, 321 | 54D21B411A4A83FB0065052D /* Resources */, 322 | ); 323 | buildRules = ( 324 | ); 325 | dependencies = ( 326 | 54D21B451A4A83FB0065052D /* PBXTargetDependency */, 327 | ); 328 | name = ANKeyValueTests; 329 | productName = ANKeyValueTests; 330 | productReference = 54D21B431A4A83FB0065052D /* ANKeyValueTests.xctest */; 331 | productType = "com.apple.product-type.bundle.unit-test"; 332 | }; 333 | /* End PBXNativeTarget section */ 334 | 335 | /* Begin PBXProject section */ 336 | 54D21B221A4A83FB0065052D /* Project object */ = { 337 | isa = PBXProject; 338 | attributes = { 339 | LastUpgradeCheck = 0820; 340 | ORGANIZATIONNAME = SpringOx; 341 | TargetAttributes = { 342 | 54D21B291A4A83FB0065052D = { 343 | CreatedOnToolsVersion = 6.1; 344 | }; 345 | 54D21B421A4A83FB0065052D = { 346 | CreatedOnToolsVersion = 6.1; 347 | TestTargetID = 54D21B291A4A83FB0065052D; 348 | }; 349 | }; 350 | }; 351 | buildConfigurationList = 54D21B251A4A83FB0065052D /* Build configuration list for PBXProject "ANKeyValue" */; 352 | compatibilityVersion = "Xcode 3.2"; 353 | developmentRegion = English; 354 | hasScannedForEncodings = 0; 355 | knownRegions = ( 356 | en, 357 | Base, 358 | ); 359 | mainGroup = 54D21B211A4A83FB0065052D; 360 | productRefGroup = 54D21B2B1A4A83FB0065052D /* Products */; 361 | projectDirPath = ""; 362 | projectRoot = ""; 363 | targets = ( 364 | 54D21B291A4A83FB0065052D /* ANKeyValue */, 365 | 54D21B421A4A83FB0065052D /* ANKeyValueTests */, 366 | ); 367 | }; 368 | /* End PBXProject section */ 369 | 370 | /* Begin PBXResourcesBuildPhase section */ 371 | 54D21B281A4A83FB0065052D /* Resources */ = { 372 | isa = PBXResourcesBuildPhase; 373 | buildActionMask = 2147483647; 374 | files = ( 375 | 54D21B391A4A83FB0065052D /* Main.storyboard in Resources */, 376 | 54D21B3E1A4A83FB0065052D /* LaunchScreen.xib in Resources */, 377 | 469C5B761E7E9BAB00B97F52 /* SetDemoViewController.xib in Resources */, 378 | 54D21B3B1A4A83FB0065052D /* Images.xcassets in Resources */, 379 | 5454CA4A1A5C354100FBE041 /* test.png in Resources */, 380 | 54747A1E1AC0DB2D006B1404 /* ConcurrentViewController.xib in Resources */, 381 | 54927B791A72B01800E00047 /* PerformanceViewController.xib in Resources */, 382 | ); 383 | runOnlyForDeploymentPostprocessing = 0; 384 | }; 385 | 54D21B411A4A83FB0065052D /* Resources */ = { 386 | isa = PBXResourcesBuildPhase; 387 | buildActionMask = 2147483647; 388 | files = ( 389 | 469C5B771E7E9BAB00B97F52 /* SetDemoViewController.xib in Resources */, 390 | 5454CA4B1A5C354100FBE041 /* test.png in Resources */, 391 | ); 392 | runOnlyForDeploymentPostprocessing = 0; 393 | }; 394 | /* End PBXResourcesBuildPhase section */ 395 | 396 | /* Begin PBXSourcesBuildPhase section */ 397 | 54D21B261A4A83FB0065052D /* Sources */ = { 398 | isa = PBXSourcesBuildPhase; 399 | buildActionMask = 2147483647; 400 | files = ( 401 | 540685EF1B28A03A00EFD96B /* SetDemoItem.m in Sources */, 402 | 54854DCD1B121E870089A443 /* UIImage+ANKeyValue.m in Sources */, 403 | 5454CA461A5A5C3B00FBE041 /* ANPersistentStrategy.m in Sources */, 404 | 54747A1D1AC0DB2D006B1404 /* ConcurrentViewController.m in Sources */, 405 | 54D21B361A4A83FB0065052D /* ViewController.m in Sources */, 406 | 540685E91B274E2000EFD96B /* NSString+Base64.m in Sources */, 407 | 540685A71B27332F00EFD96B /* AutoCoding.m in Sources */, 408 | 540685E71B274E2000EFD96B /* NSData+CommonCrypto.m in Sources */, 409 | 54D21B661A4A84380065052D /* ANKeyValueStrategy.m in Sources */, 410 | 54D21B621A4A84380065052D /* ANKeyValueData.m in Sources */, 411 | 54D21B641A4A84380065052D /* ANKeyValueTable.m in Sources */, 412 | 54854DC91B121E870089A443 /* NSData+ANKeyValue.m in Sources */, 413 | 540685E11B274E2000EFD96B /* AESCrypt.m in Sources */, 414 | 54D21B331A4A83FB0065052D /* AppDelegate.m in Sources */, 415 | 54854DCB1B121E870089A443 /* NSString+ANKeyValue.m in Sources */, 416 | 469C5B5F1E7E707300B97F52 /* ANMemoryPage.m in Sources */, 417 | 5454CA531A62DA2400FBE041 /* SetDemoViewController.m in Sources */, 418 | 54927B771A72B01800E00047 /* PerformanceViewController.m in Sources */, 419 | 54DE7AE81B70868300A2417C /* TableHelper.m in Sources */, 420 | 54D21B301A4A83FB0065052D /* main.m in Sources */, 421 | 5454CA441A5A5C3B00FBE041 /* ANPersistentData.m in Sources */, 422 | 540685E51B274E2000EFD96B /* NSData+Base64.m in Sources */, 423 | ); 424 | runOnlyForDeploymentPostprocessing = 0; 425 | }; 426 | 54D21B3F1A4A83FB0065052D /* Sources */ = { 427 | isa = PBXSourcesBuildPhase; 428 | buildActionMask = 2147483647; 429 | files = ( 430 | 54854DCC1B121E870089A443 /* NSString+ANKeyValue.m in Sources */, 431 | 54D21B4A1A4A83FB0065052D /* ANKeyValueTests.m in Sources */, 432 | 5454CA471A5A5C3B00FBE041 /* ANPersistentStrategy.m in Sources */, 433 | 540685E21B274E2000EFD96B /* AESCrypt.m in Sources */, 434 | 54D21B671A4A84380065052D /* ANKeyValueStrategy.m in Sources */, 435 | 540685E81B274E2000EFD96B /* NSData+CommonCrypto.m in Sources */, 436 | 540685A81B27332F00EFD96B /* AutoCoding.m in Sources */, 437 | 54D21B651A4A84380065052D /* ANKeyValueTable.m in Sources */, 438 | 540685EA1B274E2000EFD96B /* NSString+Base64.m in Sources */, 439 | 54854DCA1B121E870089A443 /* NSData+ANKeyValue.m in Sources */, 440 | 54D21B631A4A84380065052D /* ANKeyValueData.m in Sources */, 441 | 54854DCE1B121E870089A443 /* UIImage+ANKeyValue.m in Sources */, 442 | 540685E61B274E2000EFD96B /* NSData+Base64.m in Sources */, 443 | 469C5B601E7E707300B97F52 /* ANMemoryPage.m in Sources */, 444 | 5454CA451A5A5C3B00FBE041 /* ANPersistentData.m in Sources */, 445 | ); 446 | runOnlyForDeploymentPostprocessing = 0; 447 | }; 448 | /* End PBXSourcesBuildPhase section */ 449 | 450 | /* Begin PBXTargetDependency section */ 451 | 54D21B451A4A83FB0065052D /* PBXTargetDependency */ = { 452 | isa = PBXTargetDependency; 453 | target = 54D21B291A4A83FB0065052D /* ANKeyValue */; 454 | targetProxy = 54D21B441A4A83FB0065052D /* PBXContainerItemProxy */; 455 | }; 456 | /* End PBXTargetDependency section */ 457 | 458 | /* Begin PBXVariantGroup section */ 459 | 54D21B371A4A83FB0065052D /* Main.storyboard */ = { 460 | isa = PBXVariantGroup; 461 | children = ( 462 | 54D21B381A4A83FB0065052D /* Base */, 463 | ); 464 | name = Main.storyboard; 465 | sourceTree = ""; 466 | }; 467 | 54D21B3C1A4A83FB0065052D /* LaunchScreen.xib */ = { 468 | isa = PBXVariantGroup; 469 | children = ( 470 | 54D21B3D1A4A83FB0065052D /* Base */, 471 | ); 472 | name = LaunchScreen.xib; 473 | sourceTree = ""; 474 | }; 475 | /* End PBXVariantGroup section */ 476 | 477 | /* Begin XCBuildConfiguration section */ 478 | 54D21B4B1A4A83FB0065052D /* Debug */ = { 479 | isa = XCBuildConfiguration; 480 | buildSettings = { 481 | ALWAYS_SEARCH_USER_PATHS = NO; 482 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 483 | CLANG_CXX_LIBRARY = "libc++"; 484 | CLANG_ENABLE_MODULES = YES; 485 | CLANG_ENABLE_OBJC_ARC = YES; 486 | CLANG_WARN_BOOL_CONVERSION = YES; 487 | CLANG_WARN_CONSTANT_CONVERSION = YES; 488 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 489 | CLANG_WARN_EMPTY_BODY = YES; 490 | CLANG_WARN_ENUM_CONVERSION = YES; 491 | CLANG_WARN_INFINITE_RECURSION = YES; 492 | CLANG_WARN_INT_CONVERSION = YES; 493 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 494 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 495 | CLANG_WARN_UNREACHABLE_CODE = YES; 496 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 497 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 498 | COPY_PHASE_STRIP = NO; 499 | ENABLE_STRICT_OBJC_MSGSEND = YES; 500 | ENABLE_TESTABILITY = YES; 501 | GCC_C_LANGUAGE_STANDARD = gnu99; 502 | GCC_DYNAMIC_NO_PIC = NO; 503 | GCC_NO_COMMON_BLOCKS = YES; 504 | GCC_OPTIMIZATION_LEVEL = 0; 505 | GCC_PREPROCESSOR_DEFINITIONS = ( 506 | "DEBUG=1", 507 | "$(inherited)", 508 | ); 509 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 510 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 511 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 512 | GCC_WARN_UNDECLARED_SELECTOR = YES; 513 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 514 | GCC_WARN_UNUSED_FUNCTION = YES; 515 | GCC_WARN_UNUSED_VARIABLE = YES; 516 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 517 | MTL_ENABLE_DEBUG_INFO = YES; 518 | ONLY_ACTIVE_ARCH = YES; 519 | SDKROOT = iphoneos; 520 | TARGETED_DEVICE_FAMILY = "1,2"; 521 | }; 522 | name = Debug; 523 | }; 524 | 54D21B4C1A4A83FB0065052D /* Release */ = { 525 | isa = XCBuildConfiguration; 526 | buildSettings = { 527 | ALWAYS_SEARCH_USER_PATHS = NO; 528 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 529 | CLANG_CXX_LIBRARY = "libc++"; 530 | CLANG_ENABLE_MODULES = YES; 531 | CLANG_ENABLE_OBJC_ARC = YES; 532 | CLANG_WARN_BOOL_CONVERSION = YES; 533 | CLANG_WARN_CONSTANT_CONVERSION = YES; 534 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 535 | CLANG_WARN_EMPTY_BODY = YES; 536 | CLANG_WARN_ENUM_CONVERSION = YES; 537 | CLANG_WARN_INFINITE_RECURSION = YES; 538 | CLANG_WARN_INT_CONVERSION = YES; 539 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 540 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 541 | CLANG_WARN_UNREACHABLE_CODE = YES; 542 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 543 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 544 | COPY_PHASE_STRIP = YES; 545 | ENABLE_NS_ASSERTIONS = NO; 546 | ENABLE_STRICT_OBJC_MSGSEND = YES; 547 | GCC_C_LANGUAGE_STANDARD = gnu99; 548 | GCC_NO_COMMON_BLOCKS = YES; 549 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 550 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 551 | GCC_WARN_UNDECLARED_SELECTOR = YES; 552 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 553 | GCC_WARN_UNUSED_FUNCTION = YES; 554 | GCC_WARN_UNUSED_VARIABLE = YES; 555 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 556 | MTL_ENABLE_DEBUG_INFO = NO; 557 | SDKROOT = iphoneos; 558 | TARGETED_DEVICE_FAMILY = "1,2"; 559 | VALIDATE_PRODUCT = YES; 560 | }; 561 | name = Release; 562 | }; 563 | 54D21B4E1A4A83FB0065052D /* Debug */ = { 564 | isa = XCBuildConfiguration; 565 | buildSettings = { 566 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 567 | DEVELOPMENT_TEAM = ""; 568 | INFOPLIST_FILE = ANKeyValue/Info.plist; 569 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 570 | PRODUCT_BUNDLE_IDENTIFIER = springox.com.ANKeyValue; 571 | PRODUCT_NAME = "$(TARGET_NAME)"; 572 | }; 573 | name = Debug; 574 | }; 575 | 54D21B4F1A4A83FB0065052D /* Release */ = { 576 | isa = XCBuildConfiguration; 577 | buildSettings = { 578 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 579 | DEVELOPMENT_TEAM = ""; 580 | INFOPLIST_FILE = ANKeyValue/Info.plist; 581 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 582 | PRODUCT_BUNDLE_IDENTIFIER = springox.com.ANKeyValue; 583 | PRODUCT_NAME = "$(TARGET_NAME)"; 584 | }; 585 | name = Release; 586 | }; 587 | 54D21B511A4A83FB0065052D /* Debug */ = { 588 | isa = XCBuildConfiguration; 589 | buildSettings = { 590 | BUNDLE_LOADER = "$(TEST_HOST)"; 591 | FRAMEWORK_SEARCH_PATHS = ( 592 | "$(SDKROOT)/Developer/Library/Frameworks", 593 | "$(inherited)", 594 | ); 595 | GCC_PREPROCESSOR_DEFINITIONS = ( 596 | "DEBUG=1", 597 | "$(inherited)", 598 | ); 599 | INFOPLIST_FILE = ANKeyValueTests/Info.plist; 600 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 601 | PRODUCT_BUNDLE_IDENTIFIER = "springox.com.$(PRODUCT_NAME:rfc1034identifier)"; 602 | PRODUCT_NAME = "$(TARGET_NAME)"; 603 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ANKeyValue.app/ANKeyValue"; 604 | }; 605 | name = Debug; 606 | }; 607 | 54D21B521A4A83FB0065052D /* Release */ = { 608 | isa = XCBuildConfiguration; 609 | buildSettings = { 610 | BUNDLE_LOADER = "$(TEST_HOST)"; 611 | FRAMEWORK_SEARCH_PATHS = ( 612 | "$(SDKROOT)/Developer/Library/Frameworks", 613 | "$(inherited)", 614 | ); 615 | INFOPLIST_FILE = ANKeyValueTests/Info.plist; 616 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 617 | PRODUCT_BUNDLE_IDENTIFIER = "springox.com.$(PRODUCT_NAME:rfc1034identifier)"; 618 | PRODUCT_NAME = "$(TARGET_NAME)"; 619 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ANKeyValue.app/ANKeyValue"; 620 | }; 621 | name = Release; 622 | }; 623 | /* End XCBuildConfiguration section */ 624 | 625 | /* Begin XCConfigurationList section */ 626 | 54D21B251A4A83FB0065052D /* Build configuration list for PBXProject "ANKeyValue" */ = { 627 | isa = XCConfigurationList; 628 | buildConfigurations = ( 629 | 54D21B4B1A4A83FB0065052D /* Debug */, 630 | 54D21B4C1A4A83FB0065052D /* Release */, 631 | ); 632 | defaultConfigurationIsVisible = 0; 633 | defaultConfigurationName = Release; 634 | }; 635 | 54D21B4D1A4A83FB0065052D /* Build configuration list for PBXNativeTarget "ANKeyValue" */ = { 636 | isa = XCConfigurationList; 637 | buildConfigurations = ( 638 | 54D21B4E1A4A83FB0065052D /* Debug */, 639 | 54D21B4F1A4A83FB0065052D /* Release */, 640 | ); 641 | defaultConfigurationIsVisible = 0; 642 | defaultConfigurationName = Release; 643 | }; 644 | 54D21B501A4A83FB0065052D /* Build configuration list for PBXNativeTarget "ANKeyValueTests" */ = { 645 | isa = XCConfigurationList; 646 | buildConfigurations = ( 647 | 54D21B511A4A83FB0065052D /* Debug */, 648 | 54D21B521A4A83FB0065052D /* Release */, 649 | ); 650 | defaultConfigurationIsVisible = 0; 651 | defaultConfigurationName = Release; 652 | }; 653 | /* End XCConfigurationList section */ 654 | }; 655 | rootObject = 54D21B221A4A83FB0065052D /* Project object */; 656 | } 657 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/AESCrypt.h: -------------------------------------------------------------------------------- 1 | // 2 | // AESCrypt.h 3 | // Gurpartap Singh 4 | // 5 | // Created by Gurpartap Singh on 06/05/12. 6 | // Copyright (c) 2012 Gurpartap Singh 7 | // 8 | // MIT License 9 | // 10 | // Permission is hereby granted, free of charge, to any person obtaining 11 | // a copy of this software and associated documentation files (the 12 | // "Software"), to deal in the Software without restriction, including 13 | // without limitation the rights to use, copy, modify, merge, publish, 14 | // distribute, sublicense, and/or sell copies of the Software, and to 15 | // permit persons to whom the Software is furnished to do so, subject to 16 | // the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be 19 | // included in all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 25 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 27 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface AESCrypt : NSObject 33 | 34 | + (NSString *)encrypt:(NSString *)message password:(NSString *)password; 35 | + (NSString *)decrypt:(NSString *)base64EncodedString password:(NSString *)password; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/AESCrypt.m: -------------------------------------------------------------------------------- 1 | // 2 | // AESCrypt.m 3 | // Gurpartap Singh 4 | // 5 | // Created by Gurpartap Singh on 06/05/12. 6 | // Copyright (c) 2012 Gurpartap Singh 7 | // 8 | // MIT License 9 | // 10 | // Permission is hereby granted, free of charge, to any person obtaining 11 | // a copy of this software and associated documentation files (the 12 | // "Software"), to deal in the Software without restriction, including 13 | // without limitation the rights to use, copy, modify, merge, publish, 14 | // distribute, sublicense, and/or sell copies of the Software, and to 15 | // permit persons to whom the Software is furnished to do so, subject to 16 | // the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be 19 | // included in all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 25 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 27 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "AESCrypt.h" 31 | 32 | #import "NSData+Base64.h" 33 | #import "NSString+Base64.h" 34 | #import "NSData+CommonCrypto.h" 35 | 36 | @implementation AESCrypt 37 | 38 | + (NSString *)encrypt:(NSString *)message password:(NSString *)password { 39 | NSData *encryptedData = [[message dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptedDataUsingKey:[[password dataUsingEncoding:NSUTF8StringEncoding] SHA256Hash] error:nil]; 40 | NSString *base64EncodedString = [NSString base64StringFromData:encryptedData length:[encryptedData length]]; 41 | return base64EncodedString; 42 | } 43 | 44 | + (NSString *)decrypt:(NSString *)base64EncodedString password:(NSString *)password { 45 | NSData *encryptedData = [NSData base64DataFromString:base64EncodedString]; 46 | NSData *decryptedData = [encryptedData decryptedAES256DataUsingKey:[[password dataUsingEncoding:NSUTF8StringEncoding] SHA256Hash] error:nil]; 47 | return [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding]; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/NSData+Base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.m 3 | // Gurpartap Singh 4 | // 5 | // Created by Gurpartap Singh on 06/05/12. 6 | // Copyright (c) 2012 Gurpartap Singh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NSString; 12 | 13 | @interface NSData (Base64Additions) 14 | 15 | + (NSData *)base64DataFromString:(NSString *)string; 16 | 17 | @end -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/NSData+Base64.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.h 3 | // Gurpartap Singh 4 | // 5 | // Created by Gurpartap Singh on 06/05/12. 6 | // Copyright (c) 2012 Gurpartap Singh. All rights reserved. 7 | // 8 | 9 | #import "NSData+Base64.h" 10 | 11 | @implementation NSData (Base64Additions) 12 | 13 | + (NSData *)base64DataFromString:(NSString *)string { 14 | unsigned long ixtext, lentext; 15 | unsigned char ch, inbuf[4], outbuf[3]; 16 | short i, ixinbuf; 17 | Boolean flignore, flendtext = false; 18 | const unsigned char *tempcstring; 19 | NSMutableData *theData; 20 | 21 | if (string == nil) { 22 | return [NSData data]; 23 | } 24 | 25 | ixtext = 0; 26 | 27 | tempcstring = (const unsigned char *)[string UTF8String]; 28 | 29 | lentext = [string length]; 30 | 31 | theData = [NSMutableData dataWithCapacity: lentext]; 32 | 33 | ixinbuf = 0; 34 | 35 | while (true) { 36 | if (ixtext >= lentext) { 37 | break; 38 | } 39 | 40 | ch = tempcstring [ixtext++]; 41 | 42 | flignore = false; 43 | 44 | if ((ch >= 'A') && (ch <= 'Z')) { 45 | ch = ch - 'A'; 46 | } 47 | else if ((ch >= 'a') && (ch <= 'z')) { 48 | ch = ch - 'a' + 26; 49 | } 50 | else if ((ch >= '0') && (ch <= '9')) { 51 | ch = ch - '0' + 52; 52 | } 53 | else if (ch == '+') { 54 | ch = 62; 55 | } 56 | else if (ch == '=') { 57 | flendtext = true; 58 | } 59 | else if (ch == '/') { 60 | ch = 63; 61 | } 62 | else { 63 | flignore = true; 64 | } 65 | 66 | if (!flignore) { 67 | short ctcharsinbuf = 3; 68 | Boolean flbreak = false; 69 | 70 | if (flendtext) { 71 | if (ixinbuf == 0) { 72 | break; 73 | } 74 | 75 | if ((ixinbuf == 1) || (ixinbuf == 2)) { 76 | ctcharsinbuf = 1; 77 | } 78 | else { 79 | ctcharsinbuf = 2; 80 | } 81 | 82 | ixinbuf = 3; 83 | 84 | flbreak = true; 85 | } 86 | 87 | inbuf [ixinbuf++] = ch; 88 | 89 | if (ixinbuf == 4) { 90 | ixinbuf = 0; 91 | 92 | outbuf[0] = (inbuf[0] << 2) | ((inbuf[1] & 0x30) >> 4); 93 | outbuf[1] = ((inbuf[1] & 0x0F) << 4) | ((inbuf[2] & 0x3C) >> 2); 94 | outbuf[2] = ((inbuf[2] & 0x03) << 6) | (inbuf[3] & 0x3F); 95 | 96 | for (i = 0; i < ctcharsinbuf; i++) { 97 | [theData appendBytes: &outbuf[i] length: 1]; 98 | } 99 | } 100 | 101 | if (flbreak) { 102 | break; 103 | } 104 | } 105 | } 106 | 107 | return theData; 108 | } 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/NSData+CommonCrypto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NSData+CommonCrypto.h 3 | * AQToolkit 4 | * 5 | * Created by Jim Dovey on 31/8/2008. 6 | * 7 | * Copyright (c) 2008-2009, Jim Dovey 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 21 | * Neither the name of this project's author nor the names of its 22 | * contributors may be used to endorse or promote products derived from 23 | * this software without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 31 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | */ 38 | 39 | #import 40 | #import 41 | #import 42 | #import 43 | 44 | extern NSString * const kCommonCryptoErrorDomain; 45 | 46 | @interface NSError (CommonCryptoErrorDomain) 47 | + (NSError *) errorWithCCCryptorStatus: (CCCryptorStatus) status; 48 | @end 49 | 50 | @interface NSData (CommonDigest) 51 | 52 | - (NSData *) MD2Sum; 53 | - (NSData *) MD4Sum; 54 | - (NSData *) MD5Sum; 55 | 56 | - (NSData *) SHA1Hash; 57 | - (NSData *) SHA224Hash; 58 | - (NSData *) SHA256Hash; 59 | - (NSData *) SHA384Hash; 60 | - (NSData *) SHA512Hash; 61 | 62 | @end 63 | 64 | @interface NSData (CommonCryptor) 65 | 66 | - (NSData *) AES256EncryptedDataUsingKey: (id) key error: (NSError **) error; 67 | - (NSData *) decryptedAES256DataUsingKey: (id) key error: (NSError **) error; 68 | 69 | - (NSData *) DESEncryptedDataUsingKey: (id) key error: (NSError **) error; 70 | - (NSData *) decryptedDESDataUsingKey: (id) key error: (NSError **) error; 71 | 72 | - (NSData *) CASTEncryptedDataUsingKey: (id) key error: (NSError **) error; 73 | - (NSData *) decryptedCASTDataUsingKey: (id) key error: (NSError **) error; 74 | 75 | @end 76 | 77 | @interface NSData (LowLevelCommonCryptor) 78 | 79 | - (NSData *) dataEncryptedUsingAlgorithm: (CCAlgorithm) algorithm 80 | key: (id) key // data or string 81 | error: (CCCryptorStatus *) error; 82 | - (NSData *) dataEncryptedUsingAlgorithm: (CCAlgorithm) algorithm 83 | key: (id) key // data or string 84 | options: (CCOptions) options 85 | error: (CCCryptorStatus *) error; 86 | - (NSData *) dataEncryptedUsingAlgorithm: (CCAlgorithm) algorithm 87 | key: (id) key // data or string 88 | initializationVector: (id) iv // data or string 89 | options: (CCOptions) options 90 | error: (CCCryptorStatus *) error; 91 | 92 | - (NSData *) decryptedDataUsingAlgorithm: (CCAlgorithm) algorithm 93 | key: (id) key // data or string 94 | error: (CCCryptorStatus *) error; 95 | - (NSData *) decryptedDataUsingAlgorithm: (CCAlgorithm) algorithm 96 | key: (id) key // data or string 97 | options: (CCOptions) options 98 | error: (CCCryptorStatus *) error; 99 | - (NSData *) decryptedDataUsingAlgorithm: (CCAlgorithm) algorithm 100 | key: (id) key // data or string 101 | initializationVector: (id) iv // data or string 102 | options: (CCOptions) options 103 | error: (CCCryptorStatus *) error; 104 | 105 | @end 106 | 107 | @interface NSData (CommonHMAC) 108 | 109 | - (NSData *) HMACWithAlgorithm: (CCHmacAlgorithm) algorithm; 110 | - (NSData *) HMACWithAlgorithm: (CCHmacAlgorithm) algorithm key: (id) key; 111 | 112 | @end -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/NSData+CommonCrypto.m: -------------------------------------------------------------------------------- 1 | /* 2 | * NSData+CommonCrypto.m 3 | * AQToolkit 4 | * 5 | * Created by Jim Dovey on 31/8/2008. 6 | * 7 | * Copyright (c) 2008-2009, Jim Dovey 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 21 | * Neither the name of this project's author nor the names of its 22 | * contributors may be used to endorse or promote products derived from 23 | * this software without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 31 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | */ 38 | 39 | #import 40 | #import "NSData+CommonCrypto.h" 41 | #import 42 | #import 43 | #import 44 | 45 | NSString * const kCommonCryptoErrorDomain = @"CommonCryptoErrorDomain"; 46 | 47 | @implementation NSError (CommonCryptoErrorDomain) 48 | 49 | + (NSError *) errorWithCCCryptorStatus: (CCCryptorStatus) status 50 | { 51 | NSString * description = nil, * reason = nil; 52 | 53 | switch ( status ) 54 | { 55 | case kCCSuccess: 56 | description = NSLocalizedString(@"Success", @"Error description"); 57 | break; 58 | 59 | case kCCParamError: 60 | description = NSLocalizedString(@"Parameter Error", @"Error description"); 61 | reason = NSLocalizedString(@"Illegal parameter supplied to encryption/decryption algorithm", @"Error reason"); 62 | break; 63 | 64 | case kCCBufferTooSmall: 65 | description = NSLocalizedString(@"Buffer Too Small", @"Error description"); 66 | reason = NSLocalizedString(@"Insufficient buffer provided for specified operation", @"Error reason"); 67 | break; 68 | 69 | case kCCMemoryFailure: 70 | description = NSLocalizedString(@"Memory Failure", @"Error description"); 71 | reason = NSLocalizedString(@"Failed to allocate memory", @"Error reason"); 72 | break; 73 | 74 | case kCCAlignmentError: 75 | description = NSLocalizedString(@"Alignment Error", @"Error description"); 76 | reason = NSLocalizedString(@"Input size to encryption algorithm was not aligned correctly", @"Error reason"); 77 | break; 78 | 79 | case kCCDecodeError: 80 | description = NSLocalizedString(@"Decode Error", @"Error description"); 81 | reason = NSLocalizedString(@"Input data did not decode or decrypt correctly", @"Error reason"); 82 | break; 83 | 84 | case kCCUnimplemented: 85 | description = NSLocalizedString(@"Unimplemented Function", @"Error description"); 86 | reason = NSLocalizedString(@"Function not implemented for the current algorithm", @"Error reason"); 87 | break; 88 | 89 | default: 90 | description = NSLocalizedString(@"Unknown Error", @"Error description"); 91 | break; 92 | } 93 | 94 | NSMutableDictionary * userInfo = [[NSMutableDictionary alloc] init]; 95 | [userInfo setObject: description forKey: NSLocalizedDescriptionKey]; 96 | 97 | if ( reason != nil ) 98 | [userInfo setObject: reason forKey: NSLocalizedFailureReasonErrorKey]; 99 | 100 | NSError * result = [NSError errorWithDomain: kCommonCryptoErrorDomain code: status userInfo: userInfo]; 101 | #if !__has_feature(objc_arc) 102 | [userInfo release]; 103 | #endif 104 | 105 | return ( result ); 106 | } 107 | 108 | @end 109 | 110 | #pragma mark - 111 | 112 | @implementation NSData (CommonDigest) 113 | 114 | - (NSData *) MD2Sum 115 | { 116 | unsigned char hash[CC_MD2_DIGEST_LENGTH]; 117 | (void) CC_MD2( [self bytes], (CC_LONG)[self length], hash ); 118 | return ( [NSData dataWithBytes: hash length: CC_MD2_DIGEST_LENGTH] ); 119 | } 120 | 121 | - (NSData *) MD4Sum 122 | { 123 | unsigned char hash[CC_MD4_DIGEST_LENGTH]; 124 | (void) CC_MD4( [self bytes], (CC_LONG)[self length], hash ); 125 | return ( [NSData dataWithBytes: hash length: CC_MD4_DIGEST_LENGTH] ); 126 | } 127 | 128 | - (NSData *) MD5Sum 129 | { 130 | unsigned char hash[CC_MD5_DIGEST_LENGTH]; 131 | (void) CC_MD5( [self bytes], (CC_LONG)[self length], hash ); 132 | return ( [NSData dataWithBytes: hash length: CC_MD5_DIGEST_LENGTH] ); 133 | } 134 | 135 | - (NSData *) SHA1Hash 136 | { 137 | unsigned char hash[CC_SHA1_DIGEST_LENGTH]; 138 | (void) CC_SHA1( [self bytes], (CC_LONG)[self length], hash ); 139 | return ( [NSData dataWithBytes: hash length: CC_SHA1_DIGEST_LENGTH] ); 140 | } 141 | 142 | - (NSData *) SHA224Hash 143 | { 144 | unsigned char hash[CC_SHA224_DIGEST_LENGTH]; 145 | (void) CC_SHA224( [self bytes], (CC_LONG)[self length], hash ); 146 | return ( [NSData dataWithBytes: hash length: CC_SHA224_DIGEST_LENGTH] ); 147 | } 148 | 149 | - (NSData *) SHA256Hash 150 | { 151 | unsigned char hash[CC_SHA256_DIGEST_LENGTH]; 152 | (void) CC_SHA256( [self bytes], (CC_LONG)[self length], hash ); 153 | return ( [NSData dataWithBytes: hash length: CC_SHA256_DIGEST_LENGTH] ); 154 | } 155 | 156 | - (NSData *) SHA384Hash 157 | { 158 | unsigned char hash[CC_SHA384_DIGEST_LENGTH]; 159 | (void) CC_SHA384( [self bytes], (CC_LONG)[self length], hash ); 160 | return ( [NSData dataWithBytes: hash length: CC_SHA384_DIGEST_LENGTH] ); 161 | } 162 | 163 | - (NSData *) SHA512Hash 164 | { 165 | unsigned char hash[CC_SHA512_DIGEST_LENGTH]; 166 | (void) CC_SHA512( [self bytes], (CC_LONG)[self length], hash ); 167 | return ( [NSData dataWithBytes: hash length: CC_SHA512_DIGEST_LENGTH] ); 168 | } 169 | 170 | @end 171 | 172 | @implementation NSData (CommonCryptor) 173 | 174 | - (NSData *) AES256EncryptedDataUsingKey: (id) key error: (NSError **) error 175 | { 176 | CCCryptorStatus status = kCCSuccess; 177 | NSData * result = [self dataEncryptedUsingAlgorithm: kCCAlgorithmAES128 178 | key: key 179 | options: kCCOptionPKCS7Padding 180 | error: &status]; 181 | 182 | if ( result != nil ) 183 | return ( result ); 184 | 185 | if ( error != NULL ) 186 | *error = [NSError errorWithCCCryptorStatus: status]; 187 | 188 | return ( nil ); 189 | } 190 | 191 | - (NSData *) decryptedAES256DataUsingKey: (id) key error: (NSError **) error 192 | { 193 | CCCryptorStatus status = kCCSuccess; 194 | NSData * result = [self decryptedDataUsingAlgorithm: kCCAlgorithmAES128 195 | key: key 196 | options: kCCOptionPKCS7Padding 197 | error: &status]; 198 | 199 | if ( result != nil ) 200 | return ( result ); 201 | 202 | if ( error != NULL ) 203 | *error = [NSError errorWithCCCryptorStatus: status]; 204 | 205 | return ( nil ); 206 | } 207 | 208 | - (NSData *) DESEncryptedDataUsingKey: (id) key error: (NSError **) error 209 | { 210 | CCCryptorStatus status = kCCSuccess; 211 | NSData * result = [self dataEncryptedUsingAlgorithm: kCCAlgorithmDES 212 | key: key 213 | options: kCCOptionPKCS7Padding 214 | error: &status]; 215 | 216 | if ( result != nil ) 217 | return ( result ); 218 | 219 | if ( error != NULL ) 220 | *error = [NSError errorWithCCCryptorStatus: status]; 221 | 222 | return ( nil ); 223 | } 224 | 225 | - (NSData *) decryptedDESDataUsingKey: (id) key error: (NSError **) error 226 | { 227 | CCCryptorStatus status = kCCSuccess; 228 | NSData * result = [self decryptedDataUsingAlgorithm: kCCAlgorithmDES 229 | key: key 230 | options: kCCOptionPKCS7Padding 231 | error: &status]; 232 | 233 | if ( result != nil ) 234 | return ( result ); 235 | 236 | if ( error != NULL ) 237 | *error = [NSError errorWithCCCryptorStatus: status]; 238 | 239 | return ( nil ); 240 | } 241 | 242 | - (NSData *) CASTEncryptedDataUsingKey: (id) key error: (NSError **) error 243 | { 244 | CCCryptorStatus status = kCCSuccess; 245 | NSData * result = [self dataEncryptedUsingAlgorithm: kCCAlgorithmCAST 246 | key: key 247 | options: kCCOptionPKCS7Padding 248 | error: &status]; 249 | 250 | if ( result != nil ) 251 | return ( result ); 252 | 253 | if ( error != NULL ) 254 | *error = [NSError errorWithCCCryptorStatus: status]; 255 | 256 | return ( nil ); 257 | } 258 | 259 | - (NSData *) decryptedCASTDataUsingKey: (id) key error: (NSError **) error 260 | { 261 | CCCryptorStatus status = kCCSuccess; 262 | NSData * result = [self decryptedDataUsingAlgorithm: kCCAlgorithmCAST 263 | key: key 264 | options: kCCOptionPKCS7Padding 265 | error: &status]; 266 | 267 | if ( result != nil ) 268 | return ( result ); 269 | 270 | if ( error != NULL ) 271 | *error = [NSError errorWithCCCryptorStatus: status]; 272 | 273 | return ( nil ); 274 | } 275 | 276 | @end 277 | 278 | static void FixKeyLengths( CCAlgorithm algorithm, NSMutableData * keyData, NSMutableData * ivData ) 279 | { 280 | NSUInteger keyLength = [keyData length]; 281 | switch ( algorithm ) 282 | { 283 | case kCCAlgorithmAES128: 284 | { 285 | if ( keyLength < 16 ) 286 | { 287 | [keyData setLength: 16]; 288 | } 289 | else if ( keyLength < 24 ) 290 | { 291 | [keyData setLength: 24]; 292 | } 293 | else 294 | { 295 | [keyData setLength: 32]; 296 | } 297 | 298 | break; 299 | } 300 | 301 | case kCCAlgorithmDES: 302 | { 303 | [keyData setLength: 8]; 304 | break; 305 | } 306 | 307 | case kCCAlgorithm3DES: 308 | { 309 | [keyData setLength: 24]; 310 | break; 311 | } 312 | 313 | case kCCAlgorithmCAST: 314 | { 315 | if ( keyLength < 5 ) 316 | { 317 | [keyData setLength: 5]; 318 | } 319 | else if ( keyLength > 16 ) 320 | { 321 | [keyData setLength: 16]; 322 | } 323 | 324 | break; 325 | } 326 | 327 | case kCCAlgorithmRC4: 328 | { 329 | if ( keyLength > 512 ) 330 | [keyData setLength: 512]; 331 | break; 332 | } 333 | 334 | default: 335 | break; 336 | } 337 | 338 | [ivData setLength: [keyData length]]; 339 | } 340 | 341 | @implementation NSData (LowLevelCommonCryptor) 342 | 343 | - (NSData *) _runCryptor: (CCCryptorRef) cryptor result: (CCCryptorStatus *) status 344 | { 345 | size_t bufsize = CCCryptorGetOutputLength( cryptor, (size_t)[self length], true ); 346 | void * buf = malloc( bufsize ); 347 | size_t bufused = 0; 348 | size_t bytesTotal = 0; 349 | *status = CCCryptorUpdate( cryptor, [self bytes], (size_t)[self length], 350 | buf, bufsize, &bufused ); 351 | if ( *status != kCCSuccess ) 352 | { 353 | free( buf ); 354 | return ( nil ); 355 | } 356 | 357 | bytesTotal += bufused; 358 | 359 | // From Brent Royal-Gordon (Twitter: architechies): 360 | // Need to update buf ptr past used bytes when calling CCCryptorFinal() 361 | *status = CCCryptorFinal( cryptor, buf + bufused, bufsize - bufused, &bufused ); 362 | if ( *status != kCCSuccess ) 363 | { 364 | free( buf ); 365 | return ( nil ); 366 | } 367 | 368 | bytesTotal += bufused; 369 | 370 | return ( [NSData dataWithBytesNoCopy: buf length: bytesTotal] ); 371 | } 372 | 373 | - (NSData *) dataEncryptedUsingAlgorithm: (CCAlgorithm) algorithm 374 | key: (id) key 375 | error: (CCCryptorStatus *) error 376 | { 377 | return ( [self dataEncryptedUsingAlgorithm: algorithm 378 | key: key 379 | initializationVector: nil 380 | options: 0 381 | error: error] ); 382 | } 383 | 384 | - (NSData *) dataEncryptedUsingAlgorithm: (CCAlgorithm) algorithm 385 | key: (id) key 386 | options: (CCOptions) options 387 | error: (CCCryptorStatus *) error 388 | { 389 | return ( [self dataEncryptedUsingAlgorithm: algorithm 390 | key: key 391 | initializationVector: nil 392 | options: options 393 | error: error] ); 394 | } 395 | 396 | - (NSData *) dataEncryptedUsingAlgorithm: (CCAlgorithm) algorithm 397 | key: (id) key 398 | initializationVector: (id) iv 399 | options: (CCOptions) options 400 | error: (CCCryptorStatus *) error 401 | { 402 | CCCryptorRef cryptor = NULL; 403 | CCCryptorStatus status = kCCSuccess; 404 | 405 | NSParameterAssert([key isKindOfClass: [NSData class]] || [key isKindOfClass: [NSString class]]); 406 | NSParameterAssert(iv == nil || [iv isKindOfClass: [NSData class]] || [iv isKindOfClass: [NSString class]]); 407 | 408 | NSMutableData * keyData, * ivData; 409 | if ( [key isKindOfClass: [NSData class]] ) 410 | keyData = (NSMutableData *) [key mutableCopy]; 411 | else 412 | keyData = [[key dataUsingEncoding: NSUTF8StringEncoding] mutableCopy]; 413 | 414 | if ( [iv isKindOfClass: [NSString class]] ) 415 | ivData = [[iv dataUsingEncoding: NSUTF8StringEncoding] mutableCopy]; 416 | else 417 | ivData = (NSMutableData *) [iv mutableCopy]; // data or nil 418 | 419 | #if !__has_feature(objc_arc) 420 | [keyData autorelease]; 421 | [ivData autorelease]; 422 | #endif 423 | // ensure correct lengths for key and iv data, based on algorithms 424 | FixKeyLengths( algorithm, keyData, ivData ); 425 | 426 | status = CCCryptorCreate( kCCEncrypt, algorithm, options, 427 | [keyData bytes], [keyData length], [ivData bytes], 428 | &cryptor ); 429 | 430 | if ( status != kCCSuccess ) 431 | { 432 | if ( error != NULL ) 433 | *error = status; 434 | return ( nil ); 435 | } 436 | 437 | NSData * result = [self _runCryptor: cryptor result: &status]; 438 | if ( (result == nil) && (error != NULL) ) 439 | *error = status; 440 | 441 | CCCryptorRelease( cryptor ); 442 | 443 | return ( result ); 444 | } 445 | 446 | - (NSData *) decryptedDataUsingAlgorithm: (CCAlgorithm) algorithm 447 | key: (id) key // data or string 448 | error: (CCCryptorStatus *) error 449 | { 450 | return ( [self decryptedDataUsingAlgorithm: algorithm 451 | key: key 452 | initializationVector: nil 453 | options: 0 454 | error: error] ); 455 | } 456 | 457 | - (NSData *) decryptedDataUsingAlgorithm: (CCAlgorithm) algorithm 458 | key: (id) key // data or string 459 | options: (CCOptions) options 460 | error: (CCCryptorStatus *) error 461 | { 462 | return ( [self decryptedDataUsingAlgorithm: algorithm 463 | key: key 464 | initializationVector: nil 465 | options: options 466 | error: error] ); 467 | } 468 | 469 | - (NSData *) decryptedDataUsingAlgorithm: (CCAlgorithm) algorithm 470 | key: (id) key // data or string 471 | initializationVector: (id) iv // data or string 472 | options: (CCOptions) options 473 | error: (CCCryptorStatus *) error 474 | { 475 | CCCryptorRef cryptor = NULL; 476 | CCCryptorStatus status = kCCSuccess; 477 | 478 | NSParameterAssert([key isKindOfClass: [NSData class]] || [key isKindOfClass: [NSString class]]); 479 | NSParameterAssert(iv == nil || [iv isKindOfClass: [NSData class]] || [iv isKindOfClass: [NSString class]]); 480 | 481 | NSMutableData * keyData, * ivData; 482 | if ( [key isKindOfClass: [NSData class]] ) 483 | keyData = (NSMutableData *) [key mutableCopy]; 484 | else 485 | keyData = [[key dataUsingEncoding: NSUTF8StringEncoding] mutableCopy]; 486 | 487 | if ( [iv isKindOfClass: [NSString class]] ) 488 | ivData = [[iv dataUsingEncoding: NSUTF8StringEncoding] mutableCopy]; 489 | else 490 | ivData = (NSMutableData *) [iv mutableCopy]; // data or nil 491 | 492 | #if !__has_feature(objc_arc) 493 | [keyData autorelease]; 494 | [ivData autorelease]; 495 | #endif 496 | 497 | // ensure correct lengths for key and iv data, based on algorithms 498 | FixKeyLengths( algorithm, keyData, ivData ); 499 | 500 | status = CCCryptorCreate( kCCDecrypt, algorithm, options, 501 | [keyData bytes], [keyData length], [ivData bytes], 502 | &cryptor ); 503 | 504 | if ( status != kCCSuccess ) 505 | { 506 | if ( error != NULL ) 507 | *error = status; 508 | return ( nil ); 509 | } 510 | 511 | NSData * result = [self _runCryptor: cryptor result: &status]; 512 | if ( (result == nil) && (error != NULL) ) 513 | *error = status; 514 | 515 | CCCryptorRelease( cryptor ); 516 | 517 | return ( result ); 518 | } 519 | 520 | @end 521 | 522 | @implementation NSData (CommonHMAC) 523 | 524 | - (NSData *) HMACWithAlgorithm: (CCHmacAlgorithm) algorithm 525 | { 526 | return ( [self HMACWithAlgorithm: algorithm key: nil] ); 527 | } 528 | 529 | - (NSData *) HMACWithAlgorithm: (CCHmacAlgorithm) algorithm key: (id) key 530 | { 531 | NSParameterAssert(key == nil || [key isKindOfClass: [NSData class]] || [key isKindOfClass: [NSString class]]); 532 | 533 | NSData * keyData = nil; 534 | if ( [key isKindOfClass: [NSString class]] ) 535 | keyData = [key dataUsingEncoding: NSUTF8StringEncoding]; 536 | else 537 | keyData = (NSData *) key; 538 | 539 | // this could be either CC_SHA1_DIGEST_LENGTH or CC_MD5_DIGEST_LENGTH. SHA1 is larger. 540 | unsigned char buf[CC_SHA1_DIGEST_LENGTH]; 541 | CCHmac( algorithm, [keyData bytes], [keyData length], [self bytes], [self length], buf ); 542 | 543 | return ( [NSData dataWithBytes: buf length: (algorithm == kCCHmacAlgMD5 ? CC_MD5_DIGEST_LENGTH : CC_SHA1_DIGEST_LENGTH)] ); 544 | } 545 | 546 | @end -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/NSString+Base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Base64.h 3 | // Gurpartap Singh 4 | // 5 | // Created by Gurpartap Singh on 06/05/12. 6 | // Copyright (c) 2012 Gurpartap Singh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (Base64Additions) 12 | 13 | + (NSString *)base64StringFromData:(NSData *)data length:(NSUInteger)length; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AESCrypt/NSString+Base64.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSStringAdditions.m 3 | // Gurpartap Singh 4 | // 5 | // Created by Gurpartap Singh on 06/05/12. 6 | // Copyright (c) 2012 Gurpartap Singh. All rights reserved. 7 | // 8 | 9 | #import "NSString+Base64.h" 10 | 11 | static char base64EncodingTable[64] = { 12 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 13 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 14 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 15 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' 16 | }; 17 | 18 | @implementation NSString (Base64Additions) 19 | 20 | + (NSString *)base64StringFromData: (NSData *)data length: (NSUInteger)length { 21 | unsigned long ixtext, lentext; 22 | long ctremaining; 23 | unsigned char input[3], output[4]; 24 | short i, charsonline = 0, ctcopy; 25 | const unsigned char *raw; 26 | NSMutableString *result; 27 | 28 | lentext = [data length]; 29 | if (lentext < 1) { 30 | return @""; 31 | } 32 | result = [NSMutableString stringWithCapacity: lentext]; 33 | raw = [data bytes]; 34 | ixtext = 0; 35 | 36 | while (true) { 37 | ctremaining = lentext - ixtext; 38 | if (ctremaining <= 0) { 39 | break; 40 | } 41 | for (i = 0; i < 3; i++) { 42 | unsigned long ix = ixtext + i; 43 | if (ix < lentext) { 44 | input[i] = raw[ix]; 45 | } 46 | else { 47 | input[i] = 0; 48 | } 49 | } 50 | output[0] = (input[0] & 0xFC) >> 2; 51 | output[1] = ((input[0] & 0x03) << 4) | ((input[1] & 0xF0) >> 4); 52 | output[2] = ((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6); 53 | output[3] = input[2] & 0x3F; 54 | ctcopy = 4; 55 | switch (ctremaining) { 56 | case 1: 57 | ctcopy = 2; 58 | break; 59 | case 2: 60 | ctcopy = 3; 61 | break; 62 | } 63 | 64 | for (i = 0; i < ctcopy; i++) { 65 | [result appendString: [NSString stringWithFormat: @"%c", base64EncodingTable[output[i]]]]; 66 | } 67 | 68 | for (i = ctcopy; i < 4; i++) { 69 | [result appendString: @"="]; 70 | } 71 | 72 | ixtext += 3; 73 | charsonline += 4; 74 | 75 | if ((length > 0) && (charsonline >= length)) { 76 | charsonline = 0; 77 | } 78 | } 79 | return result; 80 | } 81 | 82 | @end -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/ANKeyValueData.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueData.h 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/17. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ANPersistentData.h" 10 | #import "ANKeyValueProtocol.h" 11 | 12 | @interface ANKeyValueData : ANPersistentData 13 | 14 | @property (nonatomic, strong) NSMutableDictionary *keyValueMap; 15 | 16 | - (void)setValue:(id)aValue withKey:(id )aKey; 17 | 18 | - (id)valueWithKey:(id)aKey; 19 | 20 | - (void)setDataValue:(id )aValue withKey:(id )aKey; 21 | 22 | - (id)dataValueWithKey:(id)aKey; 23 | 24 | - (NSArray *)allKeys; 25 | 26 | - (NSArray *)allValues; 27 | 28 | - (void)removeValueWithKey:(id )aKey; 29 | 30 | - (void)removeAllValues; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/ANKeyValueData.m: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueData.m 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/17. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ANKeyValueData.h" 10 | #import "ANKeyValueStrategy.h" 11 | 12 | NSString *const GlobalDataBlockArchivePathPrefix = @"$$PATH="; 13 | 14 | @interface ANKeyValueData() 15 | { 16 | @private 17 | __strong NSCache *_dataBlockCache; 18 | __strong NSMutableDictionary *_removedDataPathMap; 19 | } 20 | 21 | @end 22 | 23 | @implementation ANKeyValueData 24 | 25 | + (id)data:(NSString *)name version:(NSString *)version domain:(NSString *)domain level:(ANPersistentLevel)level 26 | { 27 | id data = [super data:name version:version domain:domain level:level]; 28 | // 容错处理,确保key-value的容器ready,springox(20141225) 29 | if ([data respondsToSelector:@selector(keyValueMap)]) { 30 | ANKeyValueData *kvData = (ANKeyValueData *)data; 31 | if (nil == kvData.keyValueMap) { 32 | kvData.keyValueMap = [NSMutableDictionary dictionary]; 33 | } 34 | return data; 35 | } 36 | return nil; 37 | } 38 | 39 | + (id)strategy:(ANPersistentLevel)level 40 | { 41 | return [[ANKeyValueStrategy alloc] initWithLevel:level]; 42 | } 43 | 44 | - (id)init 45 | { 46 | self = [super init]; 47 | if (self) { 48 | _keyValueMap = [NSMutableDictionary dictionary]; 49 | _dataBlockCache = [[NSCache alloc] init]; 50 | _removedDataPathMap = [NSMutableDictionary dictionary]; 51 | } 52 | return self; 53 | } 54 | 55 | - (id)initWithCoder:(NSCoder *)aDecoder 56 | { 57 | self = [super initWithCoder:aDecoder]; 58 | if (self) { 59 | _dataBlockCache = [[NSCache alloc] init]; 60 | _removedDataPathMap = [NSMutableDictionary dictionary]; 61 | } 62 | return self; 63 | } 64 | 65 | - (void)encodeWithCoder:(NSCoder *)aCoder 66 | { 67 | [super encodeWithCoder:aCoder]; 68 | } 69 | 70 | - (void)dealloc 71 | { 72 | // do nothing 73 | } 74 | 75 | - (void)clearData 76 | { 77 | [_dataLock lock]; 78 | [_keyValueMap removeAllObjects]; 79 | [_dataBlockCache removeAllObjects]; 80 | [_removedDataPathMap removeAllObjects]; 81 | [_dataLock unlock]; 82 | 83 | [super clearData]; 84 | } 85 | 86 | - (void)archiveWillStart 87 | { 88 | [super archiveWillStart]; 89 | } 90 | 91 | - (void)archiveDidFinish 92 | { 93 | [_dataLock lock]; 94 | NSFileManager *fm = [NSFileManager defaultManager]; 95 | NSError *error = nil; 96 | @autoreleasepool { 97 | for (NSString *path in _removedDataPathMap.allValues) { 98 | if ([path isKindOfClass:[NSString class]]) { 99 | error = nil; 100 | [fm removeItemAtPath:path error:&error]; 101 | if (nil != error) { 102 | NSLog(@"Key Value Data remove data block %@ fail:%@\n", path, error); 103 | } else { 104 | NSLog(@"Key Value Data remove data block %@ success\n", path); 105 | } 106 | } 107 | } 108 | } 109 | [_dataLock unlock]; 110 | 111 | [super archiveDidFinish]; 112 | } 113 | 114 | - (void)setValue:(id )aValue withKey:(id )aKey 115 | { 116 | [_dataLock lock]; 117 | [_keyValueMap setObject:aValue forKey:aKey]; 118 | [_dataLock unlock]; 119 | } 120 | 121 | - (id)valueWithKey:(id)aKey 122 | { 123 | [_dataLock lock]; 124 | id value = [_keyValueMap objectForKey:aKey]; 125 | [_dataLock unlock]; 126 | return value; 127 | } 128 | 129 | - (void)setDataValue:(id )aValue withKey:(id )aKey 130 | { 131 | if ([aValue respondsToSelector:@selector(shouldEncodeWithDataBlock)]) { 132 | if ([aValue shouldEncodeWithDataBlock]) { 133 | [_dataLock lock]; 134 | [_dataBlockCache setObject:aValue forKey:aKey]; 135 | // 给Map写入一个索引值,即归档前缀和key组成,springox(20150105) 136 | NSString *newValue = [NSString stringWithFormat:@"%@%@", GlobalDataBlockArchivePathPrefix, aKey]; 137 | [_keyValueMap setObject:newValue forKey:aKey]; 138 | // 如果一个被remove的key重新被使用,那么删除列表里面的节点将变得不合理,springox(20150105) 139 | [_removedDataPathMap removeObjectForKey:aKey]; 140 | [_dataLock unlock]; 141 | 142 | // 做好data block的归档任务,springox(20150105) 143 | NSString *dataPath = [(ANKeyValueStrategy *)self.strategy dataBlockPath:self primaryKey:(NSString *)aKey]; 144 | if (nil != dataPath) { 145 | NSLog(@"Data block archive %@", dataPath); 146 | [NSKeyedArchiver archiveRootObject:aValue toFile:dataPath]; 147 | return; 148 | } 149 | } 150 | } 151 | 152 | [_dataLock lock]; 153 | [_keyValueMap setObject:aValue forKey:aKey]; 154 | [_dataLock unlock]; 155 | } 156 | 157 | - (id)dataValueWithKey:(id)aKey 158 | { 159 | [_dataLock lock]; 160 | id value = [_keyValueMap objectForKey:aKey]; 161 | // 判断是否有data block,springox(20150105) 162 | if ([value isKindOfClass:[NSString class]]) { 163 | NSString *valueStr = (NSString *)value; 164 | if ([valueStr hasPrefix:GlobalDataBlockArchivePathPrefix]) { 165 | NSString *tempValue = [_dataBlockCache objectForKey:aKey]; 166 | if (nil == tempValue) { 167 | NSString *tempKey = [valueStr stringByReplacingOccurrencesOfString:GlobalDataBlockArchivePathPrefix withString:@""]; 168 | NSString *dataPath = [(ANKeyValueStrategy *)self.strategy dataBlockPath:self primaryKey:(NSString *)tempKey]; 169 | if (nil != dataPath) { 170 | tempValue = [NSKeyedUnarchiver unarchiveObjectWithFile:dataPath]; 171 | if (nil != tempValue) { 172 | value = tempValue; 173 | [_dataBlockCache setObject:value forKey:aKey]; 174 | } 175 | } 176 | } else { 177 | value = tempValue; 178 | } 179 | } 180 | } 181 | [_dataLock unlock]; 182 | return value; 183 | } 184 | 185 | - (NSArray *)allKeys 186 | { 187 | return [_keyValueMap allKeys]; 188 | } 189 | 190 | - (NSArray *)allValues 191 | { 192 | return [_keyValueMap allValues]; 193 | } 194 | 195 | - (void)removeValueWithKey:(id )aKey 196 | { 197 | [_dataLock lock]; 198 | id value = [_keyValueMap objectForKey:aKey]; 199 | 200 | // 判断是否有data block,springox(20150105) 201 | if ([value isKindOfClass:[NSString class]]) { 202 | NSString *valueStr = (NSString *)value; 203 | if ([valueStr hasPrefix:GlobalDataBlockArchivePathPrefix]) { 204 | NSString *tempKey = [valueStr stringByReplacingOccurrencesOfString:GlobalDataBlockArchivePathPrefix withString:@""]; 205 | NSString *dataPath = [(ANKeyValueStrategy *)self.strategy dataBlockPath:self primaryKey:(NSString *)tempKey]; 206 | if (nil != dataPath) { 207 | [_removedDataPathMap setObject:dataPath forKey:aKey]; 208 | } 209 | } 210 | } 211 | 212 | [_keyValueMap removeObjectForKey:aKey]; 213 | [_dataLock unlock]; 214 | } 215 | 216 | - (void)removeAllValues 217 | { 218 | [self clearData]; 219 | } 220 | 221 | @end 222 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/ANKeyValueStrategy.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueStrategy.h 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/17. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ANPersistentStrategy.h" 10 | 11 | @class ANKeyValueData; 12 | 13 | @interface ANKeyValueStrategy : ANPersistentStrategy 14 | 15 | - (NSString *)dataBlockPath:(ANKeyValueData *)data primaryKey:(NSString *)key; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/ANKeyValueStrategy.m: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueStrategy.m 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/17. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ANKeyValueStrategy.h" 10 | #import "ANKeyValueData.h" 11 | 12 | @implementation ANKeyValueStrategy 13 | 14 | - (id)init 15 | { 16 | self = [super init]; 17 | if (self) { 18 | 19 | // do nothing 20 | 21 | } 22 | return self; 23 | } 24 | 25 | - (void)dealloc 26 | { 27 | // do nothing 28 | } 29 | 30 | - (NSString *)dataBlockPath:(ANKeyValueData *)data primaryKey:(NSString *)key 31 | { 32 | if ([key isKindOfClass:[NSString class]] && 0 < [key length]) { 33 | NSString *localDirPath = [self localDirectory:data.name domain:data.domain]; 34 | NSString *blockDirPath = [self localDirectory:localDirPath relativePath:@"Data"]; 35 | if (nil != blockDirPath) { 36 | return [blockDirPath stringByAppendingPathComponent:[key MD5String]]; 37 | } 38 | } 39 | return nil; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/ANKeyValueTable.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueTable.h 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/12. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ANKeyValueData.h" 11 | 12 | @interface ANKeyValueTable : NSObject 13 | 14 | /*! @brief 表创建的类方法 15 | 16 | * 通过传入的参数,创建、初始化并返回表 17 | * @param name 一般填写业务名称,不可以为空 18 | * @param version 版本号管理,默认为空 19 | * @param resumable 用于标记该表数据是否可恢复的,可恢复数据会存储到Library/Caches目录,否则会存储到Library/Application Support目录 20 | */ 21 | + (id)tableWithName:(NSString *)name version:(NSString *)version resumable:(BOOL)resumable; 22 | 23 | /*! @brief 表创建的类方法,数据会存储到Document目录 24 | * 25 | * 通过传入的参数,创建、初始化并返回表 26 | * @param name 一般填写业务名称,不可以为空 27 | * @param version 版本号管理,默认为空 28 | */ 29 | + (id)tableForUser:(NSString *)name version:(NSString *)version; 30 | 31 | /*! @brief 默认表创建的类方法,数据会存储到Document目录 32 | 33 | * 快速创建一张默认表,可用于App配置项或者状态保持 34 | */ 35 | + (id)userDefaultTable; 36 | 37 | /*! @brief 38 | 39 | * 清空低级别的文件,springox(20151127) 40 | */ 41 | + (void)clearResumableTables; 42 | 43 | /*! @brief 44 | 45 | * 清空所有级别的文件,springox(20160408) 46 | */ 47 | + (void)clearAllLevelTables; 48 | 49 | #pragma mark - 50 | /*! @brief 表的初始化方法 51 | * 52 | * @param data 数据对象 53 | */ 54 | - (id)initWithData:(ANKeyValueData *)data; 55 | 56 | /*! @brief 持久化操作 57 | * 58 | * 支持持久化操作,强制执行,springox(20150618) 59 | */ 60 | - (void)synchronize; 61 | 62 | /*! @brief 持久化操作 63 | * 64 | * 支持持久化操作,可选择定时执行还是强制执行,atomically==YES为定时执行,定时执行对于频繁持久化操作更有效,减少重复持久化操作的浪费,springox(20150618) 65 | */ 66 | - (void)synchronize:(BOOL)atomically; 67 | 68 | /*! @brief 持久化状态判断 69 | * 70 | */ 71 | - (BOOL)isArchiving; 72 | 73 | /*! @brief 表清空操作 74 | * 75 | * 该操作会清空表内存和本地磁盘上存储的数据 76 | */ 77 | - (void)clear; 78 | 79 | #pragma mark - 80 | /*! @brief Value 81 | * 82 | * 最基础的set方法 83 | * @param key 84 | */ 85 | - (void)setValue:(id )value withKey:(id )key; 86 | 87 | /*! @brief Int 88 | * 89 | * @param key 90 | */ 91 | - (void)setInt:(int)value withKey:(id )key; 92 | 93 | /*! @brief Integer 94 | * 95 | * @param key 96 | */ 97 | - (void)setInteger:(NSInteger)value withKey:(id )key; 98 | 99 | /*! @brief Float 100 | * 101 | * @param key 102 | */ 103 | - (void)setFloat:(float)value withKey:(id )key; 104 | 105 | /*! @brief Double 106 | * 107 | * @param key 108 | */ 109 | - (void)setDouble:(double)value withKey:(id )key; 110 | 111 | /*! @brief Bool 112 | * 113 | * @param key 114 | */ 115 | - (void)setBool:(BOOL)value withKey:(id )key; 116 | 117 | /*! @brief 字符串加密 118 | * 119 | * @param key 120 | */ 121 | - (void)encryptContent:(NSString *)content withKey:(id )key; 122 | 123 | /*! @brief 添加容器类数据 124 | * 125 | * @param key 126 | */ 127 | - (void)setContainer:(id)container withKey:(id )key; 128 | 129 | /*! @brief 添加资源类数据,会单独针对资源类数据做优化,springox(20150922) 130 | * 131 | * @param key 132 | */ 133 | - (void)setResource:(id)resource withKey:(id )key; 134 | 135 | #pragma mark - 136 | /*! @brief value 137 | * 138 | * 最基础的get方法,该方法返回值默认是copy操作,如果支持“NSMutableCopying”协议是mutableCopy操作 139 | * @param key 140 | */ 141 | - (id)valueWithKey:(id )key; 142 | 143 | /*! @brief int 144 | * 145 | * @param key 146 | */ 147 | - (int)intWithKey:(id )key; 148 | 149 | /*! @brief integer 150 | * 151 | * @param key 152 | */ 153 | - (NSInteger)integerWithKey:(id )key; 154 | 155 | /*! @brief float 156 | * 157 | * @param key 158 | */ 159 | - (float)floatWithKey:(id )key; 160 | 161 | /*! @brief double 162 | * 163 | * @param key 164 | */ 165 | - (double)doubleWithKey:(id )key; 166 | 167 | /*! @brief bool 168 | * 169 | * @param key 170 | */ 171 | - (BOOL)boolWithKey:(id )key; 172 | 173 | /*! @brief 字符串解密 174 | * 175 | * @param key 176 | */ 177 | - (id)decryptContentWithKey:(id )key; 178 | 179 | /*! @brief get容器 180 | * 181 | * @param key 182 | */ 183 | - (id)containerWithKey:(id )key; 184 | 185 | /*! @brief value 186 | * 187 | * 获取资源文件的方法,该方法返回值默认是copy操作,如果支持“NSMutableCopying”协议是mutableCopy操作 188 | * @param key 189 | */ 190 | - (id)resourceWithKey:(id )key; 191 | 192 | #pragma mark - 193 | /*! @brief 获取所有keys 194 | * 195 | */ 196 | - (NSArray *)allKeys; 197 | 198 | /*! @brief 获取所有values 199 | * 200 | */ 201 | - (NSArray *)allValues; 202 | 203 | /*! @brief 移除value 204 | * 205 | * @param key 206 | */ 207 | - (void)removeValueWithKey:(id )key; 208 | 209 | /*! @brief 移除所有value 210 | * 211 | */ 212 | - (void)removeAllValues; 213 | 214 | @end 215 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/ANKeyValueTable.m: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueTable.m 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/12. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ANKeyValueTable.h" 10 | #import "ANKeyValueData.h" 11 | #import "ANMemoryPage.h" 12 | #import "AESCrypt.h" 13 | 14 | #define PERSISTENT_DOMAIN @"KeyValueStorage" 15 | #define AES_CRYPT_PASSWORD @"xq$\"1#.H" 16 | 17 | static ANMemoryPage *GlobalDataCache; 18 | 19 | @interface ANKeyValueTable() 20 | { 21 | @private 22 | __strong ANKeyValueData *_keyValueData; 23 | __strong NSString *_dataName; 24 | __strong NSString *_dataVersion; 25 | ANPersistentLevel _dataLevel; 26 | } 27 | 28 | @end 29 | 30 | @implementation ANKeyValueTable 31 | 32 | + (id)tableWithName:(NSString *)name version:(NSString *)version resumable:(BOOL)resumable 33 | { 34 | if (![name isKindOfClass:[NSString class]] || 0 == [name length]) { 35 | return nil; 36 | } 37 | 38 | if (![version isKindOfClass:[NSString class]] || 0 == [version length]) { 39 | version = @""; 40 | } 41 | 42 | // 预先加载共享核心data,springox(20151201) 43 | ANPersistentLevel level = ANPersistentLevelResumableCaches; 44 | if (!resumable) { 45 | level = ANPersistentLevelApplicationSupport; 46 | } 47 | NSString *cacheName = [NSString stringWithFormat:@"L%u-%@", level, name]; 48 | ANMemoryPage *cache = [self dataCache]; 49 | @synchronized (self) { 50 | ANKeyValueData *data = [cache object:cacheName version:version]; 51 | if (nil == data) { 52 | data = [ANKeyValueData data:name version:version domain:PERSISTENT_DOMAIN level:level]; 53 | [cache setObject:data name:cacheName version:version]; 54 | } 55 | } 56 | 57 | // 创建一个表对象作为数据交互接口,springox(20151201) 58 | return [[ANKeyValueTable alloc] initWithName:name version:version level:level]; 59 | } 60 | 61 | + (id)tableForUser:(NSString *)name version:(NSString *)version 62 | { 63 | if (![name isKindOfClass:[NSString class]] || 0 == [name length]) { 64 | return nil; 65 | } 66 | 67 | if (![version isKindOfClass:[NSString class]] || 0 == [version length]) { 68 | version = @""; 69 | } 70 | 71 | // 预先加载共享核心data,springox(20151201) 72 | ANPersistentLevel level = ANPersistentLevelUserDocument; 73 | NSString *cacheName = [NSString stringWithFormat:@"L%u-%@", level, name]; 74 | ANMemoryPage *cache = [self dataCache]; 75 | @synchronized (self) { 76 | ANKeyValueData *data = [cache object:cacheName version:version]; 77 | if (nil == data) { 78 | data = [ANKeyValueData data:name version:version domain:PERSISTENT_DOMAIN level:level]; 79 | [cache setObject:data name:cacheName version:version]; 80 | } 81 | } 82 | 83 | // 创建一个表对象作为数据交互接口,springox(20151201) 84 | return [[ANKeyValueTable alloc] initWithName:name version:version level:level]; 85 | } 86 | 87 | + (id)userDefaultTable 88 | { 89 | static ANKeyValueTable *defTable; 90 | @synchronized(self) { 91 | if (nil == defTable) { 92 | defTable = [self tableForUser:@"UserDefault" version:@"1.0.0"]; 93 | } 94 | } 95 | return defTable; 96 | } 97 | 98 | + (id)defaultLoginTable 99 | { 100 | // 5.5 优化了写文件性能,统一异步操作,暴露前后调用接口时文件读写有时序问题,先要求对登录表做静态化操作, 101 | // 目前绝大部分table都是业务持有table对象,大大减少读文件的风险(内存已更新文件还未及时更新),jiachunke 102 | //if ( ![UIDevice isIOS7] ) { 103 | // return [ANKeyValueTable tableForUser:@"LoginUserInfo" version:@"1.0.0"]; 104 | //} 105 | //在ios 7下,当出现内存警告时,nscache会被系统释放,同时首页收到内存警告也会释放,会导致死锁,将loginTable设置为静态变量确保不被系统释放,charli,jiachun 4.5.2 20151217 106 | static id _loginTable = nil; 107 | @synchronized(self) { 108 | if (nil == _loginTable) { 109 | _loginTable = [ANKeyValueTable tableForUser:@"LoginUserInfo" version:@"1.0.0"]; 110 | } 111 | } 112 | return _loginTable; 113 | } 114 | 115 | + (ANMemoryPage *)dataCache 116 | { 117 | if (nil == GlobalDataCache) { 118 | static dispatch_once_t onceToken; 119 | dispatch_once(&onceToken, ^{ 120 | 121 | GlobalDataCache = [[ANMemoryPage alloc] init]; 122 | }); 123 | } 124 | return GlobalDataCache; 125 | } 126 | 127 | + (void)clearResumableTables 128 | { 129 | [ANKeyValueData clearCache:PERSISTENT_DOMAIN level:ANPersistentLevelResumableCaches]; 130 | } 131 | 132 | + (void)clearAllLevelTables 133 | { 134 | [ANKeyValueData clearCache:PERSISTENT_DOMAIN level:ANPersistentLevelResumableCaches]; 135 | [ANKeyValueData clearCache:PERSISTENT_DOMAIN level:ANPersistentLevelApplicationSupport]; 136 | [ANKeyValueData clearCache:PERSISTENT_DOMAIN level:ANPersistentLevelUserDocument]; 137 | } 138 | 139 | - (ANKeyValueData *)keyValueData 140 | { 141 | if (nil != _keyValueData) { 142 | return _keyValueData; 143 | } else { 144 | if (![_dataName isKindOfClass:[NSString class]] || 0 == [_dataName length]) { 145 | return nil; 146 | } 147 | 148 | NSString *cacheName = [NSString stringWithFormat:@"L%u-%@", _dataLevel, _dataName]; 149 | ANMemoryPage *cache = [[self class] dataCache]; 150 | _keyValueData = [cache object:cacheName version:_dataVersion]; 151 | if (nil == _keyValueData) { 152 | ANKeyValueData *data = [ANKeyValueData data:_dataName version:_dataVersion domain:PERSISTENT_DOMAIN level:_dataLevel]; 153 | if (nil != data) { 154 | [cache setObject:data name:cacheName version:_dataVersion]; 155 | // 在模拟器上,启用内存memory warning功能,可能会导致setObject后cache马上触发evict Object, 156 | // 所以这里刻意把_keyValueData和notification延后设置,这样,即使evict Object在这里 157 | // 被同步方式提前触发,_keyValueData也能因为是后面set而继续可用,不会导致_keyValueData为nil时, 158 | // 重新生成一个又被evict Object触发马上重新设置为nil,陷入不可用的循环,springox(20150316) 159 | _keyValueData = data; 160 | } 161 | } 162 | 163 | return _keyValueData; 164 | } 165 | } 166 | 167 | #pragma mark - 168 | - (id)initWithData:(ANKeyValueData *)data 169 | { 170 | self = [super init]; 171 | if (self) { 172 | _keyValueData = data; 173 | } 174 | return self; 175 | } 176 | 177 | - (id)initWithName:(NSString *)name version:(NSString *)version level:(ANPersistentLevel)level 178 | { 179 | self = [super init]; 180 | if (self) { 181 | _dataName = name; 182 | _dataVersion = version; 183 | _dataLevel = level; 184 | } 185 | return self; 186 | } 187 | 188 | - (void)dealloc 189 | { 190 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 191 | [_keyValueData archiveNow]; 192 | } 193 | 194 | - (void)cacheWillEvictObjectNotification:(NSNotification *)not 195 | { 196 | if (nil != _keyValueData && not.object == _keyValueData) { 197 | _keyValueData = nil; 198 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 199 | } 200 | } 201 | 202 | - (void)synchronize 203 | { 204 | // 默认强制持久化操作,springox(20150618) 205 | [self synchronize:NO]; 206 | } 207 | 208 | - (void)synchronize:(BOOL)atomically 209 | { 210 | if (atomically) { 211 | [[self keyValueData] setNeedToArchive:self]; 212 | } else { 213 | [[self keyValueData] fireArchive]; 214 | } 215 | } 216 | 217 | - (BOOL)isArchiving 218 | { 219 | return [[self keyValueData] isArchiving] || [[self keyValueData] isWillArchive]; 220 | } 221 | 222 | - (void)clear 223 | { 224 | [[self keyValueData] clearData]; 225 | } 226 | 227 | #pragma mark - 228 | - (void)setValue:(id )value withKey:(id )key 229 | { 230 | [[self keyValueData] setValue:value withKey:key]; 231 | 232 | [self synchronize:YES]; 233 | } 234 | 235 | - (void)setInt:(int)value withKey:(id )key 236 | { 237 | NSNumber *intNum = [NSNumber numberWithInt:value]; 238 | [[self keyValueData] setValue:intNum withKey:key]; 239 | 240 | [self synchronize:YES]; 241 | } 242 | 243 | - (void)setInteger:(NSInteger)value withKey:(id )key 244 | { 245 | NSNumber *integerNum = [NSNumber numberWithInteger:value]; 246 | [[self keyValueData] setValue:integerNum withKey:key]; 247 | 248 | [self synchronize:YES]; 249 | } 250 | 251 | - (void)setFloat:(float)value withKey:(id )key 252 | { 253 | NSNumber *floatNum = [NSNumber numberWithFloat:value]; 254 | [[self keyValueData] setValue:floatNum withKey:key]; 255 | 256 | [self synchronize:YES]; 257 | } 258 | 259 | - (void)setDouble:(double)value withKey:(id )key 260 | { 261 | NSNumber *doubleNum = [NSNumber numberWithDouble:value]; 262 | [[self keyValueData] setValue:doubleNum withKey:key]; 263 | 264 | [self synchronize:YES]; 265 | } 266 | 267 | - (void)setBool:(BOOL)value withKey:(id )key 268 | { 269 | NSNumber *boolNum = [NSNumber numberWithBool:value]; 270 | [[self keyValueData] setValue:boolNum withKey:key]; 271 | 272 | [self synchronize:YES]; 273 | } 274 | 275 | - (void)encryptContent:(NSString *)content withKey:(id )key 276 | { 277 | if (nil == content || ![content isKindOfClass:[NSString class]]) { 278 | return; 279 | } 280 | 281 | NSString *cryptedContent = [AESCrypt encrypt:content password:AES_CRYPT_PASSWORD]; 282 | [[self keyValueData] setValue:cryptedContent withKey:key]; 283 | 284 | [self synchronize:YES]; 285 | } 286 | 287 | - (void)setContainer:(id)container withKey:(id )key 288 | { 289 | if ([container isKindOfClass:[NSSet class]] || 290 | [container isKindOfClass:[NSArray class]] || 291 | [container isKindOfClass:[NSDictionary class]]) { 292 | 293 | [self setValue:container withKey:key]; 294 | } 295 | } 296 | 297 | - (void)setResource:(id)resource withKey:(id )key 298 | { 299 | [[self keyValueData] setDataValue:resource withKey:key]; 300 | 301 | [self synchronize:YES]; 302 | } 303 | 304 | #pragma mark - 305 | - (id)valueWithKey:(id )key 306 | { 307 | return [[self keyValueData] valueWithKey:key]; 308 | } 309 | 310 | - (int)intWithKey:(id )key 311 | { 312 | NSNumber *value = [[self keyValueData] valueWithKey:key]; 313 | if ([value respondsToSelector:@selector(intValue)]) { 314 | return [value intValue]; 315 | } 316 | return 0; 317 | } 318 | 319 | - (NSInteger)integerWithKey:(id )key 320 | { 321 | NSNumber *value = [[self keyValueData] valueWithKey:key]; 322 | if ([value respondsToSelector:@selector(integerValue)]) { 323 | return [value integerValue]; 324 | } 325 | return 0; 326 | } 327 | 328 | - (float)floatWithKey:(id )key 329 | { 330 | NSNumber *value = [[self keyValueData] valueWithKey:key]; 331 | if ([value respondsToSelector:@selector(floatValue)]) { 332 | return [value floatValue]; 333 | } 334 | return 0; 335 | } 336 | 337 | - (double)doubleWithKey:(id )key 338 | { 339 | NSNumber *value = [[self keyValueData] valueWithKey:key]; 340 | if ([value respondsToSelector:@selector(doubleValue)]) { 341 | return [value doubleValue]; 342 | } 343 | return 0; 344 | } 345 | 346 | - (BOOL)boolWithKey:(id )key 347 | { 348 | NSNumber *value = [[self keyValueData] valueWithKey:key]; 349 | if ([value respondsToSelector:@selector(boolValue)]) { 350 | return [value boolValue]; 351 | } 352 | return 0; 353 | } 354 | 355 | - (id)decryptContentWithKey:(id )key 356 | { 357 | NSString *value = [[self keyValueData] valueWithKey:key]; 358 | return [AESCrypt decrypt:value password:AES_CRYPT_PASSWORD]; 359 | } 360 | 361 | - (id)containerWithKey:(id )key 362 | { 363 | id value = [[self keyValueData] valueWithKey:key]; 364 | if ([value isKindOfClass:[NSSet class]] || 365 | [value isKindOfClass:[NSArray class]] || 366 | [value isKindOfClass:[NSDictionary class]]) { 367 | 368 | return value; 369 | } 370 | return nil; 371 | } 372 | 373 | - (id)resourceWithKey:(id )key 374 | { 375 | return [[self keyValueData] dataValueWithKey:key]; 376 | } 377 | 378 | #pragma mark - 379 | - (NSArray *)allKeys 380 | { 381 | return [[self keyValueData] allKeys]; 382 | } 383 | 384 | - (NSArray *)allValues 385 | { 386 | return [[self keyValueData] allValues]; 387 | } 388 | 389 | - (void)removeValueWithKey:(id )key 390 | { 391 | [[self keyValueData] removeValueWithKey:key]; 392 | 393 | [self synchronize:YES]; 394 | } 395 | 396 | - (void)removeAllValues 397 | { 398 | [self clear]; 399 | } 400 | 401 | @end 402 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AutoCoding/AutoCoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // AutoCoding.h 3 | // 4 | // Version 2.2.1 5 | // 6 | // Created by Nick Lockwood on 19/11/2011. 7 | // Copyright (c) 2011 Charcoal Design 8 | // 9 | // Distributed under the permissive zlib License 10 | // Get the latest version from here: 11 | // 12 | // https://github.com/nicklockwood/AutoCoding 13 | // 14 | // This software is provided 'as-is', without any express or implied 15 | // warranty. In no event will the authors be held liable for any damages 16 | // arising from the use of this software. 17 | // 18 | // Permission is granted to anyone to use this software for any purpose, 19 | // including commercial applications, and to alter it and redistribute it 20 | // freely, subject to the following restrictions: 21 | // 22 | // 1. The origin of this software must not be misrepresented; you must not 23 | // claim that you wrote the original software. If you use this software 24 | // in a product, an acknowledgment in the product documentation would be 25 | // appreciated but is not required. 26 | // 27 | // 2. Altered source versions must be plainly marked as such, and must not be 28 | // misrepresented as being the original software. 29 | // 30 | // 3. This notice may not be removed or altered from any source distribution. 31 | // 32 | 33 | #import 34 | 35 | @interface NSObject (AutoCoding) 36 | 37 | //coding 38 | 39 | + (NSDictionary *)codableProperties; 40 | - (void)setWithCoder:(NSCoder *)aDecoder; 41 | 42 | //property access 43 | 44 | - (NSDictionary *)codableProperties; 45 | - (NSDictionary *)dictionaryRepresentation; 46 | 47 | //loading / saving 48 | 49 | + (instancetype)objectWithContentsOfFile:(NSString *)path; 50 | - (BOOL)writeToFile:(NSString *)filePath atomically:(BOOL)useAuxiliaryFile; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/AutoCoding/AutoCoding.m: -------------------------------------------------------------------------------- 1 | // 2 | // AutoCoding.m 3 | // 4 | // Version 2.2.1 5 | // 6 | // Created by Nick Lockwood on 19/11/2011. 7 | // Copyright (c) 2011 Charcoal Design 8 | // 9 | // Distributed under the permissive zlib License 10 | // Get the latest version from here: 11 | // 12 | // https://github.com/nicklockwood/AutoCoding 13 | // 14 | // This software is provided 'as-is', without any express or implied 15 | // warranty. In no event will the authors be held liable for any damages 16 | // arising from the use of this software. 17 | // 18 | // Permission is granted to anyone to use this software for any purpose, 19 | // including commercial applications, and to alter it and redistribute it 20 | // freely, following restrictions: 21 | // 22 | // 1. The origin of this software must not be misrepresented; you must not 23 | // claim that you wrote the original software. If you use this software 24 | // in a product, an acknowledgment in the product documentation would be 25 | // appreciated but is not required. 26 | // 27 | // 2. Altered source versions must be plainly marked as such, and must not be 28 | // misrepresented as being the original software. 29 | // 30 | // 3. This notice may not be removed or altered from any source distribution. 31 | // 32 | 33 | #import "AutoCoding.h" 34 | #import 35 | 36 | 37 | #pragma GCC diagnostic ignored "-Wgnu" 38 | 39 | 40 | static NSString *const AutocodingException = @"AutocodingException"; 41 | 42 | 43 | @implementation NSObject (AutoCoding) 44 | 45 | + (BOOL)supportsSecureCoding 46 | { 47 | return YES; 48 | } 49 | 50 | + (instancetype)objectWithContentsOfFile:(NSString *)filePath 51 | { 52 | //load the file 53 | NSData *data = [NSData dataWithContentsOfFile:filePath]; 54 | 55 | //attempt to deserialise data as a plist 56 | id object = nil; 57 | if (data) 58 | { 59 | NSPropertyListFormat format; 60 | object = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:NULL]; 61 | 62 | //success? 63 | if (object) 64 | { 65 | //check if object is an NSCoded unarchive 66 | if ([object respondsToSelector:@selector(objectForKey:)] && [(NSDictionary *)object objectForKey:@"$archiver"]) 67 | { 68 | object = [NSKeyedUnarchiver unarchiveObjectWithData:data]; 69 | } 70 | } 71 | else 72 | { 73 | //return raw data 74 | object = data; 75 | } 76 | } 77 | 78 | //return object 79 | return object; 80 | } 81 | 82 | - (BOOL)writeToFile:(NSString *)filePath atomically:(BOOL)useAuxiliaryFile 83 | { 84 | //note: NSData, NSDictionary and NSArray already implement this method 85 | //and do not save using NSCoding, however the objectWithContentsOfFile 86 | //method will correctly recover these objects anyway 87 | 88 | //archive object 89 | NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self]; 90 | return [data writeToFile:filePath atomically:useAuxiliaryFile]; 91 | } 92 | 93 | + (NSDictionary *)codableProperties 94 | { 95 | //deprecated 96 | SEL deprecatedSelector = NSSelectorFromString(@"codableKeys"); 97 | if ([self respondsToSelector:deprecatedSelector] || [self instancesRespondToSelector:deprecatedSelector]) 98 | { 99 | NSLog(@"AutoCoding Warning: codableKeys method is no longer supported. Use codableProperties instead."); 100 | } 101 | deprecatedSelector = NSSelectorFromString(@"uncodableKeys"); 102 | if ([self respondsToSelector:deprecatedSelector] || [self instancesRespondToSelector:deprecatedSelector]) 103 | { 104 | NSLog(@"AutoCoding Warning: uncodableKeys method is no longer supported. Use ivars, or synthesize your properties using non-KVC-compliant names to avoid coding them instead."); 105 | } 106 | deprecatedSelector = NSSelectorFromString(@"uncodableProperties"); 107 | NSArray *uncodableProperties = nil; 108 | if ([self respondsToSelector:deprecatedSelector] || [self instancesRespondToSelector:deprecatedSelector]) 109 | { 110 | uncodableProperties = [self valueForKey:@"uncodableProperties"]; 111 | NSLog(@"AutoCoding Warning: uncodableProperties method is no longer supported. Use ivars, or synthesize your properties using non-KVC-compliant names to avoid coding them instead."); 112 | } 113 | 114 | unsigned int propertyCount; 115 | __autoreleasing NSMutableDictionary *codableProperties = [NSMutableDictionary dictionary]; 116 | objc_property_t *properties = class_copyPropertyList(self, &propertyCount); 117 | for (unsigned int i = 0; i < propertyCount; i++) 118 | { 119 | //get property name 120 | objc_property_t property = properties[i]; 121 | const char *propertyName = property_getName(property); 122 | __autoreleasing NSString *key = @(propertyName); 123 | 124 | //check if codable 125 | if (![uncodableProperties containsObject:key]) 126 | { 127 | //get property type 128 | Class propertyClass = nil; 129 | char *typeEncoding = property_copyAttributeValue(property, "T"); 130 | switch (typeEncoding[0]) 131 | { 132 | case '@': 133 | { 134 | if (strlen(typeEncoding) >= 3) 135 | { 136 | char *className = strndup(typeEncoding + 2, strlen(typeEncoding) - 3); 137 | __autoreleasing NSString *name = @(className); 138 | NSRange range = [name rangeOfString:@"<"]; 139 | if (range.location != NSNotFound) 140 | { 141 | name = [name substringToIndex:range.location]; 142 | } 143 | propertyClass = NSClassFromString(name) ?: [NSObject class]; 144 | free(className); 145 | } 146 | break; 147 | } 148 | case 'c': 149 | case 'i': 150 | case 's': 151 | case 'l': 152 | case 'q': 153 | case 'C': 154 | case 'I': 155 | case 'S': 156 | case 'L': 157 | case 'Q': 158 | case 'f': 159 | case 'd': 160 | case 'B': 161 | { 162 | propertyClass = [NSNumber class]; 163 | break; 164 | } 165 | case '{': 166 | { 167 | propertyClass = [NSValue class]; 168 | break; 169 | } 170 | } 171 | free(typeEncoding); 172 | 173 | if (propertyClass) 174 | { 175 | //check if there is a backing ivar 176 | char *ivar = property_copyAttributeValue(property, "V"); 177 | if (ivar) 178 | { 179 | //check if ivar has KVC-compliant name 180 | __autoreleasing NSString *ivarName = @(ivar); 181 | if ([ivarName isEqualToString:key] || [ivarName isEqualToString:[@"_" stringByAppendingString:key]]) 182 | { 183 | //no setter, but setValue:forKey: will still work 184 | codableProperties[key] = propertyClass; 185 | } 186 | free(ivar); 187 | } 188 | else 189 | { 190 | //check if property is dynamic and readwrite 191 | char *dynamic = property_copyAttributeValue(property, "D"); 192 | char *readonly = property_copyAttributeValue(property, "R"); 193 | if (dynamic && !readonly) 194 | { 195 | //no ivar, but setValue:forKey: will still work 196 | codableProperties[key] = propertyClass; 197 | } 198 | free(dynamic); 199 | free(readonly); 200 | } 201 | } 202 | } 203 | } 204 | 205 | free(properties); 206 | return codableProperties; 207 | } 208 | 209 | - (NSDictionary *)codableProperties 210 | { 211 | __autoreleasing NSDictionary *codableProperties = objc_getAssociatedObject([self class], _cmd); 212 | if (!codableProperties) 213 | { 214 | codableProperties = [NSMutableDictionary dictionary]; 215 | Class subclass = [self class]; 216 | while (subclass != [NSObject class]) 217 | { 218 | [(NSMutableDictionary *)codableProperties addEntriesFromDictionary:[subclass codableProperties]]; 219 | subclass = [subclass superclass]; 220 | } 221 | codableProperties = [NSDictionary dictionaryWithDictionary:codableProperties]; 222 | 223 | //make the association atomically so that we don't need to bother with an @synchronize 224 | objc_setAssociatedObject([self class], _cmd, codableProperties, OBJC_ASSOCIATION_RETAIN); 225 | } 226 | return codableProperties; 227 | } 228 | 229 | - (NSDictionary *)dictionaryRepresentation 230 | { 231 | NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 232 | for (__unsafe_unretained NSString *key in [self codableProperties]) 233 | { 234 | id value = [self valueForKey:key]; 235 | if (value) dict[key] = value; 236 | } 237 | return dict; 238 | } 239 | 240 | - (void)setWithCoder:(NSCoder *)aDecoder 241 | { 242 | BOOL secureAvailable = [aDecoder respondsToSelector:@selector(decodeObjectOfClass:forKey:)]; 243 | BOOL secureSupported = [[self class] supportsSecureCoding]; 244 | NSDictionary *properties = [self codableProperties]; 245 | for (NSString *key in properties) 246 | { 247 | id object = nil; 248 | Class propertyClass = properties[key]; 249 | if (secureAvailable) 250 | { 251 | object = [aDecoder decodeObjectOfClass:propertyClass forKey:key]; 252 | } 253 | else 254 | { 255 | object = [aDecoder decodeObjectForKey:key]; 256 | } 257 | if (object) 258 | { 259 | if (secureSupported && ![object isKindOfClass:propertyClass]) 260 | { 261 | [NSException raise:AutocodingException format:@"Expected '%@' to be a %@, but was actually a %@", key, propertyClass, [object class]]; 262 | } 263 | [self setValue:object forKey:key]; 264 | } 265 | } 266 | } 267 | 268 | - (instancetype)initWithCoder:(NSCoder *)aDecoder 269 | { 270 | [self setWithCoder:aDecoder]; 271 | return self; 272 | } 273 | 274 | - (void)encodeWithCoder:(NSCoder *)aCoder 275 | { 276 | for (NSString *key in [self codableProperties]) 277 | { 278 | id object = [self valueForKey:key]; 279 | if (object) [aCoder encodeObject:object forKey:key]; 280 | } 281 | } 282 | 283 | @end 284 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Memory/ANMemoryPage.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANMemoryPage.h 3 | // QLBaseCore 4 | // 5 | // Created by jiachunke on 20/02/2017. 6 | // Copyright © 2017 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ANMemoryPage : NSCache 12 | 13 | - (id)object:(NSString *)name version:(NSString *)version; 14 | 15 | - (void)setObject:(id)obj name:(NSString *)name version:(NSString *)version; 16 | 17 | - (NSString *)generateKey:(NSString *)name version:(NSString *)version; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Memory/ANMemoryPage.m: -------------------------------------------------------------------------------- 1 | // 2 | // ANMemoryPage.m 3 | // QLBaseCore 4 | // 5 | // Created by jiachunke on 20/02/2017. 6 | // Copyright © 2017 Tencent. All rights reserved. 7 | // 8 | 9 | #import "ANMemoryPage.h" 10 | #import 11 | #import 12 | #import "ANPersistentData.h" 13 | 14 | @interface ANMemoryPage() 15 | { 16 | //增加永久性内存cache的结构,用于支持一些有必要永久cache的情况 17 | NSMutableDictionary *_permanentCache; 18 | pthread_mutex_t _mutex; 19 | NSHashTable *_activeDataList; 20 | } 21 | 22 | @end 23 | 24 | @implementation ANMemoryPage 25 | 26 | - (instancetype)init 27 | { 28 | self = [super init]; 29 | if (self) { 30 | NSString *version = [UIDevice currentDevice].systemVersion; 31 | if (version.doubleValue < 9.0) { 32 | //由于iOS7和iOS8均发现有NSCache导致的crash,出于规避的目的,在iOS7和iOS8上面启动备用cache结构 33 | _permanentCache = [NSMutableDictionary dictionary]; 34 | 35 | pthread_mutexattr_t attr; 36 | pthread_mutexattr_init(&attr); 37 | //设置锁的属性为可递归 38 | //pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); 39 | pthread_mutex_init(&_mutex, &attr); 40 | pthread_mutexattr_destroy(&attr); 41 | } 42 | 43 | _activeDataList = [NSHashTable weakObjectsHashTable]; 44 | 45 | [[NSNotificationCenter defaultCenter] addObserver:self 46 | selector:@selector(applicationWillTerminate:) 47 | name:UIApplicationWillTerminateNotification 48 | object:nil]; 49 | [[NSNotificationCenter defaultCenter] addObserver:self 50 | selector:@selector(applicationDidEnterBackground:) 51 | name:UIApplicationDidEnterBackgroundNotification 52 | object:nil]; 53 | } 54 | return self; 55 | } 56 | 57 | - (id)object:(NSString *)name version:(NSString *)version 58 | { 59 | if (![name isKindOfClass:[NSString class]] || 0 == [name length]) { 60 | return nil; 61 | } 62 | 63 | NSString *key = [self generateKey:name version:version]; 64 | if (nil != key) { 65 | if (_permanentCache) { 66 | pthread_mutex_lock(&_mutex); 67 | id object = [_permanentCache objectForKey:key]; 68 | pthread_mutex_unlock(&_mutex); 69 | return object; 70 | } else { 71 | return [self objectForKey:key]; 72 | } 73 | } 74 | return nil; 75 | } 76 | 77 | - (void)setObject:(id)obj name:(NSString *)name version:(NSString *)version 78 | { 79 | if (![name isKindOfClass:[NSString class]] || 0 == [name length]) { 80 | return; 81 | } 82 | 83 | NSString *key = [self generateKey:name version:version]; 84 | if (nil != obj && nil != key) { 85 | if (_permanentCache) { 86 | pthread_mutex_lock(&_mutex); 87 | [_permanentCache setObject:obj forKey:key]; 88 | pthread_mutex_unlock(&_mutex); 89 | } else { 90 | [self setObject:obj forKey:key]; 91 | } 92 | [_activeDataList addObject:obj]; 93 | } 94 | } 95 | 96 | - (NSString *)generateKey:(NSString *)name version:(NSString *)version 97 | { 98 | if (![name isKindOfClass:[NSString class]] || 0 == [name length]) { 99 | return nil; 100 | } 101 | 102 | if (![version isKindOfClass:[NSString class]] || 0 == [version length]) { 103 | return [NSString stringWithFormat:@"%@", name]; 104 | } 105 | return [NSString stringWithFormat:@"%@-%@", name, version]; 106 | } 107 | 108 | - (void)dataArchiveNow 109 | { 110 | NSArray *dataObjects = [_activeDataList allObjects]; 111 | for (ANPersistentData *pData in dataObjects) { 112 | [pData archiveNow]; 113 | } 114 | } 115 | 116 | - (void)applicationWillTerminate:(NSNotification *)not 117 | { 118 | [self dataArchiveNow]; 119 | } 120 | 121 | - (void)applicationDidEnterBackground:(NSNotification *)not 122 | { 123 | [self dataArchiveNow]; 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Persistent/ANPersistentData.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANPersistentData.h 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/12. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "AutoCoding.h" 12 | #import "ANPersistentStrategy.h" 13 | 14 | @interface ANPersistentData : NSObject 15 | { 16 | @protected 17 | __strong NSRecursiveLock *_dataLock; 18 | } 19 | 20 | @property (nonatomic, strong) NSString *domain; 21 | 22 | @property (nonatomic, strong) NSString *version; 23 | 24 | @property (nonatomic, strong) NSString *name; 25 | 26 | @property (nonatomic, strong) NSDate *createdTime; 27 | 28 | @property (nonatomic, strong) NSDate *modifiedTime; 29 | 30 | @property (nonatomic, strong) ANPersistentStrategy *strategy; 31 | 32 | // 加强内部对sender(调用者)的内存管理,避免sender被提前释放导致的各种稳定性问题, 33 | // 包括sender在dealloc调用强制归档(archiveNow)也是不合适的,springox(20151004) 34 | @property (nonatomic, strong) NSMutableArray *observers; 35 | 36 | + (id)data:(NSString *)name version:(NSString *)version domain:(NSString *)domain level:(ANPersistentLevel)level; 37 | 38 | + (void)clearCache:(NSString *)domain level:(ANPersistentLevel)level; 39 | 40 | + (id)strategy:(ANPersistentLevel)level; 41 | 42 | - (void)setNeedToArchive:(id)observer; 43 | 44 | - (void)archiveNow; 45 | 46 | - (void)fireArchive; 47 | 48 | - (BOOL)isWillArchive; 49 | 50 | - (BOOL)isArchiving; 51 | 52 | - (void)clearData; 53 | 54 | - (void)archiveWillStart; 55 | 56 | - (void)archiveDidFinish; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Persistent/ANPersistentData.m: -------------------------------------------------------------------------------- 1 | // 2 | // ANPersistentData.m 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/12. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ANPersistentData.h" 10 | 11 | #define ArchiveTimerTimeIntervalDefault 5.f 12 | 13 | void *const GlobalArchiveQueueIdentityKey = (void *)&GlobalArchiveQueueIdentityKey; 14 | 15 | @interface ANPersistentData() 16 | { 17 | @private 18 | BOOL _isArchiving; 19 | __strong NSTimer *_archiveTimer; 20 | } 21 | 22 | @end 23 | 24 | @implementation ANPersistentData 25 | 26 | + (id)data:(NSString *)name version:(NSString *)version domain:(NSString *)domain level:(ANPersistentLevel)level 27 | { 28 | ANPersistentStrategy *strategy = [self strategy:level]; 29 | 30 | NSString *path = [strategy localPath:name version:version domain:domain]; 31 | 32 | ANPersistentData *data = nil; 33 | @try { 34 | data = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; 35 | } 36 | @catch (NSException *exception) { 37 | 38 | } 39 | //end modify 40 | 41 | if (nil == data || ![data respondsToSelector:@selector(strategy)]) { 42 | data = [[[self class] alloc] init]; 43 | data.createdTime = [NSDate date]; 44 | } 45 | data.domain = domain; 46 | data.version = version; 47 | data.name = name; 48 | data.modifiedTime = [NSDate date]; 49 | data.strategy = strategy; 50 | 51 | return data; 52 | } 53 | 54 | + (void)clearCache:(NSString *)domain level:(ANPersistentLevel)level 55 | { 56 | ANPersistentStrategy *strategy = [self strategy:level]; 57 | if (0 < [strategy.rootDirectory length]) { 58 | NSString *dirPath = [strategy localDirectoryWithRelativePath:domain]; 59 | [[NSFileManager defaultManager] removeItemAtPath:dirPath error:NULL]; 60 | } 61 | } 62 | 63 | + (id)strategy:(ANPersistentLevel)level 64 | { 65 | return [[ANPersistentStrategy alloc] initWithLevel:level]; 66 | } 67 | 68 | - (void)dealloc 69 | { 70 | // do nothing 71 | } 72 | 73 | - (id)init 74 | { 75 | self = [super init]; 76 | if (self) { 77 | 78 | _dataLock = [[NSRecursiveLock alloc] init]; 79 | _observers = [NSMutableArray array]; 80 | } 81 | return self; 82 | } 83 | 84 | - (id)initWithCoder:(NSCoder *)aDecoder 85 | { 86 | self = [super initWithCoder:aDecoder]; 87 | if (self) { 88 | 89 | _dataLock = [[NSRecursiveLock alloc] init]; 90 | _observers = [NSMutableArray array]; 91 | } 92 | return self; 93 | } 94 | 95 | - (void)encodeWithCoder:(NSCoder *)aCoder 96 | { 97 | [super encodeWithCoder:aCoder]; 98 | } 99 | 100 | - (id)copyWithZone:(NSZone *)zone 101 | { 102 | return self; 103 | } 104 | 105 | - (void)setNeedToArchive:(id)observer 106 | { 107 | [_dataLock lock]; 108 | if ([self.strategy shouldArchive:self name:self.name]) { 109 | if (nil == _archiveTimer) { 110 | NSTimeInterval timeInterval = [self.strategy timeIntervalOfArchiveTimer]; 111 | _archiveTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(archiveTimerOperation) userInfo:nil repeats:NO]; 112 | 113 | } 114 | // support strong observer(just like network connection delegate), added by springox(20151004) 115 | if (![_observers containsObject:observer]) { 116 | [_observers addObject:observer]; 117 | } 118 | } 119 | [_dataLock unlock]; 120 | } 121 | 122 | - (void)archiveNow 123 | { 124 | // _archiveTimer会影响self的计数,因此先自己做好保护,springox(20150318) 125 | __strong ANPersistentData *strongSelf = self; 126 | 127 | [_dataLock lock]; 128 | if (nil != _archiveTimer) { 129 | [self fireArchive]; 130 | } 131 | [_dataLock unlock]; 132 | 133 | strongSelf = nil; 134 | } 135 | 136 | // 为了提升性能,将所有序列化操作均异步线程执行,- (void)syncArchive命名不再适合,更换下方法命名 137 | - (void)fireArchive 138 | { 139 | // _archiveTimer会影响self的计数,因此先自己做好保护,springox(20150318) 140 | __strong ANPersistentData *strongSelf = self; 141 | 142 | [_dataLock lock]; 143 | [_archiveTimer invalidate]; 144 | @autoreleasepool { 145 | [self archiveOperation:self]; 146 | } 147 | _archiveTimer = nil; 148 | // support strong observer(just like network connection delegate), added by springox(20151004) 149 | [_observers removeAllObjects]; 150 | [_dataLock unlock]; 151 | 152 | strongSelf = nil; 153 | } 154 | 155 | - (BOOL)isWillArchive 156 | { 157 | [_dataLock lock]; 158 | BOOL flag = (nil != _archiveTimer); 159 | [_dataLock unlock]; 160 | return flag; 161 | } 162 | 163 | - (BOOL)isArchiving 164 | { 165 | [_dataLock lock]; 166 | BOOL flag = (_isArchiving || (nil != _archiveTimer)); 167 | [_dataLock unlock]; 168 | return flag; 169 | } 170 | 171 | - (void)clearData 172 | { 173 | // _archiveTimer会影响self的计数,因此先自己做好保护,springox(20150318) 174 | __strong ANPersistentData *strongSelf = self; 175 | 176 | [_dataLock lock]; 177 | NSString *path = [self.strategy localDirectory:self.name domain:self.domain]; 178 | NSFileManager *fm = [NSFileManager defaultManager]; 179 | NSError *error = nil; 180 | [fm removeItemAtPath:path error:&error]; 181 | if (nil != error) { 182 | NSLog(@"Persistent Data remove local directory %@ fail:%@\n", path, error); 183 | } else { 184 | NSLog(@"Persistent Data remove local directory %@ success\n", path); 185 | } 186 | 187 | [self fireArchive]; 188 | [_dataLock unlock]; 189 | 190 | strongSelf = nil; 191 | } 192 | 193 | - (void)archiveWillStart 194 | { 195 | // do nothing 196 | } 197 | 198 | - (void)archiveDidFinish 199 | { 200 | // do nothing 201 | } 202 | 203 | #pragma mark - Private Method 204 | 205 | - (void)archiveTimerOperation 206 | { 207 | // _archiveTimer会影响self的计数,因此先自己做好保护,springox(20150318) 208 | __strong ANPersistentData *strongSelf = self; 209 | 210 | [_dataLock lock]; 211 | [_archiveTimer invalidate]; 212 | [self archiveOperation:self]; 213 | _archiveTimer = nil; 214 | // support strong observer(just like network connection delegate), added by springox(20151004) 215 | [_observers removeAllObjects]; 216 | [_dataLock unlock]; 217 | 218 | strongSelf = nil; 219 | } 220 | 221 | - (void)archiveOperation:(id)rootObject 222 | { 223 | [_dataLock lock]; 224 | id obj = [rootObject copy]; 225 | dispatch_block_t archiveBlock = ^{ 226 | @autoreleasepool { 227 | [self archive:obj]; 228 | } 229 | }; 230 | dispatch_async([self archiveQueue], archiveBlock); 231 | [_dataLock unlock]; 232 | } 233 | 234 | - (dispatch_queue_t)archiveQueue 235 | { 236 | // added by springox(20150105) 237 | static dispatch_queue_t archiveQueue; 238 | if (NULL == archiveQueue) { 239 | static dispatch_once_t onceToken; 240 | dispatch_once(&onceToken, ^{ 241 | const char *archiveQueueName = NULL; 242 | archiveQueueName = [@"GlobalArchiveQueueName" UTF8String]; 243 | // 遇到一些系统内的内存管理crash(objc_retain + 16),简化这里的并发特性,改为串行队列 244 | // 这里需要特别说明虽然全局使用一个并行的任务队列,同时也认为有频控的持久化实现对于并发任务的要求并不高, 245 | // 即使存在多个持久化目标,单个子线程串行执行也能满足需要,springox(20150105) 246 | archiveQueue = dispatch_queue_create(archiveQueueName, NULL); 247 | //archiveQueue = dispatch_queue_create(archiveQueueName, DISPATCH_QUEUE_CONCURRENT); 248 | 249 | void *key = GlobalArchiveQueueIdentityKey; 250 | void *nonNullValue = GlobalArchiveQueueIdentityKey; 251 | dispatch_queue_set_specific(archiveQueue, key, nonNullValue, NULL); 252 | }); 253 | } 254 | return archiveQueue; 255 | } 256 | 257 | - (void)archive:(id)rootObject 258 | { 259 | NSString *dataPath = [self.strategy localPath:_name version:_version domain:_domain]; 260 | if (nil == dataPath) { 261 | return; 262 | } 263 | 264 | [self archiveWillStart]; 265 | 266 | [_dataLock lock]; 267 | 268 | _isArchiving = YES; 269 | 270 | NSLog(@"Persistent Data archive %@\n", dataPath); 271 | [NSKeyedArchiver archiveRootObject:rootObject toFile:dataPath]; 272 | self.modifiedTime = [NSDate date]; 273 | 274 | _isArchiving = NO; 275 | 276 | [_dataLock unlock]; 277 | 278 | [self archiveDidFinish]; 279 | } 280 | 281 | @end 282 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Persistent/ANPersistentStrategy.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANPersistentStrategy.h 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/12. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_OPTIONS(unsigned, ANPersistentLevel) { 12 | ANPersistentLevelResumableCaches = 0, // 当系统回收存储空间时,数据能够自动完整的恢复 13 | ANPersistentLevelApplicationSupport = 1, // App运行时依赖的资源,同时不能够自动完整的恢复 14 | ANPersistentLevelUserDocument = 2, // 记录用户特定行为和隐私信息,同时不能够自动完整的恢复 15 | }; 16 | 17 | @interface NSString (MD5String) 18 | 19 | - (NSString *)MD5String; 20 | 21 | @end 22 | 23 | @class ANPersistentData; 24 | 25 | @interface ANPersistentStrategy : NSObject 26 | 27 | @property (nonatomic, strong) NSString *rootDirectory; 28 | 29 | - (id)initWithLevel:(ANPersistentLevel)level; 30 | 31 | - (BOOL)shouldArchive:(ANPersistentData *)data name:(NSString *)name; 32 | 33 | - (NSTimeInterval)timeIntervalOfArchiveTimer; 34 | 35 | - (NSString *)localDirectory:(NSString *)rootDir relativePath:(NSString *)relPath; 36 | 37 | - (NSString *)localDirectoryWithRelativePath:(NSString *)relPath; 38 | 39 | - (NSString *)localDirectory:(NSString *)name domain:(NSString *)domain; 40 | 41 | - (NSString *)localPath:(NSString *)name version:(NSString *)version domain:(NSString *)domain; 42 | 43 | - (NSArray *)localPathArrayWithDomain:(NSString *)domain; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Persistent/ANPersistentStrategy.m: -------------------------------------------------------------------------------- 1 | // 2 | // ANPersistentStrategy.m 3 | // Araneo 4 | // 5 | // Created by SpringOx on 14/12/12. 6 | // Copyright (c) 2014年 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ANPersistentStrategy.h" 10 | #import 11 | 12 | #define ARCHIVE_TIME_INTERVAL_DEFAULT 5.f 13 | #define DOMAIN_STRING_DEFAULT @"PersistentData" 14 | #define VERSION_DEFAULT @"1.0.0" 15 | 16 | @implementation NSString (MD5String) 17 | 18 | - (NSString *)MD5String 19 | { 20 | if(self == nil || [self length] == 0) 21 | return nil; 22 | 23 | const char *value = [self UTF8String]; 24 | 25 | unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH]; 26 | CC_MD5(value, (unsigned int)strlen(value), outputBuffer); 27 | 28 | NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; 29 | for(NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++){ 30 | [outputString appendFormat:@"%02X",outputBuffer[count]]; 31 | } 32 | return outputString; 33 | } 34 | 35 | @end 36 | 37 | @implementation ANPersistentStrategy 38 | 39 | - (id)init 40 | { 41 | self = [super init]; 42 | if (self) { 43 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 44 | self.rootDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 45 | 46 | } 47 | return self; 48 | } 49 | 50 | - (id)initWithLevel:(ANPersistentLevel)level 51 | { 52 | self = [super init]; 53 | if (self) { 54 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 55 | if (ANPersistentLevelApplicationSupport == level) { 56 | paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); 57 | } else if (ANPersistentLevelUserDocument == level) { 58 | paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 59 | } 60 | self.rootDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 61 | 62 | } 63 | return self; 64 | } 65 | 66 | - (BOOL)shouldArchive:(ANPersistentData *)data name:(NSString *)name 67 | { 68 | return YES; 69 | } 70 | 71 | - (NSTimeInterval)timeIntervalOfArchiveTimer 72 | { 73 | return ARCHIVE_TIME_INTERVAL_DEFAULT; 74 | } 75 | 76 | - (NSString *)localDirectory:(NSString *)rootDir relativePath:(NSString *)relPath 77 | { 78 | if (![rootDir isKindOfClass:[NSString class]] || 0 == [rootDir length]) { 79 | return nil; 80 | } 81 | 82 | NSString *dirPath = [rootDir stringByAppendingPathComponent:relPath]; 83 | NSFileManager *fm = [NSFileManager defaultManager]; 84 | if(![fm fileExistsAtPath:dirPath]){ 85 | NSError *error; 86 | [fm createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:&error]; 87 | if (nil != error) { 88 | NSLog(@"create directory error : %@ %@", dirPath, error); 89 | } else { 90 | return dirPath; 91 | } 92 | } 93 | return dirPath; 94 | } 95 | 96 | - (NSString *)localDirectoryWithRelativePath:(NSString *)relPath 97 | { 98 | return [self localDirectory:self.rootDirectory relativePath:relPath]; 99 | } 100 | 101 | - (NSString *)localDirectory:(NSString *)name domain:(NSString *)domain 102 | { 103 | NSString *relPath = [NSString stringWithFormat:@"%@/%@", domain, [name MD5String]]; 104 | return [self localDirectoryWithRelativePath:relPath]; 105 | } 106 | 107 | - (NSString *)localPath:(NSString *)name version:(NSString *)version domain:(NSString *)domain 108 | { 109 | if (nil == self.rootDirectory) { 110 | return nil; 111 | } 112 | 113 | if ([name isKindOfClass:[NSString class]] && 0 < [name length]) { 114 | if (![version isKindOfClass:[NSString class]] || 0 == [version length]) { 115 | version = VERSION_DEFAULT; 116 | } 117 | if (![domain isKindOfClass:[NSString class]] || 0 == [domain length]) { 118 | domain = DOMAIN_STRING_DEFAULT; 119 | } 120 | 121 | NSString *dirPath = [self localDirectory:name domain:domain]; 122 | if (nil != dirPath) { 123 | NSString *fileName = [NSString stringWithFormat:@"%@-%@", [name MD5String], version]; 124 | return [dirPath stringByAppendingPathComponent:fileName]; 125 | } 126 | } 127 | return nil; 128 | } 129 | 130 | - (NSArray *)localPathArrayWithDomain:(NSString *)domain 131 | { 132 | if (nil == self.rootDirectory) { 133 | return nil; 134 | } 135 | 136 | if (![domain isKindOfClass:[NSString class]] || 0 == [domain length]) { 137 | return [NSArray array]; 138 | } 139 | 140 | NSString *relPath = domain; 141 | NSString *dirPath = [self localDirectoryWithRelativePath:relPath]; 142 | NSFileManager *fm = [NSFileManager defaultManager]; 143 | if (![fm fileExistsAtPath:dirPath]) { 144 | return [NSArray array]; 145 | } 146 | 147 | NSError *error = nil; 148 | NSArray *contents = [fm contentsOfDirectoryAtPath:dirPath error:&error]; 149 | if (nil != error) { 150 | return [NSArray array]; 151 | } 152 | 153 | NSMutableArray *tempArr = [NSMutableArray arrayWithCapacity:[contents count]]; 154 | for (NSString *content in contents) { 155 | NSString *path = [dirPath stringByAppendingPathComponent:content]; 156 | [tempArr addObject:path]; 157 | } 158 | return [NSArray arrayWithArray:tempArr]; 159 | } 160 | 161 | @end 162 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Protocol/ANKeyValueProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueProtocol.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/3/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #ifndef ANKeyValue_ANKeyValueProtocol_h 10 | #define ANKeyValue_ANKeyValueProtocol_h 11 | 12 | @protocol ANKeyValue 13 | 14 | - (BOOL)shouldEncodeWithDataBlock; 15 | 16 | @end 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Protocol/NSData+ANKeyValue.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+ANKeyValue.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/3/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ANKeyValueProtocol.h" 11 | 12 | @interface NSData (ANKeyValue) 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Protocol/NSData+ANKeyValue.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+ANKeyValue.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/3/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "NSData+ANKeyValue.h" 10 | 11 | #define DATA_ENCODE_WITHOUT_DATA_BLOCK 1024 12 | 13 | @implementation NSData (ANKeyValue) 14 | 15 | - (BOOL)shouldEncodeWithDataBlock 16 | { 17 | if (DATA_ENCODE_WITHOUT_DATA_BLOCK < [self length]) { 18 | return YES; 19 | } 20 | return NO; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Protocol/NSString+ANKeyValue.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+ANKeyValue.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/3/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ANKeyValueProtocol.h" 11 | 12 | @interface NSString (ANKeyValue) 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Protocol/NSString+ANKeyValue.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+ANKeyValue.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/3/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "NSString+ANKeyValue.h" 10 | 11 | #define STRING_ENCODE_WITHOUT_DATA_BLOCK 1024 12 | 13 | @implementation NSString (ANKeyValue) 14 | 15 | - (BOOL)shouldEncodeWithDataBlock 16 | { 17 | if (STRING_ENCODE_WITHOUT_DATA_BLOCK < [self length]) { 18 | return YES; 19 | } 20 | return NO; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Protocol/UIImage+ANKeyValue.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+ANKeyValue.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/6/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ANKeyValueProtocol.h" 11 | 12 | @interface UIImage (ANKeyValue) 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ANKeyValue/ANKeyValue/Protocol/UIImage+ANKeyValue.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+ANKeyValue.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/6/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "UIImage+ANKeyValue.h" 10 | 11 | @implementation UIImage (ANKeyValue) 12 | 13 | - (BOOL)shouldEncodeWithDataBlock 14 | { 15 | return YES; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /ANKeyValue/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 12/24/14. 6 | // Copyright (c) 2014 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /ANKeyValue/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 12/24/14. 6 | // Copyright (c) 2014 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /ANKeyValue/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ANKeyValue/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /ANKeyValue/ConcurrentViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ConcurrentViewController.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 3/24/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ConcurrentViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *thread1Label; 14 | @property (weak, nonatomic) IBOutlet UILabel *thread2Label; 15 | @property (weak, nonatomic) IBOutlet UILabel *thread3Label; 16 | @property (weak, nonatomic) IBOutlet UIButton *startButton; 17 | 18 | - (IBAction)didPressStartButtonAction:(id)sender; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ANKeyValue/ConcurrentViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ConcurrentViewController.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 3/24/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ConcurrentViewController.h" 10 | #import "ANKeyValueTable.h" 11 | 12 | @interface ConcurrentViewController () 13 | { 14 | __strong NSMutableDictionary *_tableDict; 15 | } 16 | 17 | @end 18 | 19 | @implementation ConcurrentViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | // Do any additional setup after loading the view from its nib. 24 | 25 | _tableDict = [NSMutableDictionary dictionary]; 26 | 27 | _thread1Label.text = @"Thread 1"; 28 | _thread2Label.text = @"Thread 2"; 29 | _thread3Label.text = @"Thread 3"; 30 | } 31 | 32 | - (void)didReceiveMemoryWarning { 33 | [super didReceiveMemoryWarning]; 34 | // Dispose of any resources that can be recreated. 35 | } 36 | 37 | /* 38 | #pragma mark - Navigation 39 | 40 | // In a storyboard-based application, you will often want to do a little preparation before navigation 41 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 42 | // Get the new view controller using [segue destinationViewController]. 43 | // Pass the selected object to the new view controller. 44 | } 45 | */ 46 | 47 | - (IBAction)didPressStartButtonAction:(id)sender { 48 | [NSThread detachNewThreadSelector:@selector(subThreadSelector1:) 49 | toTarget:self 50 | withObject:nil]; 51 | 52 | [NSThread detachNewThreadSelector:@selector(subThreadSelector2:) 53 | toTarget:self 54 | withObject:nil]; 55 | 56 | [NSThread detachNewThreadSelector:@selector(subThreadSelector3:) 57 | toTarget:self 58 | withObject:nil]; 59 | } 60 | 61 | - (void)subThreadSelector1:(id)object 62 | { 63 | [self executeSetOperation:0]; 64 | } 65 | 66 | - (void)subThreadSelector2:(id)object 67 | { 68 | [self executeSetOperation:1]; 69 | } 70 | 71 | - (void)subThreadSelector3:(id)object 72 | { 73 | [self executeGetOperation]; 74 | } 75 | 76 | - (void)executeSetOperation:(int)type 77 | { 78 | @autoreleasepool { 79 | NSMutableArray *tableArr = [NSMutableArray array]; 80 | int num = 0; 81 | do { 82 | 83 | NSString *key = [NSString stringWithFormat:@"SetOperation-%d", num]; 84 | ANKeyValueTable *table = [_tableDict objectForKey:key]; 85 | if (nil == table) { 86 | table = [ANKeyValueTable tableWithName:key version:@"0.0.9" resumable:NO]; 87 | [_tableDict setObject:table forKey:key]; 88 | } 89 | [tableArr addObject:table]; 90 | 91 | } while (10 > ++num); 92 | 93 | NSInteger total = 10000; 94 | NSInteger count = total; 95 | while (count) { 96 | 97 | for (ANKeyValueTable *t in tableArr) { 98 | //int randNum = arc4random(); 99 | int randNum = (int)count; 100 | NSString *key = [NSString stringWithFormat:@"Key-%d", randNum]; 101 | 102 | if (0 == type) { 103 | 104 | [t setInt:randNum withKey:key]; 105 | 106 | dispatch_async(dispatch_get_main_queue(), ^{ 107 | if (1 == randNum) { 108 | _thread1Label.text = [NSString stringWithFormat:@"Thread 1 Completed"]; 109 | } else { 110 | _thread1Label.text = [NSString stringWithFormat:@"Thread 1 %d", randNum]; 111 | } 112 | }); 113 | } else { 114 | 115 | [t setValue:@"ABCDEFGHIJKLMNOPQRSTVUWXYZ" withKey:key]; 116 | 117 | dispatch_async(dispatch_get_main_queue(), ^{ 118 | if (1 == randNum) { 119 | _thread2Label.text = [NSString stringWithFormat:@"Thread 2 Completed"]; 120 | } else { 121 | _thread2Label.text = [NSString stringWithFormat:@"Thread 2 %d", randNum]; 122 | } 123 | }); 124 | } 125 | } 126 | 127 | count--; 128 | } 129 | } 130 | } 131 | 132 | - (void)executeGetOperation 133 | { 134 | @autoreleasepool { 135 | 136 | NSMutableArray *tableArr = [NSMutableArray array]; 137 | int num = 0; 138 | do { 139 | 140 | NSString *key = [NSString stringWithFormat:@"SetOperation-%d", num]; 141 | ANKeyValueTable *table = [_tableDict objectForKey:key]; 142 | if (nil == table) { 143 | table = [ANKeyValueTable tableWithName:key version:@"0.0.9" resumable:NO]; 144 | [_tableDict setObject:table forKey:key]; 145 | } 146 | [tableArr addObject:table]; 147 | 148 | } while (10 > ++num); 149 | 150 | NSInteger total = 10000; 151 | NSInteger count = total; 152 | while (count) { 153 | 154 | for (ANKeyValueTable *t in tableArr) { 155 | //int randNum = arc4random(); 156 | int randNum = (int)count; 157 | NSString *key = [NSString stringWithFormat:@"Key-%d", randNum]; 158 | NSString *value = [t valueWithKey:key]; 159 | if (nil != value) { 160 | 161 | dispatch_async(dispatch_get_main_queue(), ^{ 162 | if (1 == randNum) { 163 | _thread3Label.text = [NSString stringWithFormat:@"Thread 3 Completed"]; 164 | } else { 165 | _thread3Label.text = [NSString stringWithFormat:@"Thread 3 %d", randNum]; 166 | } 167 | }); 168 | } 169 | } 170 | 171 | count--; 172 | } 173 | } 174 | } 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /ANKeyValue/ConcurrentViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 35 | 44 | 53 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /ANKeyValue/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /ANKeyValue/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ANKeyValue/PerformanceViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // PerformanceViewController.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/24/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface PerformanceViewController : UIViewController 12 | 13 | - (IBAction)didPressSetNumOperationButtonAction:(id)sender; 14 | 15 | - (IBAction)didPressSetStrOperationButtonAction:(id)sender; 16 | 17 | - (IBAction)didPressGetOperationButtonAction:(id)sender; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /ANKeyValue/PerformanceViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // PerformanceViewController.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/24/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "PerformanceViewController.h" 10 | #import "ANKeyValueTable.h" 11 | #import 12 | 13 | CGFloat BNRTimeBlock (void (^block)(void)) { 14 | mach_timebase_info_data_t info; 15 | if (mach_timebase_info(&info) != KERN_SUCCESS) return -1.0; 16 | 17 | uint64_t start = mach_absolute_time (); 18 | block (); 19 | uint64_t end = mach_absolute_time (); 20 | uint64_t elapsed = end - start; 21 | 22 | uint64_t nanos = elapsed * info.numer / info.denom; 23 | return (CGFloat)nanos / NSEC_PER_SEC; 24 | } 25 | 26 | @interface PerformanceViewController () 27 | { 28 | __strong NSMutableDictionary *_tableDict; 29 | } 30 | 31 | @end 32 | 33 | @implementation PerformanceViewController 34 | 35 | - (void)viewDidLoad { 36 | [super viewDidLoad]; 37 | // Do any additional setup after loading the view from its nib. 38 | 39 | _tableDict = [NSMutableDictionary dictionary]; 40 | } 41 | 42 | - (void)didReceiveMemoryWarning { 43 | [super didReceiveMemoryWarning]; 44 | // Dispose of any resources that can be recreated. 45 | } 46 | 47 | /* 48 | #pragma mark - Navigation 49 | 50 | // In a storyboard-based application, you will often want to do a little preparation before navigation 51 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 52 | // Get the new view controller using [segue destinationViewController]. 53 | // Pass the selected object to the new view controller. 54 | } 55 | */ 56 | 57 | - (IBAction)didPressSetNumOperationButtonAction:(id)sender { 58 | 59 | int num = 0; 60 | do { 61 | 62 | NSString *key = [NSString stringWithFormat:@"SetOperation-%d", num]; 63 | ANKeyValueTable *table = [_tableDict objectForKey:key]; 64 | if (nil == table) { 65 | table = [ANKeyValueTable tableWithName:key version:@"0.0.9" resumable:YES]; 66 | [_tableDict setObject:table forKey:key]; 67 | } 68 | [table clear]; 69 | 70 | } while (10 > ++num); 71 | 72 | CGFloat timeInterval1 = BNRTimeBlock(^{ 73 | [self executeSetOperation:0]; 74 | }); 75 | CGFloat timeInterval2 = BNRTimeBlock(^{ 76 | [self executeSetOperation:0]; 77 | }); 78 | CGFloat timeInterval3 = BNRTimeBlock(^{ 79 | [self executeSetOperation:0]; 80 | }); 81 | 82 | NSString *messsage = [NSString stringWithFormat:@"Calculate:10000 * 10 table\nConsuming:%fs\n(Average of 3 times)", 83 | (timeInterval1+timeInterval2+timeInterval3)/3]; 84 | NSLog(@"Set Num Operation: %@", messsage); 85 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Set Num Operation" 86 | message:messsage 87 | delegate:nil 88 | cancelButtonTitle:@"YES" 89 | otherButtonTitles:nil]; 90 | [alert show]; 91 | } 92 | 93 | - (IBAction)didPressSetStrOperationButtonAction:(id)sender { 94 | 95 | // 使用clearResumableTable方式清空数据,springox(20151130) 96 | /* 97 | int num = 0; 98 | do { 99 | 100 | NSString *key = [NSString stringWithFormat:@"SetOperation-%d", num]; 101 | ANKeyValueTable *table = [_tableDict objectForKey:key]; 102 | if (nil == table) { 103 | table = [ANKeyValueTable tableWithName:key version:@"0.0.9" resumable:YES]; 104 | [_tableDict setObject:table forKey:key]; 105 | } 106 | [table clear]; 107 | 108 | } while (10 > ++num); 109 | */ 110 | 111 | [ANKeyValueTable clearResumableTables]; 112 | 113 | CGFloat timeInterval1 = BNRTimeBlock(^{ 114 | [self executeSetOperation:1]; 115 | }); 116 | CGFloat timeInterval2 = BNRTimeBlock(^{ 117 | [self executeSetOperation:1]; 118 | }); 119 | CGFloat timeInterval3 = BNRTimeBlock(^{ 120 | [self executeSetOperation:1]; 121 | }); 122 | 123 | NSString *messsage = [NSString stringWithFormat:@"Calculate:10000 * 10 table\nConsuming:%fs\n(Average of 3 times)", 124 | (timeInterval1+timeInterval2+timeInterval3)/3]; 125 | NSLog(@"Set Str Operation: %@", messsage); 126 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Set Str Operation" 127 | message:messsage 128 | delegate:nil 129 | cancelButtonTitle:@"YES" 130 | otherButtonTitles:nil]; 131 | [alert show]; 132 | } 133 | 134 | - (IBAction)didPressGetOperationButtonAction:(id)sender { 135 | 136 | [self executeSetOperation:1]; 137 | 138 | CGFloat timeInterval1 = BNRTimeBlock(^{ 139 | [self executeGetOperation]; 140 | }); 141 | CGFloat timeInterval2 = BNRTimeBlock(^{ 142 | [self executeGetOperation]; 143 | }); 144 | CGFloat timeInterval3 = BNRTimeBlock(^{ 145 | [self executeGetOperation]; 146 | }); 147 | 148 | NSString *messsage = [NSString stringWithFormat:@"Calculate:10000 * 10 table\nConsuming:%fs\n(Average of 3 times)", 149 | (timeInterval1+timeInterval2+timeInterval3)/3]; 150 | NSLog(@"Get Str Operation: %@", messsage); 151 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Get Str Operation" 152 | message:messsage 153 | delegate:nil 154 | cancelButtonTitle:@"YES" 155 | otherButtonTitles:nil]; 156 | [alert show]; 157 | } 158 | 159 | - (void)executeSetOperation:(int)type 160 | { 161 | @autoreleasepool { 162 | NSMutableArray *tableArr = [NSMutableArray array]; 163 | int num = 0; 164 | do { 165 | 166 | NSString *key = [NSString stringWithFormat:@"SetOperation-%d", num]; 167 | ANKeyValueTable *table = [_tableDict objectForKey:key]; 168 | if (nil == table) { 169 | table = [ANKeyValueTable tableWithName:key version:@"0.0.9" resumable:YES]; 170 | [_tableDict setObject:table forKey:key]; 171 | } 172 | [tableArr addObject:table]; 173 | 174 | } while (10 > ++num); 175 | 176 | NSInteger total = 10000; 177 | NSInteger count = total; 178 | while (count) { 179 | 180 | for (ANKeyValueTable *t in tableArr) { 181 | //int randNum = arc4random(); 182 | int randNum = (int)count; 183 | NSString *key = [NSString stringWithFormat:@"Key-%d", randNum]; 184 | 185 | if (0 == type) { 186 | 187 | [t setInt:randNum withKey:key]; 188 | 189 | } else { 190 | 191 | [t setValue:@"ABCDEFGHIJKLMNOPQRSTVUWXYZ" withKey:key]; 192 | 193 | } 194 | 195 | } 196 | 197 | count--; 198 | } 199 | } 200 | } 201 | 202 | - (void)executeGetOperation 203 | { 204 | @autoreleasepool { 205 | 206 | NSMutableArray *tableArr = [NSMutableArray array]; 207 | int num = 0; 208 | do { 209 | 210 | NSString *key = [NSString stringWithFormat:@"SetOperation-%d", num]; 211 | ANKeyValueTable *table = [_tableDict objectForKey:key]; 212 | if (nil == table) { 213 | table = [ANKeyValueTable tableWithName:key version:@"0.0.9" resumable:YES]; 214 | [_tableDict setObject:table forKey:key]; 215 | } 216 | [tableArr addObject:table]; 217 | 218 | } while (10 > ++num); 219 | 220 | NSInteger total = 10000; 221 | NSInteger count = total; 222 | while (count) { 223 | 224 | for (ANKeyValueTable *t in tableArr) { 225 | //int randNum = arc4random(); 226 | int randNum = (int)count; 227 | NSString *key = [NSString stringWithFormat:@"Key-%d", randNum]; 228 | NSString *value = [t valueWithKey:key]; 229 | if (nil != value) { 230 | 231 | // do noting 232 | } 233 | } 234 | 235 | count--; 236 | } 237 | } 238 | } 239 | 240 | @end 241 | -------------------------------------------------------------------------------- /ANKeyValue/PerformanceViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 35 | 48 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /ANKeyValue/SetDemoItem.h: -------------------------------------------------------------------------------- 1 | // 2 | // SetDemoItem.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 6/11/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AutoCoding.h" 11 | #import "ANKeyValueProtocol.h" 12 | 13 | @interface SetDemoItem : NSObject 14 | 15 | @property (nonatomic, strong) NSString *timeStr; 16 | 17 | @property (nonatomic, assign) int randNum; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /ANKeyValue/SetDemoItem.m: -------------------------------------------------------------------------------- 1 | // 2 | // SetDemoItem.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 6/11/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "SetDemoItem.h" 10 | 11 | @implementation SetDemoItem 12 | 13 | - (BOOL)shouldEncodeWithDataBlock 14 | { 15 | return NO; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /ANKeyValue/SetDemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SetDemoViewController.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/12/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SetDemoViewController : UIViewController 12 | 13 | @property (nonatomic, strong) IBOutlet UITableView *tableView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /ANKeyValue/SetDemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SetDemoViewController.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 1/12/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "SetDemoViewController.h" 10 | #import "ANKeyValueTable.h" 11 | #import "SetDemoItem.h" 12 | #import "TableHelper.h" 13 | 14 | @interface SetDemoViewController () 15 | 16 | @property (nonatomic, strong) NSMutableArray *itemList; 17 | 18 | @end 19 | 20 | @implementation SetDemoViewController 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | // Do any additional setup after loading the view from its nib. 25 | 26 | UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add" 27 | style:UIBarButtonItemStylePlain 28 | target:self 29 | action:@selector(didPressAddButtonAction:)]; 30 | self.navigationItem.rightBarButtonItem = addButtonItem; 31 | 32 | self.itemList = [[TableHelper getSetItemTable] containerWithKey:@"setItemList"]; 33 | } 34 | 35 | - (void)didReceiveMemoryWarning { 36 | [super didReceiveMemoryWarning]; 37 | // Dispose of any resources that can be recreated. 38 | } 39 | 40 | - (NSString *)date:(NSDate *)date stringWithFormat:(NSString *)string 41 | { 42 | static NSDateFormatter *localDateFormatter = nil; 43 | if (nil == localDateFormatter) { 44 | localDateFormatter = [[NSDateFormatter alloc] init]; 45 | [localDateFormatter setLocale:[NSLocale currentLocale]]; 46 | [localDateFormatter setDateStyle:NSDateFormatterMediumStyle]; 47 | [localDateFormatter setTimeStyle:NSDateFormatterShortStyle]; 48 | } 49 | [localDateFormatter setDateFormat:string]; 50 | return [localDateFormatter stringFromDate:date]; 51 | } 52 | 53 | - (void)didPressAddButtonAction:(id)sender 54 | { 55 | NSString *dateKey = [self date:[NSDate date] stringWithFormat:@"yyyy/MM/dd hh:mm"]; 56 | [self insertCellWithKey:dateKey]; 57 | } 58 | 59 | - (void)insertCellWithKey:(NSString *)key 60 | { 61 | int randNum = arc4random(); 62 | SetDemoItem *item = [[SetDemoItem alloc] init]; 63 | item.timeStr = key; 64 | item.randNum = randNum; 65 | 66 | if (nil == self.itemList) { 67 | self.itemList = [NSMutableArray array]; 68 | } 69 | [self.itemList addObject:item]; 70 | 71 | [[TableHelper getSetItemTable] setContainer:self.itemList withKey:@"setItemList"]; 72 | 73 | [self.tableView reloadData]; 74 | } 75 | 76 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 77 | { 78 | return [self.itemList count]; 79 | } 80 | 81 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 82 | { 83 | static NSString *cellIndentifier = @"TextCell"; 84 | UITableViewCell *textCell = [_tableView dequeueReusableCellWithIdentifier:cellIndentifier]; 85 | if (nil == textCell) { 86 | textCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIndentifier]; 87 | textCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 88 | textCell.detailTextLabel.adjustsFontSizeToFitWidth = YES; 89 | } 90 | 91 | SetDemoItem *item = [self.itemList objectAtIndex:indexPath.row]; 92 | textCell.textLabel.text = item.timeStr; 93 | textCell.detailTextLabel.text = [NSString stringWithFormat:@"%2X", item.randNum]; 94 | 95 | return textCell; 96 | } 97 | 98 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 99 | { 100 | NSString *key = [tableView cellForRowAtIndexPath:indexPath].textLabel.text; 101 | [self insertCellWithKey:key]; 102 | 103 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 104 | } 105 | 106 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 107 | { 108 | return YES; 109 | } 110 | 111 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 112 | { 113 | [self.itemList removeObjectAtIndex:indexPath.row]; 114 | [[TableHelper getSetItemTable] synchronize]; 115 | 116 | [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /ANKeyValue/SetDemoViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /ANKeyValue/TableHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableHelper.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 8/4/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ANKeyValueTable.h" 11 | 12 | @interface TableHelper : NSObject 13 | 14 | + (ANKeyValueTable *)getUserDefaultTable; 15 | 16 | + (ANKeyValueTable *)getSetItemTable; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /ANKeyValue/TableHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableHelper.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 8/4/15. 6 | // Copyright (c) 2015 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "TableHelper.h" 10 | 11 | @implementation TableHelper 12 | 13 | + (ANKeyValueTable *)getUserDefaultTable 14 | { 15 | return [ANKeyValueTable userDefaultTable]; 16 | } 17 | 18 | + (ANKeyValueTable *)getSetItemTable 19 | { 20 | return [ANKeyValueTable tableWithName:@"SetItem" version:@"1.0.0" resumable:YES]; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /ANKeyValue/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 12/24/14. 6 | // Copyright (c) 2014 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @property (nonatomic, strong) IBOutlet UITableView *tableView; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /ANKeyValue/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 12/24/14. 6 | // Copyright (c) 2014 SpringOx. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ANKeyValueTable.h" 11 | #import "SetDemoViewController.h" 12 | #import "PerformanceViewController.h" 13 | #import "ConcurrentViewController.h" 14 | 15 | @interface ViewController () 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | // Do any additional setup after loading the view, typically from a nib. 24 | 25 | 26 | } 27 | 28 | - (void)didReceiveMemoryWarning { 29 | [super didReceiveMemoryWarning]; 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 34 | { 35 | return 3; 36 | } 37 | 38 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 39 | { 40 | static NSString *cellIndentifier = @"TextCell"; 41 | UITableViewCell *textCell = [_tableView dequeueReusableCellWithIdentifier:cellIndentifier]; 42 | if (nil == textCell) { 43 | textCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier]; 44 | textCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 45 | } 46 | 47 | if (0 == indexPath.row) { 48 | textCell.textLabel.text = @"Set & Get"; 49 | } else if (1 == indexPath.row) { 50 | textCell.textLabel.text = @"Performance"; 51 | } else if (2 == indexPath.row) { 52 | textCell.textLabel.text = @"Concurrent"; 53 | } 54 | 55 | return textCell; 56 | } 57 | 58 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 59 | { 60 | [[NSUserDefaults standardUserDefaults] synchronize]; 61 | 62 | if (0 == indexPath.row) { 63 | SetDemoViewController *viewCtl = [[SetDemoViewController alloc] initWithNibName:nil bundle:nil]; 64 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 65 | viewCtl.title = cell.textLabel.text; 66 | [self.navigationController pushViewController:viewCtl animated:YES]; 67 | } else if (1 == indexPath.row) { 68 | PerformanceViewController *viewCtl = [[PerformanceViewController alloc] initWithNibName:nil bundle:nil]; 69 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 70 | viewCtl.title = cell.textLabel.text; 71 | [self.navigationController pushViewController:viewCtl animated:YES]; 72 | } else if (2 == indexPath.row) { 73 | ConcurrentViewController *viewCtl = [[ConcurrentViewController alloc] initWithNibName:nil bundle:nil]; 74 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 75 | viewCtl.title = cell.textLabel.text; 76 | [self.navigationController pushViewController:viewCtl animated:YES]; 77 | } 78 | 79 | [_tableView deselectRowAtIndexPath:indexPath animated:YES]; 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /ANKeyValue/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ANKeyValue 4 | // 5 | // Created by SpringOx on 12/24/14. 6 | // Copyright (c) 2014 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ANKeyValue/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringOx/ANKeyValue/3b8e8fb92f11777a9769eb93b8e921d1749b9d1e/ANKeyValue/test.png -------------------------------------------------------------------------------- /ANKeyValueTests/ANKeyValueTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ANKeyValueTests.m 3 | // ANKeyValueTests 4 | // 5 | // Created by SpringOx on 12/24/14. 6 | // Copyright (c) 2014 SpringOx. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "ANKeyValueTable.h" 12 | 13 | @interface ANKeyValueTests : XCTestCase 14 | 15 | @end 16 | 17 | @implementation ANKeyValueTests 18 | 19 | - (void)setUp { 20 | [super setUp]; 21 | // Put setup code here. This method is called before the invocation of each test method in the class. 22 | } 23 | 24 | - (void)tearDown { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | 27 | [super tearDown]; 28 | } 29 | 30 | //- (void)testExample { 31 | // // This is an example of a functional test case. 32 | // XCTAssert(YES, @"Pass"); 33 | //} 34 | 35 | //- (void)testPerformanceExample { 36 | // // This is an example of a performance test case. 37 | // [self measureBlock:^{ 38 | // // Put the code you want to measure the time of here. 39 | // }]; 40 | //} 41 | 42 | - (void)testSet { 43 | 44 | ANKeyValueTable *table = [ANKeyValueTable tableWithName:@"SetValueTest" version:@"0.0.1" resumable:YES]; 45 | [self measureBlock:^{ 46 | NSString *keyStr = [NSString stringWithFormat:@"Key-IntTest"]; 47 | [table setInt:INT32_MIN+1 withKey:keyStr]; 48 | NSNumber *value = [table valueWithKey:keyStr]; 49 | NSAssert1(INT32_MIN+1==[value intValue], @"int test fail", value); 50 | 51 | keyStr = [NSString stringWithFormat:@"Key-IntegerTest"]; 52 | [table setInteger:INT32_MAX withKey:keyStr]; 53 | value = [table valueWithKey:keyStr]; 54 | NSAssert1(INT32_MAX==[value integerValue], @"integer test fail", value); 55 | 56 | keyStr = [NSString stringWithFormat:@"Key-FloatTest"]; 57 | [table setFloat:MAXFLOAT withKey:keyStr]; 58 | value = [table valueWithKey:keyStr]; 59 | NSAssert1(MAXFLOAT==[[table valueWithKey:keyStr] floatValue], @"float test fail", value); 60 | 61 | keyStr = [NSString stringWithFormat:@"Key-DoubleTest"]; 62 | [table setDouble:MAXFLOAT+MAXFLOAT withKey:keyStr]; 63 | value = [table valueWithKey:keyStr]; 64 | NSAssert1(MAXFLOAT+MAXFLOAT==[[table valueWithKey:keyStr] doubleValue], @"double test fail", value); 65 | 66 | keyStr = [NSString stringWithFormat:@"Key-BoolTest"]; 67 | [table setBool:YES withKey:keyStr]; 68 | value = [table valueWithKey:keyStr]; 69 | NSAssert1(YES==[[table valueWithKey:keyStr] boolValue], @"bool test fail", value); 70 | NSAssert1(YES==[table boolWithKey:keyStr], @"bool test fail", value); 71 | }]; 72 | 73 | while ([table isArchiving]) { 74 | [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:3.f]]; 75 | } 76 | } 77 | 78 | - (void)testGet { 79 | 80 | ANKeyValueTable *preTable = [ANKeyValueTable tableWithName:@"GetValueTest" version:@"0.0.1" resumable:YES]; 81 | if (nil == [preTable valueWithKey:@"Key-GetTest1"]) { 82 | int count = 0; 83 | while (50 > ++count) { 84 | NSString *keyStr = [NSString stringWithFormat:@"Key-GetTest%d", count]; 85 | [preTable setInt:count withKey:keyStr]; 86 | } 87 | [preTable synchronize]; 88 | NSAssert(0, @"data for get test is not ready");; 89 | } 90 | 91 | [self measureBlock:^{ 92 | ANKeyValueTable *table = [ANKeyValueTable tableWithName:@"GetValueTest" version:@"0.0.1" resumable:YES]; 93 | int count = 0; 94 | while (50 > ++count) { 95 | NSString *keyStr = [NSString stringWithFormat:@"Key-GetTest%d", count]; 96 | NSNumber *value = [table valueWithKey:keyStr]; 97 | NSAssert1(count==[value intValue], @"get test fail", value); 98 | } 99 | }]; 100 | } 101 | 102 | - (void)testClear { 103 | 104 | ANKeyValueTable *preTable = [ANKeyValueTable tableWithName:@"ClearValueTest" version:@"0.0.1" resumable:YES]; 105 | if (nil == [preTable valueWithKey:@"Key-ClearTest1"]) { 106 | int count = 0; 107 | while (50 > ++count) { 108 | NSString *keyStr = [NSString stringWithFormat:@"Key-ClearTest%d", count]; 109 | [preTable setInt:count withKey:keyStr]; 110 | } 111 | [preTable synchronize]; 112 | } 113 | 114 | NSAssert(nil != [preTable valueWithKey:@"Key-ClearTest1"], @"data for clear test is not ready"); 115 | [preTable removeValueWithKey:@"Key-ClearTest1"]; 116 | NSAssert(nil == [preTable valueWithKey:@"Key-ClearTest1"], @"clear test is not passed"); 117 | 118 | int count = 1; 119 | while (50 > ++count) { 120 | NSString *keyStr = [NSString stringWithFormat:@"Key-ClearTest%d", count]; 121 | NSAssert(nil != [preTable valueWithKey:keyStr], @"data for clear test is not ready"); 122 | } 123 | [preTable clear]; 124 | count = 1; 125 | while (50 > ++count) { 126 | NSString *keyStr = [NSString stringWithFormat:@"Key-ClearTest%d", count]; 127 | NSAssert(nil == [preTable valueWithKey:keyStr], @"clear test is not passed"); 128 | } 129 | } 130 | 131 | - (void)testCrypt { 132 | 133 | ANKeyValueTable *cTable = [ANKeyValueTable tableWithName:@"CryptContentTest" version:@"0.0.1" resumable:YES]; 134 | NSString *c1 = @"Content-CryptTest"; 135 | [cTable encryptContent:c1 withKey:@"Key-CryptTest"]; 136 | NSString *c2 = [cTable decryptContentWithKey:@"Key-CryptTest"]; 137 | NSAssert([c1 isEqualToString:c2], @"crypt test is not passed"); 138 | } 139 | 140 | - (void)testUpdateVersion { 141 | 142 | ANKeyValueTable *table1 = [ANKeyValueTable tableWithName:@"UpdateVersionTest" version:@"0.0.1" resumable:NO]; 143 | if (nil == [table1 valueWithKey:@"Key-UpdateVersion"]) { 144 | NSString *keyStr = [NSString stringWithFormat:@"Key-UpdateVersion"]; 145 | [table1 setValue:[NSNumber numberWithBool:YES] withKey:keyStr]; 146 | [table1 synchronize]; 147 | NSAssert(0, @"data for update version test is not ready"); 148 | } 149 | 150 | ANKeyValueTable *table2 = [ANKeyValueTable tableWithName:@"UpdateVersionTest" version:@"0.1.1" resumable:NO]; 151 | NSAssert(nil == [table2 valueWithKey:@"Key-UpdateVersion"], @"update version test is not passed"); 152 | } 153 | 154 | - (void)testDataBlock { 155 | 156 | ANKeyValueTable *table = [ANKeyValueTable tableWithName:@"DataBlockTest" version:@"0.0.1" resumable:YES]; 157 | if (nil == [table valueWithKey:@"Key-DataBlockTest1"]) { 158 | NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"]; 159 | NSData *testData = [NSData dataWithContentsOfFile:filePath]; 160 | [table setResource:testData withKey:@"Key-DataBlockTest1"]; 161 | 162 | UIImage *testImg = [UIImage imageWithData:testData]; 163 | [table setResource:testImg withKey:@"Key-DataBlockTest2"]; 164 | 165 | [table synchronize]; 166 | NSAssert(0, @"data for data block test is not ready"); 167 | } 168 | 169 | NSData *data = [table resourceWithKey:@"Key-DataBlockTest1"]; 170 | NSAssert1([data isKindOfClass:[NSData class]], @"data block test is not passed", data); 171 | UIImage *image = [table resourceWithKey:@"Key-DataBlockTest2"]; 172 | NSAssert1([image isKindOfClass:[UIImage class]], @"data block test is not passed", image); 173 | } 174 | 175 | - (void)testContainer { 176 | 177 | ANKeyValueTable *table = [ANKeyValueTable tableWithName:@"ContainerTest" version:@"0.0.1" resumable:YES]; 178 | if (nil == [table valueWithKey:@"Key-ContainerSet"]) { 179 | NSMutableSet *set = [NSMutableSet set]; 180 | [table setContainer:set withKey:@"Key-ContainerSet"]; 181 | 182 | NSMutableArray *array = [NSMutableArray array]; 183 | [table setContainer:array withKey:@"Key-ContainerArray"]; 184 | 185 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 186 | [table setContainer:dictionary withKey:@"Key-ContainerDictionary"]; 187 | 188 | [table synchronize]; 189 | NSAssert(0, @"data for data block test is not ready"); 190 | } 191 | 192 | NSMutableSet *set = [table containerWithKey:@"Key-ContainerSet"]; 193 | [set addObject:@"test"]; 194 | 195 | NSMutableArray *array = [table containerWithKey:@"Key-ContainerArray"]; 196 | [array addObject:@"test"]; 197 | 198 | NSMutableDictionary *dictionary = [table containerWithKey:@"Key-ContainerDictionary"]; 199 | [dictionary setObject:@"test" forKey:@"keyValue"]; 200 | } 201 | 202 | @end 203 | -------------------------------------------------------------------------------- /ANKeyValueTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ANKeyValue(键值存储) 2 | ========= 3 | 4 | ###### A advanced "NSUserDefault" with key-value-based, a flexible and efficient object storage solution. 5 | 6 | ###### 一个基于key-value方式的NSUserDefault加强版,一种灵活又快捷的对象存储方案。 7 | 8 | With features: 9 | 10 | 1. multi-service, using the memory completely isolated; 11 | 12 | 2. support automatic serialization and de-serialization simplifies persistence; 13 | 14 | 3. long-lasting semi-automatic operation, refresh, Special Scene enforced; 15 | 16 | 4. supports concurrent execution of task execution queue; 17 | 18 | 5. support for policy control, multi-level storage; 19 | 20 | 6. support encryption / decryption operations; 21 | 22 | 具备特性: 23 | 24 | 1. 支持多业务,使用到存储完全隔离; 25 | 26 | 2. 支持自动序列化和反序列化,简化持久化; 27 | 28 | 3. 持久化操作半自动,定时刷新,特殊场景强制执行; 29 | 30 | 4. 支持任务执行队列化并发执行; 31 | 32 | 5. 支持策略控制,多级存储; 33 | 34 | 6. 支持加密/解密操作; 35 | 36 | 37 | ![Screenshot](https://github.com/SpringOx/ANKeyValue/blob/master/ANKeyValue-1.png) 38 | 39 | ![Screenshot](https://github.com/SpringOx/ANKeyValue/blob/master/ANKeyValue-2.png) 40 | 41 | ![Screenshot](https://github.com/SpringOx/ANKeyValue/blob/master/ANKeyValue-3.png) 42 | 43 | 44 | 45 | ### Usage(用法) 46 | 47 | ``` objective-c 48 | // 支持容器存储 49 | self.itemList = [[TableHelper getSetItemTable] containerWithKey:@"setItemList"]; 50 | 51 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 52 | { 53 | [self.itemList removeObjectAtIndex:indexPath.row]; 54 | [[TableHelper getSetItemTable] synchronize]; 55 | 56 | [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; 57 | } 58 | ``` 59 | 60 | ``` objective-c 61 | // 支持key-value值存储 62 | @autoreleasepool { 63 | NSMutableArray *tableArr = [NSMutableArray array]; 64 | int num = 0; 65 | do { 66 | 67 | NSString *key = [NSString stringWithFormat:@"SetOperation-%d", num]; 68 | ANKeyValueTable *table = [_tableDict objectForKey:key]; 69 | if (nil == table) { 70 | table = [ANKeyValueTable tableWithName:key version:@"0.0.9" resumable:YES]; 71 | [_tableDict setObject:table forKey:key]; 72 | } 73 | [tableArr addObject:table]; 74 | 75 | } while (10 > ++num); 76 | 77 | NSInteger total = 10000; 78 | NSInteger count = total; 79 | while (count) { 80 | 81 | for (ANKeyValueTable *t in tableArr) { 82 | //int randNum = arc4random(); 83 | int randNum = (int)count; 84 | NSString *key = [NSString stringWithFormat:@"Key-%d", randNum]; 85 | 86 | if (0 == type) { 87 | 88 | [t setInt:randNum withKey:key]; 89 | 90 | } else { 91 | 92 | [t setValue:@"ABCDEFGHIJKLMNOPQRSTVUWXYZ" withKey:key]; 93 | 94 | } 95 | 96 | } 97 | 98 | count--; 99 | } 100 | } 101 | ``` 102 | 103 | ``` objective-c 104 | // 支持加解密 105 | ANKeyValueTable *cTable = [ANKeyValueTable tableWithName:@"CryptContentTest" version:@"0.0.1" resumable:YES]; 106 | NSString *c1 = @"Content-CryptTest"; 107 | [cTable encryptContent:c1 withKey:@"Key-CryptTest"]; 108 | NSString *c2 = [cTable decryptContentWithKey:@"Key-CryptTest"]; 109 | NSAssert([c1 isEqualToString:c2], @"crypt test is not passed"); 110 | ``` 111 | 112 | ### Contact(联系) 113 | 114 | - [https://github.com/SpringOx](https://github.com/SpringOx)(GitHub) 115 | - [jiachunke@gmail.com](jiachunke@gmail.com)(Email) 116 | 117 | 118 | 119 | --------------------------------------------------------------------------------