Skip to content

Commit

Permalink
model name overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiki270 committed Apr 5, 2018
1 parent 2e3b665 commit d3c9d55
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
8 changes: 7 additions & 1 deletion Classes/CoreData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ public class CoreData {
/// Default implementation, should be sufficient in most cases
public static let `default` = CoreData()

/// Fallback container name, overrides bundle name globally
/// Use in multitarget apps with shared model
public static var fallbackContainerName: String?

/// Container name
let containerName: String

// MARK: Initialization

/// Initialize CoreData with an optional NSPersistentContainer name.
/// App name will be used as default if nil
public init(containerName: String? = nil) {
guard let containerName = containerName ?? Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String else {
guard let containerName = containerName ?? CoreData.fallbackContainerName ?? Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String else {
fatalError("CoreData container name is not set and can not be inferred")
}
self.containerName = containerName
Expand Down Expand Up @@ -83,6 +88,7 @@ public class CoreData {

// MARK: Private interface

/// Save context, private helper
private static func save(context: NSManagedObjectContext) throws {
if context.hasChanges {
try context.save()
Expand Down
4 changes: 4 additions & 0 deletions Classes/Libs/Filter/QueryFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public struct QueryFilter {

extension QueryFilter {

/// Convert filter to predicate
public func asPredicate() -> NSPredicate {
if let value = value as? String {
let predicate = NSPredicate(format: "\(field.name) \(type.interpretation)\(caseSensitive ? "" : "[c]") %@", value)
Expand All @@ -47,6 +48,9 @@ extension QueryFilter {
} else if let value = value as? LosslessStringConvertible {
let predicate = NSPredicate(format: "\(field.name) \(type.interpretation) \(value)")
return predicate
} else if let value = value as? Date {
let predicate = NSPredicate(format: "\(field.name) \(type.interpretation) %@", value as CVarArg)
return predicate
}
fatalError("Not implemented")
}
Expand Down
7 changes: 6 additions & 1 deletion Classes/Libs/Filter/QueryFilterType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public struct QueryFilterType: Equatable {

enum Storage: Equatable {
case equals
case equalEquals
case contains
case beginsWith
case endsWith
Expand All @@ -27,6 +28,8 @@ public struct QueryFilterType: Equatable {
public var interpretation: String {
switch storage {
case .equals:
return "="
case .equalEquals:
return "=="
case .contains:
return "CONTAINS"
Expand All @@ -52,8 +55,10 @@ public struct QueryFilterType: Equatable {
/// Internal storage.
let storage: Storage

/// ==
/// =
public static var equals: QueryFilterType { return .init(storage: .equals) }
/// ==
public static var equalEquals: QueryFilterType { return .init(storage: .equalEquals) }
/// CONTAINS
public static var contains: QueryFilterType { return .init(storage: .contains) }
/// BEGINSWITH
Expand Down
30 changes: 5 additions & 25 deletions Classes/Libs/Filter/QueryFilterValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,15 @@ public struct QueryFilterValue {
}
}

// /// Returns the `QueryData` value if it exists.
// public func data() -> [QueryData]? {
// switch storage {
// case .data(let data): return [data]
// case .array(let a): return a
// default: return nil
// }
// }

/// Another query field.
/// Query field.
public static func field(_ field: QueryField) -> QueryFilterValue {
return .init(storage: .field(field))
}

// /// A single value.
// public static func data<T>(_ data: T) throws -> QueryFilterValue {
// return try .init(storage: .data(queryDataSerialize(data: data)))
// }

// /// A single value.
// public static func array<T>(_ array: [T]) throws -> QueryFilterValue {
// let array = try array.map { try queryDataSerialize(data: $0) }
// return .init(storage: .array(array))
// }

// /// A sub query.
// public static func subquery(_ subquery: DatabaseQuery) -> QueryFilterValue {
// return .init(storage: .subquery(subquery))
// }
/// An array of supported values
public static func array<T>(_ array: [T]) throws -> QueryFilterValue where T: QueryDataRepresentable {
return .init(storage: .array(array))
}

/// No value.
public static func none() -> QueryFilterValue {
Expand Down
1 change: 1 addition & 0 deletions Classes/Protocols/QueryDataRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extension QueryDataRepresentable {

}

/// Internal substitute for
struct NULL: ExactQueryDataRepresentable {

var value: String {
Expand Down
2 changes: 1 addition & 1 deletion Reloaded.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Reloaded'
s.version = '1.0.0'
s.version = '1.0.1'
s.summary = 'Reloaded! Swift "ORM like" abstraction layer for CoreData'
s.swift_version = '4.0'

Expand Down

0 comments on commit d3c9d55

Please sign in to comment.