Skip to content

Commit

Permalink
Added public initializer to the Realm Default Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Piñera committed Dec 21, 2015
1 parent d0e3e7a commit 214240a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// RealBasicView.swift
// SugarRecord
//
// Created by Pedro Pinera Buendia on 21/12/15.
// Copyright © 2015 SwiftReactive. All rights reserved.
//

import Foundation
2 changes: 1 addition & 1 deletion SugarRecord.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SugarRecord"
s.version = "2.1.1"
s.version = "2.1.3"
s.summary = "CoreData wrapper written on Swift"
s.homepage = "https://github.com/SwiftReactive/SugarRecord"
s.license = 'MIT'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3DB2B86F1BDEE67C005B7EF2"
BuildableName = "SugarRecord.framework"
BuildableName = "SugarRecordCoreData.framework"
BlueprintName = "SugarRecord-CoreData-iOS"
ReferencedContainer = "container:SugarRecord.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -43,7 +43,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3DB2B86F1BDEE67C005B7EF2"
BuildableName = "SugarRecord.framework"
BuildableName = "SugarRecordCoreData.framework"
BlueprintName = "SugarRecord-CoreData-iOS"
ReferencedContainer = "container:SugarRecord.xcodeproj">
</BuildableReference>
Expand All @@ -65,7 +65,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3DB2B86F1BDEE67C005B7EF2"
BuildableName = "SugarRecord.framework"
BuildableName = "SugarRecordCoreData.framework"
BlueprintName = "SugarRecord-CoreData-iOS"
ReferencedContainer = "container:SugarRecord.xcodeproj">
</BuildableReference>
Expand All @@ -83,7 +83,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3DB2B86F1BDEE67C005B7EF2"
BuildableName = "SugarRecord.framework"
BuildableName = "SugarRecordCoreData.framework"
BlueprintName = "SugarRecord-CoreData-iOS"
ReferencedContainer = "container:SugarRecord.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2319B8831C2402490050ABE8"
BuildableName = "SugarRecord-Realm-iOS.framework"
BuildableName = "SugarRecordRealm.framework"
BlueprintName = "SugarRecord-Realm-iOS"
ReferencedContainer = "container:SugarRecord.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -46,7 +46,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2319B8831C2402490050ABE8"
BuildableName = "SugarRecord-Realm-iOS.framework"
BuildableName = "SugarRecordRealm.framework"
BlueprintName = "SugarRecord-Realm-iOS"
ReferencedContainer = "container:SugarRecord.xcodeproj">
</BuildableReference>
Expand All @@ -64,7 +64,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2319B8831C2402490050ABE8"
BuildableName = "SugarRecord-Realm-iOS.framework"
BuildableName = "SugarRecordRealm.framework"
BlueprintName = "SugarRecord-Realm-iOS"
ReferencedContainer = "container:SugarRecord.xcodeproj">
</BuildableReference>
Expand Down
2 changes: 1 addition & 1 deletion SugarRecord/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>2.1.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
26 changes: 24 additions & 2 deletions SugarRecord/Source/Realm/Storages/RealmDefaultStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import RealmSwift
/// Default Realm storage. In this case the structure is much simpler (compared with CoreData) contexts are represented by Realm instances in the thread where they are requested.
public class RealmDefaultStorage: Storage {

// MARK: - Attributes

private let configuration: Realm.Configuration?


/// MARK: - Init

public init(configuration: Realm.Configuration? = nil) {
self.configuration = configuration
}


// MARK: - Storage conformance

/// Storage description. This description property is defined in the CustomStringLiteralConvertible protocol
Expand All @@ -24,14 +36,24 @@ public class RealmDefaultStorage: Storage {
/// Note: Use this context with the main thread only
public var mainContext: Context! {
get {
return try? Realm()
if let configuration = self.configuration {
return try? Realm(configuration: configuration)
}
else {
return try? Realm()
}
}
}

/// Save context. This context is mostly used for save operations
public var saveContext: Context! {
get {
return try? Realm()
if let configuration = self.configuration {
return try? Realm(configuration: configuration)
}
else {
return try? Realm()
}
}
}

Expand Down

0 comments on commit 214240a

Please sign in to comment.