diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index f90b1afc..00000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.3.2 diff --git a/Example/Podfile b/Example/Podfile index f6155b1d..d8836d1d 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -5,14 +5,12 @@ target 'SugarRecord_Example' do pod 'SugarRecord', :path => "../" pod 'SugarRecord/CoreData', :path => "../" pod 'SugarRecord/CoreData+iCloud', :path => "../" - pod 'SugarRecord/Realm', :path => "../" end target 'SugarRecord_Tests' do pod 'SugarRecord', :path => "../" pod 'SugarRecord/CoreData', :path => "../" pod 'SugarRecord/CoreData+iCloud', :path => "../" - pod 'SugarRecord/Realm', :path => "../" pod 'Quick', "~> 0.10" pod 'Nimble', '~> 5.0' pod "OHHTTPStubs" diff --git a/Example/Podfile.lock b/Example/Podfile.lock index fcd52b3d..617a24f1 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,38 +1,29 @@ PODS: - - Nimble (5.0.0) - - OHHTTPStubs (5.2.1): - - OHHTTPStubs/Default (= 5.2.1) - - OHHTTPStubs/Core (5.2.1) - - OHHTTPStubs/Default (5.2.1): + - Nimble (5.1.1) + - OHHTTPStubs (6.0.0): + - OHHTTPStubs/Default (= 6.0.0) + - OHHTTPStubs/Core (6.0.0) + - OHHTTPStubs/Default (6.0.0): - OHHTTPStubs/Core - OHHTTPStubs/JSON - OHHTTPStubs/NSURLSession - OHHTTPStubs/OHPathHelpers - - OHHTTPStubs/JSON (5.2.1): + - OHHTTPStubs/JSON (6.0.0): - OHHTTPStubs/Core - - OHHTTPStubs/NSURLSession (5.2.1): - - OHHTTPStubs/Core - - OHHTTPStubs/OHPathHelpers (5.2.1) - - OHHTTPStubs/Swift (5.2.1): + - OHHTTPStubs/NSURLSession (6.0.0): - OHHTTPStubs/Core + - OHHTTPStubs/OHPathHelpers (6.0.0) + - OHHTTPStubs/Swift (6.0.0): + - OHHTTPStubs/Default - Quick (0.10.0) - - Realm (1.1.0): - - Realm/Headers (= 1.1.0) - - Realm/Headers (1.1.0) - - RealmSwift (1.1.0): - - Realm (= 1.1.0) - - Result (3.0.0) - - SnapKit (3.0.1) - - SugarRecord (3.0.0-alpha.2): - - SugarRecord/CoreData (= 3.0.0-alpha.2) - - SugarRecord/CoreData+iCloud (= 3.0.0-alpha.2) - - SugarRecord/Realm (= 3.0.0-alpha.2) - - SugarRecord/CoreData (3.0.0-alpha.2): - - Result (~> 3.0) - - SugarRecord/CoreData+iCloud (3.0.0-alpha.2): + - Result (3.2.1) + - SnapKit (3.2.0) + - SugarRecord (3.1.1): + - SugarRecord/CoreData (= 3.1.1) + - SugarRecord/CoreData+iCloud (= 3.1.1) + - SugarRecord/CoreData (3.1.1): - Result (~> 3.0) - - SugarRecord/Realm (3.0.0-alpha.2): - - RealmSwift (~> 1.1) + - SugarRecord/CoreData+iCloud (3.1.1): - Result (~> 3.0) DEPENDENCIES: @@ -44,22 +35,19 @@ DEPENDENCIES: - SugarRecord (from `../`) - SugarRecord/CoreData (from `../`) - SugarRecord/CoreData+iCloud (from `../`) - - SugarRecord/Realm (from `../`) EXTERNAL SOURCES: SugarRecord: :path: "../" SPEC CHECKSUMS: - Nimble: 56fc9f5020effa2206de22c3dd910f4fb011b92f - OHHTTPStubs: 3a42f25c00563b71355ac73112ba2324e9e6cef4 + Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29 + OHHTTPStubs: 752f9b11fd810a15162d50f11c06ff94f8e012eb Quick: 5d290df1c69d5ee2f0729956dcf0fd9a30447eaa - Realm: ceecf1a4540c4ce9efe196fe73fa9855bce05bd8 - RealmSwift: 838058b2db95b12cb86bd0cf209df642c33fb60a - Result: 1b3e431f37cbcd3ad89c6aa9ab0ae55515fae3b6 - SnapKit: f818b8326d45b4e1c777d0ab27b5c0a3624bfdeb - SugarRecord: 5d12c70dadef8e036edc795c76e533584b7da453 + Result: 2453a22e5c5b11c0c3a478736e82cd02f763b781 + SnapKit: 1ca44df72cfa543218d177cb8aab029d10d86ea7 + SugarRecord: d3c8f4df864518bf30e5bf32a62564b8397fe508 -PODFILE CHECKSUM: 93e4a0d6049261cca889912a17deebad59571a81 +PODFILE CHECKSUM: d61f456397a3e8bb696c939fc5e85337d5040894 COCOAPODS: 1.1.0.rc.2 diff --git a/Example/SugarRecord.xcodeproj/project.pbxproj b/Example/SugarRecord.xcodeproj/project.pbxproj index c567acce..02d06fb4 100644 --- a/Example/SugarRecord.xcodeproj/project.pbxproj +++ b/Example/SugarRecord.xcodeproj/project.pbxproj @@ -7,15 +7,9 @@ objects = { /* Begin PBXBuildFile section */ - 23226F871D9C1ECF006A6769 /* NewsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23226F861D9C1ECF006A6769 /* NewsService.swift */; }; - 23226F891D9C1F1A006A6769 /* RealmNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23226F881D9C1F1A006A6769 /* RealmNew.swift */; }; - 23226F8B1D9C22B1006A6769 /* NewsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23226F8A1D9C22B1006A6769 /* NewsView.swift */; }; 23E13E5B1D96896300204C82 /* CoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E341D96896300204C82 /* CoreData.swift */; }; - 23E13E5C1D96896300204C82 /* Realm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E351D96896300204C82 /* Realm.swift */; }; 23E13E5D1D96896300204C82 /* Track+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E381D96896300204C82 /* Track+CoreDataProperties.swift */; }; 23E13E5E1D96896300204C82 /* Track.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E391D96896300204C82 /* Track.swift */; }; - 23E13E5F1D96896300204C82 /* Issue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E3B1D96896300204C82 /* Issue.swift */; }; - 23E13E601D96896300204C82 /* Repository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E3C1D96896300204C82 /* Repository.swift */; }; 23E13E611D96896300204C82 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E3E1D96896300204C82 /* DataModel.xcdatamodeld */; }; 23E13E621D96896300204C82 /* CoreDataChangeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E431D96896300204C82 /* CoreDataChangeTests.swift */; }; 23E13E631D96896300204C82 /* CoreDataObservableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E441D96896300204C82 /* CoreDataObservableTests.swift */; }; @@ -27,23 +21,16 @@ 23E13E691D96896300204C82 /* DirUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E4E1D96896300204C82 /* DirUtilsTests.swift */; }; 23E13E6A1D96896300204C82 /* VersionControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E501D96896300204C82 /* VersionControllerTests.swift */; }; 23E13E6B1D96896300204C82 /* VersionProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E511D96896300204C82 /* VersionProviderTests.swift */; }; - 23E13E6C1D96896300204C82 /* RealmObservableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E551D96896300204C82 /* RealmObservableTests.swift */; }; - 23E13E6D1D96896300204C82 /* RealmTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E571D96896300204C82 /* RealmTests.swift */; }; - 23E13E6E1D96896300204C82 /* ResultsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E581D96896300204C82 /* ResultsTests.swift */; }; - 23E13E6F1D96896300204C82 /* RealmDefaultStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E5A1D96896300204C82 /* RealmDefaultStorageTests.swift */; }; 23E13E8F1D96899000204C82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 23E13E721D96899000204C82 /* Assets.xcassets */; }; 23E13E901D96899000204C82 /* Basic.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E741D96899000204C82 /* Basic.xcdatamodeld */; }; 23E13E911D96899000204C82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 23E13E771D96899000204C82 /* LaunchScreen.storyboard */; }; 23E13E921D96899000204C82 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E7A1D96899000204C82 /* AppDelegate.swift */; }; - 23E13E931D96899000204C82 /* CoreDataBasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E7E1D96899000204C82 /* CoreDataBasicView.swift */; }; - 23E13E941D96899000204C82 /* BasicObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E801D96899000204C82 /* BasicObject.swift */; }; - 23E13E951D96899000204C82 /* CoreDataBasicEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E811D96899000204C82 /* CoreDataBasicEntity.swift */; }; - 23E13E961D96899000204C82 /* RealmBasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E851D96899000204C82 /* RealmBasicView.swift */; }; - 23E13E971D96899000204C82 /* RealmBasicEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E871D96899000204C82 /* RealmBasicEntity.swift */; }; - 23E13E981D96899000204C82 /* RealmBasicObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E881D96899000204C82 /* RealmBasicObject.swift */; }; 23E13E991D96899000204C82 /* Directory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E8B1D96899000204C82 /* Directory.swift */; }; 23E13E9A1D96899000204C82 /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E8C1D96899000204C82 /* Random.swift */; }; 23E13E9B1D96899000204C82 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23E13E8E1D96899000204C82 /* ViewController.swift */; }; + 23FB2C051E97C8BB00432BCB /* CoreDataBasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23FB2BFA1E97C8BB00432BCB /* CoreDataBasicView.swift */; }; + 23FB2C061E97C8BB00432BCB /* BasicObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23FB2BFC1E97C8BB00432BCB /* BasicObject.swift */; }; + 23FB2C071E97C8BB00432BCB /* CoreDataBasicEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23FB2BFD1E97C8BB00432BCB /* CoreDataBasicEntity.swift */; }; 7F0014DAE56FEBE9A77EB8F3 /* Pods_SugarRecord_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DE4511BDA74E45A8EA0229D9 /* Pods_SugarRecord_Tests.framework */; }; A682778445C166ABA1550ECF /* Pods_SugarRecord_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB6674BDC2C223325C9246F4 /* Pods_SugarRecord_Example.framework */; }; /* End PBXBuildFile section */ @@ -60,15 +47,9 @@ /* Begin PBXFileReference section */ 199B6E9AFF9F22F151FCACD5 /* Pods-SugarRecord_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SugarRecord_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SugarRecord_Example/Pods-SugarRecord_Example.debug.xcconfig"; sourceTree = ""; }; - 23226F861D9C1ECF006A6769 /* NewsService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewsService.swift; sourceTree = ""; }; - 23226F881D9C1F1A006A6769 /* RealmNew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmNew.swift; sourceTree = ""; }; - 23226F8A1D9C22B1006A6769 /* NewsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewsView.swift; sourceTree = ""; }; 23E13E341D96896300204C82 /* CoreData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreData.swift; sourceTree = ""; }; - 23E13E351D96896300204C82 /* Realm.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Realm.swift; sourceTree = ""; }; 23E13E381D96896300204C82 /* Track+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Track+CoreDataProperties.swift"; sourceTree = ""; }; 23E13E391D96896300204C82 /* Track.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Track.swift; sourceTree = ""; }; - 23E13E3B1D96896300204C82 /* Issue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Issue.swift; sourceTree = ""; }; - 23E13E3C1D96896300204C82 /* Repository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Repository.swift; sourceTree = ""; }; 23E13E3F1D96896300204C82 /* DataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = DataModel.xcdatamodel; sourceTree = ""; }; 23E13E431D96896300204C82 /* CoreDataChangeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataChangeTests.swift; sourceTree = ""; }; 23E13E441D96896300204C82 /* CoreDataObservableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataObservableTests.swift; sourceTree = ""; }; @@ -80,23 +61,16 @@ 23E13E4E1D96896300204C82 /* DirUtilsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirUtilsTests.swift; sourceTree = ""; }; 23E13E501D96896300204C82 /* VersionControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionControllerTests.swift; sourceTree = ""; }; 23E13E511D96896300204C82 /* VersionProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionProviderTests.swift; sourceTree = ""; }; - 23E13E551D96896300204C82 /* RealmObservableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmObservableTests.swift; sourceTree = ""; }; - 23E13E571D96896300204C82 /* RealmTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmTests.swift; sourceTree = ""; }; - 23E13E581D96896300204C82 /* ResultsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultsTests.swift; sourceTree = ""; }; - 23E13E5A1D96896300204C82 /* RealmDefaultStorageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmDefaultStorageTests.swift; sourceTree = ""; }; 23E13E721D96899000204C82 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23E13E751D96899000204C82 /* Basic.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Basic.xcdatamodel; sourceTree = ""; }; 23E13E771D96899000204C82 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 23E13E7A1D96899000204C82 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 23E13E7E1D96899000204C82 /* CoreDataBasicView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataBasicView.swift; sourceTree = ""; }; - 23E13E801D96899000204C82 /* BasicObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicObject.swift; sourceTree = ""; }; - 23E13E811D96899000204C82 /* CoreDataBasicEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataBasicEntity.swift; sourceTree = ""; }; - 23E13E851D96899000204C82 /* RealmBasicView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmBasicView.swift; sourceTree = ""; }; - 23E13E871D96899000204C82 /* RealmBasicEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmBasicEntity.swift; sourceTree = ""; }; - 23E13E881D96899000204C82 /* RealmBasicObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmBasicObject.swift; sourceTree = ""; }; 23E13E8B1D96899000204C82 /* Directory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Directory.swift; sourceTree = ""; }; 23E13E8C1D96899000204C82 /* Random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Random.swift; sourceTree = ""; }; 23E13E8E1D96899000204C82 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 23FB2BFA1E97C8BB00432BCB /* CoreDataBasicView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataBasicView.swift; sourceTree = ""; }; + 23FB2BFC1E97C8BB00432BCB /* BasicObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicObject.swift; sourceTree = ""; }; + 23FB2BFD1E97C8BB00432BCB /* CoreDataBasicEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataBasicEntity.swift; sourceTree = ""; }; 43D59494AB8B01F49D62B037 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 54DE24CF394C35117CF642A6 /* Pods-SugarRecord_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SugarRecord_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SugarRecord_Tests/Pods-SugarRecord_Tests.debug.xcconfig"; sourceTree = ""; }; 5B476131E81A65EF61C0905C /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; @@ -131,45 +105,10 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 23226F811D9C1E9D006A6769 /* News */ = { - isa = PBXGroup; - children = ( - 23226F821D9C1EC6006A6769 /* Models */, - 23226F841D9C1EC6006A6769 /* Services */, - 23226F851D9C1EC6006A6769 /* Views */, - ); - path = News; - sourceTree = ""; - }; - 23226F821D9C1EC6006A6769 /* Models */ = { - isa = PBXGroup; - children = ( - 23226F881D9C1F1A006A6769 /* RealmNew.swift */, - ); - path = Models; - sourceTree = ""; - }; - 23226F841D9C1EC6006A6769 /* Services */ = { - isa = PBXGroup; - children = ( - 23226F861D9C1ECF006A6769 /* NewsService.swift */, - ); - path = Services; - sourceTree = ""; - }; - 23226F851D9C1EC6006A6769 /* Views */ = { - isa = PBXGroup; - children = ( - 23226F8A1D9C22B1006A6769 /* NewsView.swift */, - ); - path = Views; - sourceTree = ""; - }; 23E13E331D96896300204C82 /* Helpers */ = { isa = PBXGroup; children = ( 23E13E341D96896300204C82 /* CoreData.swift */, - 23E13E351D96896300204C82 /* Realm.swift */, ); name = Helpers; path = ../../Tests/Helpers; @@ -179,7 +118,6 @@ isa = PBXGroup; children = ( 23E13E371D96896300204C82 /* CoreData */, - 23E13E3A1D96896300204C82 /* Realm */, ); name = Models; path = ../../Tests/Models; @@ -194,15 +132,6 @@ path = CoreData; sourceTree = ""; }; - 23E13E3A1D96896300204C82 /* Realm */ = { - isa = PBXGroup; - children = ( - 23E13E3B1D96896300204C82 /* Issue.swift */, - 23E13E3C1D96896300204C82 /* Repository.swift */, - ); - path = Realm; - sourceTree = ""; - }; 23E13E3D1D96896300204C82 /* Resources */ = { isa = PBXGroup; children = ( @@ -218,7 +147,6 @@ 23E13E411D96896300204C82 /* CoreData */, 23E13E4A1D96896300204C82 /* Foundation */, 23E13E521D96896300204C82 /* Reactive */, - 23E13E531D96896300204C82 /* Realm */, ); name = Source; path = ../../Tests/Source; @@ -295,41 +223,6 @@ path = Reactive; sourceTree = ""; }; - 23E13E531D96896300204C82 /* Realm */ = { - isa = PBXGroup; - children = ( - 23E13E541D96896300204C82 /* Entities */, - 23E13E561D96896300204C82 /* Extensions */, - 23E13E591D96896300204C82 /* Storages */, - ); - path = Realm; - sourceTree = ""; - }; - 23E13E541D96896300204C82 /* Entities */ = { - isa = PBXGroup; - children = ( - 23E13E551D96896300204C82 /* RealmObservableTests.swift */, - ); - path = Entities; - sourceTree = ""; - }; - 23E13E561D96896300204C82 /* Extensions */ = { - isa = PBXGroup; - children = ( - 23E13E571D96896300204C82 /* RealmTests.swift */, - 23E13E581D96896300204C82 /* ResultsTests.swift */, - ); - path = Extensions; - sourceTree = ""; - }; - 23E13E591D96896300204C82 /* Storages */ = { - isa = PBXGroup; - children = ( - 23E13E5A1D96896300204C82 /* RealmDefaultStorageTests.swift */, - ); - path = Storages; - sourceTree = ""; - }; 23E13E701D96899000204C82 /* Resources */ = { isa = PBXGroup; children = ( @@ -367,8 +260,8 @@ 23E13E781D96899000204C82 /* Source */ = { isa = PBXGroup; children = ( + 23FB2BF71E97C8BB00432BCB /* Examples */, 23E13E791D96899000204C82 /* App */, - 23E13E7B1D96899000204C82 /* Examples */, 23E13E8A1D96899000204C82 /* Helpers */, 23E13E8D1D96899000204C82 /* Main */, ); @@ -383,99 +276,111 @@ path = App; sourceTree = ""; }; - 23E13E7B1D96899000204C82 /* Examples */ = { + 23E13E8A1D96899000204C82 /* Helpers */ = { + isa = PBXGroup; + children = ( + 23E13E8B1D96899000204C82 /* Directory.swift */, + 23E13E8C1D96899000204C82 /* Random.swift */, + ); + path = Helpers; + sourceTree = ""; + }; + 23E13E8D1D96899000204C82 /* Main */ = { isa = PBXGroup; children = ( - 23226F811D9C1E9D006A6769 /* News */, - 23E13E7C1D96899000204C82 /* CoreData */, - 23E13E831D96899000204C82 /* Realm */, + 23E13E8E1D96899000204C82 /* ViewController.swift */, + ); + path = Main; + sourceTree = ""; + }; + 23FB2BF71E97C8BB00432BCB /* Examples */ = { + isa = PBXGroup; + children = ( + 23FB2BF81E97C8BB00432BCB /* CoreData */, + 23FB2BFE1E97C8BB00432BCB /* News */, + 23FB2C021E97C8BB00432BCB /* Realm */, ); path = Examples; sourceTree = ""; }; - 23E13E7C1D96899000204C82 /* CoreData */ = { + 23FB2BF81E97C8BB00432BCB /* CoreData */ = { isa = PBXGroup; children = ( - 23E13E7D1D96899000204C82 /* Basic */, - 23E13E7F1D96899000204C82 /* Models */, - 23E13E821D96899000204C82 /* Observable */, + 23FB2BF91E97C8BB00432BCB /* Basic */, + 23FB2BFB1E97C8BB00432BCB /* Models */, ); path = CoreData; sourceTree = ""; }; - 23E13E7D1D96899000204C82 /* Basic */ = { + 23FB2BF91E97C8BB00432BCB /* Basic */ = { isa = PBXGroup; children = ( - 23E13E7E1D96899000204C82 /* CoreDataBasicView.swift */, + 23FB2BFA1E97C8BB00432BCB /* CoreDataBasicView.swift */, ); path = Basic; sourceTree = ""; }; - 23E13E7F1D96899000204C82 /* Models */ = { + 23FB2BFB1E97C8BB00432BCB /* Models */ = { isa = PBXGroup; children = ( - 23E13E801D96899000204C82 /* BasicObject.swift */, - 23E13E811D96899000204C82 /* CoreDataBasicEntity.swift */, + 23FB2BFC1E97C8BB00432BCB /* BasicObject.swift */, + 23FB2BFD1E97C8BB00432BCB /* CoreDataBasicEntity.swift */, ); path = Models; sourceTree = ""; }; - 23E13E821D96899000204C82 /* Observable */ = { + 23FB2BFE1E97C8BB00432BCB /* News */ = { isa = PBXGroup; children = ( + 23FB2BFF1E97C8BB00432BCB /* Models */, + 23FB2C001E97C8BB00432BCB /* Services */, + 23FB2C011E97C8BB00432BCB /* Views */, ); - path = Observable; + path = News; sourceTree = ""; }; - 23E13E831D96899000204C82 /* Realm */ = { + 23FB2BFF1E97C8BB00432BCB /* Models */ = { isa = PBXGroup; children = ( - 23E13E841D96899000204C82 /* Basic */, - 23E13E861D96899000204C82 /* Models */, - 23E13E891D96899000204C82 /* Observable */, ); - path = Realm; + path = Models; sourceTree = ""; }; - 23E13E841D96899000204C82 /* Basic */ = { + 23FB2C001E97C8BB00432BCB /* Services */ = { isa = PBXGroup; children = ( - 23E13E851D96899000204C82 /* RealmBasicView.swift */, ); - path = Basic; + path = Services; sourceTree = ""; }; - 23E13E861D96899000204C82 /* Models */ = { + 23FB2C011E97C8BB00432BCB /* Views */ = { isa = PBXGroup; children = ( - 23E13E871D96899000204C82 /* RealmBasicEntity.swift */, - 23E13E881D96899000204C82 /* RealmBasicObject.swift */, ); - path = Models; + path = Views; sourceTree = ""; }; - 23E13E891D96899000204C82 /* Observable */ = { + 23FB2C021E97C8BB00432BCB /* Realm */ = { isa = PBXGroup; children = ( + 23FB2C031E97C8BB00432BCB /* Basic */, + 23FB2C041E97C8BB00432BCB /* Models */, ); - path = Observable; + path = Realm; sourceTree = ""; }; - 23E13E8A1D96899000204C82 /* Helpers */ = { + 23FB2C031E97C8BB00432BCB /* Basic */ = { isa = PBXGroup; children = ( - 23E13E8B1D96899000204C82 /* Directory.swift */, - 23E13E8C1D96899000204C82 /* Random.swift */, ); - path = Helpers; + path = Basic; sourceTree = ""; }; - 23E13E8D1D96899000204C82 /* Main */ = { + 23FB2C041E97C8BB00432BCB /* Models */ = { isa = PBXGroup; children = ( - 23E13E8E1D96899000204C82 /* ViewController.swift */, ); - path = Main; + path = Models; sourceTree = ""; }; 51C9EF80959BF8FABCA8F5A9 /* Pods */ = { @@ -768,19 +673,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 23E13E931D96899000204C82 /* CoreDataBasicView.swift in Sources */, - 23E13E941D96899000204C82 /* BasicObject.swift in Sources */, + 23FB2C051E97C8BB00432BCB /* CoreDataBasicView.swift in Sources */, 23E13E9A1D96899000204C82 /* Random.swift in Sources */, - 23226F8B1D9C22B1006A6769 /* NewsView.swift in Sources */, 23E13E921D96899000204C82 /* AppDelegate.swift in Sources */, 23E13E9B1D96899000204C82 /* ViewController.swift in Sources */, - 23E13E981D96899000204C82 /* RealmBasicObject.swift in Sources */, - 23226F871D9C1ECF006A6769 /* NewsService.swift in Sources */, + 23FB2C061E97C8BB00432BCB /* BasicObject.swift in Sources */, 23E13E901D96899000204C82 /* Basic.xcdatamodeld in Sources */, - 23226F891D9C1F1A006A6769 /* RealmNew.swift in Sources */, - 23E13E951D96899000204C82 /* CoreDataBasicEntity.swift in Sources */, - 23E13E971D96899000204C82 /* RealmBasicEntity.swift in Sources */, - 23E13E961D96899000204C82 /* RealmBasicView.swift in Sources */, + 23FB2C071E97C8BB00432BCB /* CoreDataBasicEntity.swift in Sources */, 23E13E991D96899000204C82 /* Directory.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -789,26 +688,19 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 23E13E6C1D96896300204C82 /* RealmObservableTests.swift in Sources */, 23E13E631D96896300204C82 /* CoreDataObservableTests.swift in Sources */, 23E13E681D96896300204C82 /* RequestTests.swift in Sources */, 23E13E621D96896300204C82 /* CoreDataChangeTests.swift in Sources */, - 23E13E5F1D96896300204C82 /* Issue.swift in Sources */, 23E13E6A1D96896300204C82 /* VersionControllerTests.swift in Sources */, 23E13E5B1D96896300204C82 /* CoreData.swift in Sources */, 23E13E641D96896300204C82 /* ObjectModelTests.swift in Sources */, 23E13E671D96896300204C82 /* CoreDataDefaultStorageTests.swift in Sources */, - 23E13E6D1D96896300204C82 /* RealmTests.swift in Sources */, - 23E13E5C1D96896300204C82 /* Realm.swift in Sources */, 23E13E611D96896300204C82 /* DataModel.xcdatamodeld in Sources */, 23E13E5D1D96896300204C82 /* Track+CoreDataProperties.swift in Sources */, 23E13E691D96896300204C82 /* DirUtilsTests.swift in Sources */, - 23E13E6E1D96896300204C82 /* ResultsTests.swift in Sources */, - 23E13E6F1D96896300204C82 /* RealmDefaultStorageTests.swift in Sources */, 23E13E6B1D96896300204C82 /* VersionProviderTests.swift in Sources */, 23E13E651D96896300204C82 /* OptionsTests.swift in Sources */, 23E13E5E1D96896300204C82 /* Track.swift in Sources */, - 23E13E601D96896300204C82 /* Repository.swift in Sources */, 23E13E661D96896300204C82 /* StoreTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Example/SugarRecord/Source/Examples/News/Models/RealmNew.swift b/Example/SugarRecord/Source/Examples/News/Models/RealmNew.swift deleted file mode 100644 index b9c9fbc2..00000000 --- a/Example/SugarRecord/Source/Examples/News/Models/RealmNew.swift +++ /dev/null @@ -1,10 +0,0 @@ -import Foundation -import RealmSwift - -class RealmNew: Object { - - // MARK: - Attributes - - dynamic var title: String = "" - -} diff --git a/Example/SugarRecord/Source/Examples/News/Services/NewsService.swift b/Example/SugarRecord/Source/Examples/News/Services/NewsService.swift deleted file mode 100644 index 586fe4cd..00000000 --- a/Example/SugarRecord/Source/Examples/News/Services/NewsService.swift +++ /dev/null @@ -1,54 +0,0 @@ -import Foundation -import SugarRecord -import RealmSwift - -class NewsService { - - // MARK: - Attributes - - private let session: URLSession - private let apiKey: String - private let storage: Storage - - // MARK: - Init - - init(session: URLSession, storage: Storage, apiKey: String) { - self.session = session - self.storage = storage - self.apiKey = apiKey - } - - convenience init(storage: Storage) { - self.init(session: URLSession.shared, storage: storage, apiKey: "c7a6b4e8e221414b88a5883a98bbfbf9") - } - - // MARK: - Sync - - internal func sync(completion: ((Swift.Error?) -> Void)? = nil) { - let url = URL(string: "https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=\(self.apiKey)")! - self.session.dataTask(with: url) { [weak self] (data, _, error) in - self?.save(data: data!) - completion?(error) - }.resume() - } - - // MARK: - Private - - private func save(data: Data) { - guard let dict = try! JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { return } - guard let articles = dict["articles"] as? [[String: Any]] else { return } - DispatchQueue.main.async { - _ = try? self.storage.operation { (context, save) -> Void in - let existing = try context.fetch(FetchRequest()) - try context.remove(existing) - for article in articles { - guard let title = article["title"] as? String else { return } - let new: RealmNew = try context.create() - new.title = title - } - save() - } - } - } - -} diff --git a/Example/SugarRecord/Source/Examples/News/Views/NewsView.swift b/Example/SugarRecord/Source/Examples/News/Views/NewsView.swift deleted file mode 100644 index ec3049cf..00000000 --- a/Example/SugarRecord/Source/Examples/News/Views/NewsView.swift +++ /dev/null @@ -1,100 +0,0 @@ -import Foundation -import UIKit -import SugarRecord -import RealmSwift - -class NewsView: UIViewController, UITableViewDelegate, UITableViewDataSource { - - // MARK: - Attributes - lazy var db: RealmDefaultStorage = { - var configuration = Realm.Configuration() - configuration.fileURL = URL(fileURLWithPath: databasePath("realm-news")) - let _storage = RealmDefaultStorage(configuration: configuration) - return _storage - }() - lazy var service: NewsService = { - return NewsService(storage: self.db) - }() - lazy var tableView: UITableView = { - let _tableView = UITableView(frame: CGRect.zero, style: UITableViewStyle.plain) - _tableView.translatesAutoresizingMaskIntoConstraints = false - _tableView.delegate = self - _tableView.dataSource = self - _tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "default-cell") - return _tableView - }() - var entities: [String] = [] { - didSet { - self.tableView.reloadData() - } - } - - // MARK: - Init - - init() { - super.init(nibName: nil, bundle: nil) - self.title = "News" - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - - // MARK: - Lifecycle - - override func viewDidLoad() { - super.viewDidLoad() - setup() - self.service.sync() - let request = FetchRequest() - self.db.observable(request).observe { [weak self] (change) in - switch change { - case .initial(let values): - self?.entities = values.map({$0.title}) - case .update(_, _, _): - do { - self?.entities = try self?.db.fetch(request).map({$0.title}) ?? [] - } catch {} - default: break - } - } - } - - - // MARK: - Private - - fileprivate func setup() { - setupView() - setupTableView() - } - - fileprivate func setupView() { - self.view.backgroundColor = UIColor.white - } - - fileprivate func setupTableView() { - self.view.addSubview(tableView) - self.tableView.snp.makeConstraints { (make) -> Void in - make.edges.equalTo(self.view) - } - } - - - // MARK: - UITableViewDataSource / UITableViewDelegate - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return self.entities.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "default-cell")! - cell.textLabel?.text = "\(entities[(indexPath as NSIndexPath).row])" - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - } - -} diff --git a/Example/SugarRecord/Source/Examples/Realm/Basic/RealmBasicView.swift b/Example/SugarRecord/Source/Examples/Realm/Basic/RealmBasicView.swift deleted file mode 100644 index 64c73132..00000000 --- a/Example/SugarRecord/Source/Examples/Realm/Basic/RealmBasicView.swift +++ /dev/null @@ -1,127 +0,0 @@ -import Foundation -import UIKit -import SugarRecord -import RealmSwift - -class RealmBasicView: UIViewController, UITableViewDelegate, UITableViewDataSource { - - // MARK: - Attributes - lazy var db: RealmDefaultStorage = { - var configuration = Realm.Configuration() - configuration.fileURL = URL(fileURLWithPath: databasePath("realm-basic")) - let _storage = RealmDefaultStorage(configuration: configuration) - return _storage - }() - lazy var tableView: UITableView = { - let _tableView = UITableView(frame: CGRect.zero, style: UITableViewStyle.plain) - _tableView.translatesAutoresizingMaskIntoConstraints = false - _tableView.delegate = self - _tableView.dataSource = self - _tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "default-cell") - return _tableView - }() - var entities: [RealmBasicEntity] = [] { - didSet { - self.tableView.reloadData() - } - } - - - // MARK: - Init - - init() { - super.init(nibName: nil, bundle: nil) - self.title = "Realm Basic" - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - deinit { - print("🚀🚀🚀 Deallocating \(self) 🚀🚀🚀") - } - - - // MARK: - Lifecycle - - override func viewDidLoad() { - super.viewDidLoad() - setup() - updateData() - } - - - // MARK: - Private - - fileprivate func setup() { - setupView() - setupNavigationItem() - setupTableView() - } - - fileprivate func setupView() { - self.view.backgroundColor = UIColor.white - } - - fileprivate func setupNavigationItem() { - self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.add, target: self, action: #selector(RealmBasicView.userDidSelectAdd(_:))) - } - - fileprivate func setupTableView() { - self.view.addSubview(tableView) - self.tableView.snp.makeConstraints { (make) -> Void in - make.edges.equalTo(self.view) - } - } - - - // MARK: - UITableViewDataSource / UITableViewDelegate - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return self.entities.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "default-cell")! - cell.textLabel?.text = "\(entities[(indexPath as NSIndexPath).row].name) - \(entities[(indexPath as NSIndexPath).row].dateString)" - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - } - - func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == UITableViewCellEditingStyle.delete { - let name = entities[(indexPath as NSIndexPath).row].name - try! db.operation({ (context, save) -> Void in - guard let obj = try! context.request(RealmBasicObject.self).filtered(with: "name", equalTo: name).fetch().first else { return } - _ = try? context.remove(obj) - save() - }) - updateData() - } - } - - - // MARK: - Actions - - func userDidSelectAdd(_ sender: AnyObject!) { - try! db.operation { (context, save) -> Void in - let _object: RealmBasicObject = try! context.new() - _object.date = Date() - _object.name = randomStringWithLength(10) as String - try! context.insert(_object) - save() - } - updateData() - } - - - // MARK: - Private - - fileprivate func updateData() { - self.entities = try! db.fetch(FetchRequest()).map(RealmBasicEntity.init) - } -} diff --git a/Example/SugarRecord/Source/Examples/Realm/Models/RealmBasicEntity.swift b/Example/SugarRecord/Source/Examples/Realm/Models/RealmBasicEntity.swift deleted file mode 100644 index 3e107205..00000000 --- a/Example/SugarRecord/Source/Examples/Realm/Models/RealmBasicEntity.swift +++ /dev/null @@ -1,21 +0,0 @@ -import Foundation - -class RealmBasicEntity { - - // MARK: - Attributes - - let dateString: String - let name: String - - - // MARK: - Init - - init(object: RealmBasicObject) { - let dateFormater = DateFormatter() - dateFormater.timeStyle = DateFormatter.Style.short - dateFormater.dateStyle = DateFormatter.Style.short - self.dateString = dateFormater.string(from: object.date as Date) - self.name = object.name - } - -} diff --git a/Example/SugarRecord/Source/Examples/Realm/Models/RealmBasicObject.swift b/Example/SugarRecord/Source/Examples/Realm/Models/RealmBasicObject.swift deleted file mode 100644 index 8fb0dee6..00000000 --- a/Example/SugarRecord/Source/Examples/Realm/Models/RealmBasicObject.swift +++ /dev/null @@ -1,18 +0,0 @@ -import Foundation -import RealmSwift - -class RealmBasicObject: Object { - - // MARK: - Attributes - - dynamic var date: Date = Date() - dynamic var name: String = "" - - - // MARK: - PrimaryKey - - internal override class func primaryKey() -> String? { - return "name" - } - -} diff --git a/Example/SugarRecord/Source/Main/ViewController.swift b/Example/SugarRecord/Source/Main/ViewController.swift index ccd24014..d62d8c56 100644 --- a/Example/SugarRecord/Source/Main/ViewController.swift +++ b/Example/SugarRecord/Source/Main/ViewController.swift @@ -64,10 +64,6 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega switch (indexPath as NSIndexPath).row { case 0: cell.textLabel?.text = "CoreData Basic" - case 1: - cell.textLabel?.text = "Realm Basic" - case 2: - cell.textLabel?.text = "News from API" default: cell.textLabel?.text = "" } @@ -80,10 +76,6 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega switch (indexPath as NSIndexPath).row { case 0: self.navigationController?.pushViewController(CoreDataBasicView(), animated: true) - case 1: - self.navigationController?.pushViewController(RealmBasicView(), animated: true) - case 2: - self.navigationController?.pushViewController(NewsView(), animated: true) default: break } diff --git a/SugarRecord/Source/CoreData/Storages/CoreDataDefaultStorage.swift b/SugarRecord/Source/CoreData/Storages/CoreDataDefaultStorage.swift index 62d07915..98dd061f 100644 --- a/SugarRecord/Source/CoreData/Storages/CoreDataDefaultStorage.swift +++ b/SugarRecord/Source/CoreData/Storages/CoreDataDefaultStorage.swift @@ -74,6 +74,32 @@ public class CoreDataDefaultStorage: Storage { return returnedObject } + + public func backgroundOperation(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) -> (), completion: @escaping (Error?) -> ()) { + let context: NSManagedObjectContext = self.saveContext as! NSManagedObjectContext + var _error: Error! + context.perform { + operation(context, { () -> Void in + do { + try context.save() + } + catch { + _error = error + } + self.rootSavingContext.perform { + if self.rootSavingContext.hasChanges { + do { + try self.rootSavingContext.save() + } + catch { + _error = error + } + } + completion(_error) + } + }) + } + } public func removeStore() throws { try FileManager.default.removeItem(at: store.path() as URL) diff --git a/SugarRecord/Source/CoreData/Storages/CoreDataiCloudStorage.swift b/SugarRecord/Source/CoreData/Storages/CoreDataiCloudStorage.swift index 07fbe80d..7501e3b9 100644 --- a/SugarRecord/Source/CoreData/Storages/CoreDataiCloudStorage.swift +++ b/SugarRecord/Source/CoreData/Storages/CoreDataiCloudStorage.swift @@ -78,6 +78,32 @@ public class CoreDataiCloudStorage: Storage { return returnedObject } + public func backgroundOperation(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) -> (), completion: @escaping (Error?) -> ()) { + let context: NSManagedObjectContext = self.saveContext as! NSManagedObjectContext + var _error: Error! + context.perform { + operation(context, { () -> Void in + do { + try context.save() + } + catch { + _error = error + } + self.rootSavingContext.perform { + if self.rootSavingContext.hasChanges { + do { + try self.rootSavingContext.save() + } + catch { + _error = error + } + } + completion(_error) + } + }) + } + } + public func removeStore() throws { try FileManager.default.removeItem(at: store.path() as URL) } diff --git a/SugarRecord/Source/Foundation/Entities/Storage.swift b/SugarRecord/Source/Foundation/Entities/Storage.swift index 2e00868b..bad0fd36 100644 --- a/SugarRecord/Source/Foundation/Entities/Storage.swift +++ b/SugarRecord/Source/Foundation/Entities/Storage.swift @@ -2,7 +2,6 @@ import Foundation public enum StorageType { case coreData - case realm } typealias StorageOperation = ((_ context: Context, _ save: () -> Void) throws -> Void) throws -> Void @@ -15,6 +14,7 @@ public protocol Storage: CustomStringConvertible, Requestable { var memoryContext: Context! { get } func removeStore() throws func operation(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) throws -> T) throws -> T + func backgroundOperation(_ operation: @escaping (_ context: Context, _ save: @escaping () -> Void) -> (), completion: @escaping (Error?) -> ()) func fetch(_ request: FetchRequest) throws -> [T] } diff --git a/Tests/Helpers/Realm.swift b/Tests/Helpers/Realm.swift deleted file mode 100755 index caa6ed94..00000000 --- a/Tests/Helpers/Realm.swift +++ /dev/null @@ -1,6 +0,0 @@ -import Foundation -import RealmSwift - -func testRealm() -> Realm { - return try! Realm(configuration: Realm.Configuration(inMemoryIdentifier: "TestRealm")) -} \ No newline at end of file diff --git a/Tests/Models/Realm/Issue.swift b/Tests/Models/Realm/Issue.swift deleted file mode 100755 index 91d09530..00000000 --- a/Tests/Models/Realm/Issue.swift +++ /dev/null @@ -1,25 +0,0 @@ -import Foundation -import RealmSwift - -@testable import SugarRecord - -class Issue: Object { - - // MARK: - Attributes - - dynamic var name: String = "" - dynamic var closed: Bool = false - dynamic var id: String = "" - - - // MARK: - Object - - internal override class func primaryKey() -> String? { - return "id" - } - - - // MARK: - Relationships - - dynamic var repository: Repository? -} \ No newline at end of file diff --git a/Tests/Models/Realm/Repository.swift b/Tests/Models/Realm/Repository.swift deleted file mode 100755 index c716c237..00000000 --- a/Tests/Models/Realm/Repository.swift +++ /dev/null @@ -1,18 +0,0 @@ -import Foundation -import RealmSwift - -@testable import SugarRecord - -class Repository: Object { - - // MARK: - Attributes - - dynamic var name: String = "" - dynamic var organization: String = "" - - - // MARK: - Relationships - - let issues = LinkingObjects(fromType: Issue.self, property: "repository") - -} \ No newline at end of file diff --git a/Tests/Source/CoreData/Storage/CoreDataDefaultStorageTests.swift b/Tests/Source/CoreData/Storage/CoreDataDefaultStorageTests.swift index ed6a1192..9d9b1912 100755 --- a/Tests/Source/CoreData/Storage/CoreDataDefaultStorageTests.swift +++ b/Tests/Source/CoreData/Storage/CoreDataDefaultStorageTests.swift @@ -118,7 +118,6 @@ class CoreDataDefaultStorageTests: QuickSpec { } describe("-operation:") { - it("should return the inner value from the operation") { waitUntil(action: { (done) -> Void in let result: String = try! subject.operation({ (context, save) -> String in @@ -132,8 +131,31 @@ class CoreDataDefaultStorageTests: QuickSpec { }) } - } + + describe("-backgroundOperation") { + it("should complete") { + waitUntil { (_done) in + subject.backgroundOperation({ (_, done) in + // Do nothing + done() + }, completion: { (error) in + _done() + }) + } + } + it("it shouldn't call the completion block in the main thread") { + waitUntil { (done) in + subject.backgroundOperation({ (_, _done) in + _done() + }, completion: { (_) in + XCTAssertFalse(Thread.isMainThread) + done() + }) + } + } + } + describe("-observable:") { diff --git a/Tests/Source/Foundation/Entities/RequestTests.swift b/Tests/Source/Foundation/Entities/RequestTests.swift index aa018dde..46fd1ccf 100755 --- a/Tests/Source/Foundation/Entities/RequestTests.swift +++ b/Tests/Source/Foundation/Entities/RequestTests.swift @@ -1,7 +1,6 @@ import Foundation import Quick import Nimble -import RealmSwift import Result @testable import SugarRecord @@ -14,45 +13,45 @@ class RequestTests: QuickSpec { it("-filtered:with") { let predicate: NSPredicate = NSPredicate(format: "name == TEST") - let request: FetchRequest = FetchRequest(testRealm()).filtered(with: predicate) + let request: FetchRequest = FetchRequest(testCoreData()).filtered(with: predicate) expect(request.predicate) == predicate } it("-filtered(with:value:)") { let predicate: NSPredicate = NSPredicate(format: "name == %@", "TEST") - let request: FetchRequest = FetchRequest(testRealm()).filtered(with: "name", equalTo: "TEST") + let request: FetchRequest = FetchRequest(testCoreData()).filtered(with: "name", equalTo: "TEST") expect(request.predicate) == predicate } it("-filtered:with:in:") { let predicate: NSPredicate = NSPredicate(format: "name IN %@", ["TEST"]) - let request: FetchRequest = FetchRequest(testRealm()).filtered(with: "name", in: ["TEST"]) + let request: FetchRequest = FetchRequest(testCoreData()).filtered(with: "name", in: ["TEST"]) expect(request.predicate) == predicate } it("-filtered:with:notIn:") { let predicate: NSPredicate = NSPredicate(format: "NOT name IN %@", ["TEST"]) - let request: FetchRequest = FetchRequest(testRealm()).filtered(with: "name", notIn: ["TEST"]) + let request: FetchRequest = FetchRequest(testCoreData()).filtered(with: "name", notIn: ["TEST"]) expect(request.predicate) == predicate } it("-sorted(with:ascending:comparator)") { let descriptor: NSSortDescriptor = NSSortDescriptor(key: "name", ascending: true, comparator: { _ in return ComparisonResult.orderedSame}) - let request: FetchRequest = FetchRequest(testRealm()).sorted(with: "name", ascending: true, comparator: {_ in return ComparisonResult.orderedSame}) + let request: FetchRequest = FetchRequest(testCoreData()).sorted(with: "name", ascending: true, comparator: {_ in return ComparisonResult.orderedSame}) expect(descriptor.key) == request.sortDescriptor?.key expect(descriptor.ascending) == request.sortDescriptor?.ascending } it("-sorted(with:ascending)") { let descriptor: NSSortDescriptor = NSSortDescriptor(key: "name", ascending: true) - let request: FetchRequest = FetchRequest(testRealm()).sorted(with: "name", ascending: true) + let request: FetchRequest = FetchRequest(testCoreData()).sorted(with: "name", ascending: true) expect(descriptor.key) == request.sortDescriptor?.key expect(descriptor.ascending) == request.sortDescriptor?.ascending } it("sorted(with:ascending:selector)") { let descriptor: NSSortDescriptor = NSSortDescriptor(key: "name", ascending: true, selector: Selector("selector")) - let request: FetchRequest = FetchRequest(testRealm()).sorted(with: "name", ascending: true, selector: Selector("selector")) + let request: FetchRequest = FetchRequest(testCoreData()).sorted(with: "name", ascending: true, selector: Selector("selector")) expect(descriptor.key) == request.sortDescriptor?.key expect(descriptor.ascending) == request.sortDescriptor?.ascending expect(descriptor.selector) == request.sortDescriptor?.selector diff --git a/Tests/Source/Foundation/Version/VersionProviderTests.swift b/Tests/Source/Foundation/Version/VersionProviderTests.swift index e818bb33..925ace83 100755 --- a/Tests/Source/Foundation/Version/VersionProviderTests.swift +++ b/Tests/Source/Foundation/Version/VersionProviderTests.swift @@ -12,7 +12,7 @@ class VersionProviderTests: QuickSpec { beforeEach { subject = VersionProvider() - _ = stub(condition: isPath("/repos/pepibumur/sugarrecord/releases")) { _ in + _ = stub(condition: isPath("/repos/carambalabs/sugarrecord/releases")) { _ in let object = [["tag_name": "3.1.0"]] return OHHTTPStubsResponse(jsonObject: object, statusCode: 200, headers: ["Content-Type":"application/json"]) } diff --git a/Tests/Source/Realm/Entities/RealmObservableTests.swift b/Tests/Source/Realm/Entities/RealmObservableTests.swift deleted file mode 100755 index a922bd4f..00000000 --- a/Tests/Source/Realm/Entities/RealmObservableTests.swift +++ /dev/null @@ -1,77 +0,0 @@ -import Foundation -import Quick -import Nimble -import RealmSwift - -@testable import SugarRecord - -class RealmObservableTests: QuickSpec { - - override func spec() { - - var subject: RealmObservable! - var request: FetchRequest! - var realm: Realm! - - beforeEach { - realm = testRealm() - realm.beginWrite() - realm.create(Issue.self, value: ["id": "123", "name": "issue"], update: true) - try! realm.commitWrite() - request = FetchRequest() - subject = RealmObservable(request: request, realm: realm) - } - - afterEach { - realm.beginWrite() - realm.deleteAll() - try! realm.commitWrite() - } - - describe("-observe:") { - - context("initial") { - it("should notify about the initial state") { - waitUntil(action: { (done) in - subject.observe({ (change) in - switch change { - case .initial(let issues): - expect(issues.first?.id) == "123" - done() - default: - break - } - }) - }) - } - } - - //FIXME -// context("update") { -// it("should notify about updates") { -// waitUntil(timeout: 5.0, action: { (done) in -// var called: Bool = false -// subject.observe({ (change) in -// switch change { -// case .update(_, let insertions, _): -// if !called { -// expect(insertions.first?.element.id) == "666" -// done() -// called = true -// } -// default: -// break -// } -// }) -// realm.beginWrite() -// realm.create(Issue.self, value: ["id": "666", "name": "issue"], update: true) -// try! realm.commitWrite() -// }) -// } -// } - - } - - } - -} diff --git a/Tests/Source/Realm/Extensions/RealmTests.swift b/Tests/Source/Realm/Extensions/RealmTests.swift deleted file mode 100755 index 945e20cd..00000000 --- a/Tests/Source/Realm/Extensions/RealmTests.swift +++ /dev/null @@ -1,82 +0,0 @@ -import Foundation -import Quick -import Nimble -import RealmSwift -import Result - -@testable import SugarRecord - -class RealmTests: QuickSpec { - - override func spec() { - - var subject: Realm? - - beforeEach { - subject = testRealm() - } - - afterEach { - subject!.beginWrite() - subject!.deleteAll() - _ = try? subject!.commitWrite() - } - - describe("fetching") { - it("should properly fetch objects persisted in the database") { - let issue = Issue() - subject?.beginWrite() - subject?.add(issue) - _ = try? subject?.commitWrite() - let fetched: [Issue] = try! subject!.request(Issue.self).fetch() - expect(fetched.count) == 1 - } - } - - describe("insert") { - it("should return the object inserted in the Realm") { - subject!.beginWrite() - let inserted: Issue = try! subject!.create() - _ = try? subject!.commitWrite() - _ = inserted - expect(subject!.objects(Issue.self).count) == 1 - } - } - - describe("remove") { - - it("should remove objects from Realm properly") { - try! subject!.write({ () -> Void in - let issue: Issue = Issue() - issue.name = "test" - subject!.add(issue) - }) - - // Fetching - let _issue = subject!.objects(Issue.self).filter("name == %@", "test").first! - subject?.beginWrite() - try! (subject as? Context)!.remove([_issue]) - try! subject?.commitWrite() - - // Testing - expect(subject!.objects(Issue.self).count) == 0 - } - - } - - describe("removeAll") { - it("should remove all the objects in the Realm") { - try! subject!.write({ () -> Void in - let issue: Issue = Issue() - issue.name = "test" - subject!.add(issue) - }) - subject?.beginWrite() - try! (subject as? Context)!.removeAll() - try! subject?.commitWrite() - expect(subject!.objects(Issue.self).count) == 0 - } - } - - } -} \ No newline at end of file diff --git a/Tests/Source/Realm/Extensions/ResultsTests.swift b/Tests/Source/Realm/Extensions/ResultsTests.swift deleted file mode 100755 index 00195ccf..00000000 --- a/Tests/Source/Realm/Extensions/ResultsTests.swift +++ /dev/null @@ -1,46 +0,0 @@ -import Foundation -import Quick -import Nimble -import RealmSwift - -@testable import SugarRecord - -class ResultsTests: QuickSpec { - - override func spec() { - - var realm: Realm? - - beforeEach { - realm = testRealm() - } - - afterEach { - realm!.beginWrite() - realm!.deleteAll() - _ = try? realm!.commitWrite() - } - - describe("array generation") { - - it("should return the same number of elements") { - let issue = Issue() - realm?.beginWrite() - realm?.add(issue) - _ = try? realm?.commitWrite() - expect(realm?.objects(Issue.self).toArray().count) == 1 - } - - it("should return the proper elements") { - let issue = Issue() - realm?.beginWrite() - issue.name = "test" - realm?.add(issue) - _ = try? realm?.commitWrite() - expect(realm?.objects(Issue.self).toArray().first?.name) == "test" - } - - } - } - -} \ No newline at end of file diff --git a/Tests/Source/Realm/Storages/RealmDefaultStorageTests.swift b/Tests/Source/Realm/Storages/RealmDefaultStorageTests.swift deleted file mode 100755 index cee7def4..00000000 --- a/Tests/Source/Realm/Storages/RealmDefaultStorageTests.swift +++ /dev/null @@ -1,104 +0,0 @@ -import Foundation -import Quick -import Nimble -import RealmSwift - -@testable import SugarRecord - -class RealmDefaultStorageTests: QuickSpec { - - override func spec() { - - var subject: RealmDefaultStorage! - - beforeEach { - subject = RealmDefaultStorage() - } - - afterEach { - _ = try? subject.removeStore() - } - - describe("-description") { - it("should have the correct description") { - expect(subject.description) == "RealmDefaultStorage" - } - } - - describe("-type") { - it("should have the correct type") { - expect(subject.type) == StorageType.realm - } - } - - describe("-memoryContext") { - it("should return a memory realm for the memory context") { - let memoryRealm: Realm? = subject.memoryContext as? Realm - expect(memoryRealm?.configuration.inMemoryIdentifier) == "MemoryRealm" - } - } - - describe("-removeStore") { - it("should remove the storage") { - _ = try? subject.removeStore() - let path = Realm.Configuration.defaultConfiguration.fileURL?.absoluteString - expect(FileManager.default.fileExists(atPath: path!)) == false - } - - it("shouldn't throw an exception") { - expect{ try subject!.removeStore() }.toNot(throwError()) - } - } - - describe("-operation:") { - - it("should save the changes if the save closure is called") { - waitUntil(action: { (done) -> Void in - _ = try? subject.operation({ (context, save) -> Void in - let issue: Issue = try! context.create() - issue.name = "test" - save() - }) - let fetched = try! subject.mainContext.request(Issue.self).fetch() - expect(fetched.count) == 1 - done() - }) - } - - it("shouldn't persist the changes if the save closure is not called") { - waitUntil(action: { (done) -> Void in - _ = try? subject.operation({ (context, save) -> Void in - let issue: Issue = try! context.create() - issue.name = "test" - }) - let fetched = try! subject.mainContext.request(Issue.self).fetch() - expect(fetched.count) == 0 - done() - }) - } - - } - - describe("-observable") { - - var observable: RealmObservable! - var request: FetchRequest! - - beforeEach { - request = FetchRequest() - observable = subject.observable(request) as! RealmObservable - } - - it("should have the correct request") { - expect(observable.realm) == subject.mainContext as? Realm - } - - it("should have the correct realm") { - expect((observable as RequestObservable).request) == request - } - - } - - } - -}