WIP: objc utilities

This commit is contained in:
John Rommel Estropia
2016-06-19 02:40:25 +09:00
parent 3d5c4f8121
commit e5a199489c
19 changed files with 913 additions and 177 deletions

View File

@@ -28,3 +28,5 @@
FOUNDATION_EXPORT double CoreStoreVersionNumber;
FOUNDATION_EXPORT const unsigned char CoreStoreVersionString[];
#import "CoreStoreBridge.h"

View File

@@ -41,6 +41,17 @@ import CoreData
*/
public struct From<T: NSManagedObject> {
/**
The associated `NSManagedObject` entity class
*/
public let entityClass: AnyClass
/**
The `NSPersistentStore` configuration names to associate objects from.
May contain `String`s to pertain to named configurations, or `nil` to pertain to the default configuration
*/
public let configurations: [String?]?
/**
Initializes a `From` clause.
```
@@ -49,7 +60,7 @@ public struct From<T: NSManagedObject> {
*/
public init(){
self.init(entityClass: T.self)
self.init(entityClass: T.self, configurations: nil)
}
/**
@@ -58,11 +69,11 @@ public struct From<T: NSManagedObject> {
let people = transaction.fetchAll(From<MyPersonEntity>())
```
- parameter entity: the `NSManagedObject` type to be created
- parameter entity: the associated `NSManagedObject` type
*/
public init(_ entity: T.Type) {
self.init(entityClass: entity)
self.init(entityClass: entity, configurations: nil)
}
/**
@@ -71,7 +82,7 @@ public struct From<T: NSManagedObject> {
let people = transaction.fetchAll(From<MyPersonEntity>())
```
- parameter entityClass: the `NSManagedObject` class type to be created
- parameter entityClass: the associated `NSManagedObject` entity class
*/
public init(_ entityClass: AnyClass) {
@@ -79,7 +90,7 @@ public struct From<T: NSManagedObject> {
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass)
self.init(entityClass: entityClass, configurations: nil)
}
/**
@@ -178,9 +189,6 @@ public struct From<T: NSManagedObject> {
// MARK: Internal
internal let entityClass: AnyClass
internal let dumpInfo: (key: String, value: Any)?
@warn_unused_result
internal func applyToFetchRequest(fetchRequest: NSFetchRequest, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool {
@@ -211,7 +219,7 @@ public struct From<T: NSManagedObject> {
return From<NSManagedObject>(
entityClass: self.entityClass,
dumpInfo: self.dumpInfo,
configurations: self.configurations,
findPersistentStores: self.findPersistentStores
)
}
@@ -221,197 +229,145 @@ public struct From<T: NSManagedObject> {
private let findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]?
private init(entityClass: AnyClass) {
private init(entityClass: AnyClass, configurations: [String?]?) {
self.init(
entityClass: entityClass,
dumpInfo: nil,
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
return context.parentStack?.persistentStoresForEntityClass(entityClass)
}
)
}
private init(entityClass: AnyClass, configurations: [String?]) {
let configurationsSet = Set(configurations.map { $0 ?? Into.defaultConfigurationName })
self.init(
entityClass: entityClass,
dumpInfo: ("configurations", configurations),
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
self.entityClass = entityClass
self.configurations = configurations
if let configurations = configurations {
let configurationsSet = Set(configurations.map { $0 ?? Into.defaultConfigurationName })
self.findPersistentStores = { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
return context.parentStack?.persistentStoresForEntityClass(entityClass)?.filter {
return configurationsSet.contains($0.configurationName)
}
}
)
}
private init(entityClass: AnyClass, storeURLs: [NSURL]) {
let storeURLsSet = Set(storeURLs)
self.init(
entityClass: entityClass,
dumpInfo: ("storeURLs", storeURLs),
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
}
else {
self.findPersistentStores = { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
return context.parentStack?.persistentStoresForEntityClass(entityClass)?.filter {
return $0.URL != nil && storeURLsSet.contains($0.URL!)
}
return context.parentStack?.persistentStoresForEntityClass(entityClass)
}
)
}
}
private init(entityClass: AnyClass, persistentStores: [NSPersistentStore]) {
let persistentStores = Set(persistentStores)
self.init(
entityClass: entityClass,
dumpInfo: ("persistentStores", persistentStores),
findPersistentStores: { (context: NSManagedObjectContext) -> [NSPersistentStore]? in
return context.parentStack?.persistentStoresForEntityClass(entityClass)?.filter {
return persistentStores.contains($0)
}
}
)
}
private init(entityClass: AnyClass, dumpInfo: (key: String, value: Any)?, findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]?) {
private init(entityClass: AnyClass, configurations: [String?]?, findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]?) {
self.entityClass = entityClass
self.dumpInfo = dumpInfo
self.configurations = configurations
self.findPersistentStores = findPersistentStores
}
// MARK: Deprecated
// MARK: Obsolete
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ storeURL: NSURL, _ otherStoreURLs: NSURL...) {
self.init(entityClass: T.self, storeURLs: [storeURL] + otherStoreURLs)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ storeURLs: [NSURL]) {
self.init(entityClass: T.self, storeURLs: storeURLs)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entity: T.Type, _ storeURL: NSURL, _ otherStoreURLs: NSURL...) {
self.init(entityClass: entity, storeURLs: [storeURL] + otherStoreURLs)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entity: T.Type, _ storeURLs: [NSURL]) {
self.init(entityClass: entity, storeURLs: storeURLs)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entityClass: AnyClass, _ storeURL: NSURL, _ otherStoreURLs: NSURL...) {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, storeURLs: [storeURL] + otherStoreURLs)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entityClass: AnyClass, _ storeURLs: [NSURL]) {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, storeURLs: storeURLs)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ persistentStore: NSPersistentStore, _ otherPersistentStores: NSPersistentStore...) {
self.init(entityClass: T.self, persistentStores: [persistentStore] + otherPersistentStores)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ persistentStores: [NSPersistentStore]) {
self.init(entityClass: T.self, persistentStores: persistentStores)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entity: T.Type, _ persistentStore: NSPersistentStore, _ otherPersistentStores: NSPersistentStore...) {
self.init(entityClass: entity, persistentStores: [persistentStore] + otherPersistentStores)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entity: T.Type, _ persistentStores: [NSPersistentStore]) {
self.init(entityClass: entity, persistentStores: persistentStores)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entityClass: AnyClass, _ persistentStore: NSPersistentStore, _ otherPersistentStores: NSPersistentStore...) {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, persistentStores: [persistentStore] + otherPersistentStores)
CoreStore.abort("Use initializers that accept configuration names.")
}
/**
Deprecated. Use initializers that accept configuration names.
Obsolete. Use initializers that accept configuration names.
*/
@available(*, deprecated=2.0.0, message="Use initializers that accept configuration names.")
@available(*, obsoleted=2.0.0, message="Use initializers that accept configuration names.")
public init(_ entityClass: AnyClass, _ persistentStores: [NSPersistentStore]) {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, persistentStores: persistentStores)
CoreStore.abort("Use initializers that accept configuration names.")
}
}

View File

@@ -35,14 +35,9 @@ import CoreData
public struct GroupBy: QueryClause, Hashable {
/**
Initializes a `GroupBy` clause with a list of key path strings
- parameter keyPaths: a list of key path strings to group results with
The list of key path strings to group results with
*/
public init(_ keyPaths: [KeyPath]) {
self.keyPaths = keyPaths
}
public let keyPaths: [KeyPath]
/**
Initializes a `GroupBy` clause with an empty list of key path strings
@@ -52,6 +47,16 @@ public struct GroupBy: QueryClause, Hashable {
self.init([])
}
/**
Initializes a `GroupBy` clause with a list of key path strings
- parameter keyPaths: a list of key path strings to group results with
*/
public init(_ keyPaths: [KeyPath]) {
self.keyPaths = keyPaths
}
/**
Initializes a `GroupBy` clause with a list of key path strings
@@ -63,8 +68,6 @@ public struct GroupBy: QueryClause, Hashable {
self.init([keyPath] + keyPaths)
}
public let keyPaths: [KeyPath]
// MARK: QueryClause

View File

@@ -412,10 +412,11 @@ extension Bool: SelectValueResultType {
}
public static func fromResultObject(result: AnyObject) -> Bool? {
switch result {
case let decimal as NSDecimalNumber:
// iOS: NSDecimalNumber(string: "0.5").boolValue // true
// OSX: NSDecimalNumber(string: "0.5").boolValue // false
return NSNumber(double: decimal.doubleValue).boolValue
case let number as NSNumber:

View File

@@ -51,14 +51,9 @@ public prefix func !(clause: Where) -> Where {
public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
/**
Initializes a `Where` clause with an `NSPredicate`
- parameter predicate: the `NSPredicate` for the fetch or query
The `NSPredicate` for the fetch or query
*/
public init(_ predicate: NSPredicate) {
self.predicate = predicate
}
public let predicate: NSPredicate
/**
Initializes a `Where` clause with a predicate that always evaluates to `true`
@@ -135,7 +130,15 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
self.init(NSPredicate(format: "\(keyPath) IN %@", Array(list) as NSArray))
}
public let predicate: NSPredicate
/**
Initializes a `Where` clause with an `NSPredicate`
- parameter predicate: the `NSPredicate` for the fetch or query
*/
public init(_ predicate: NSPredicate) {
self.predicate = predicate
}
// MARK: FetchClause, QueryClause, DeleteClause

View File

@@ -198,9 +198,9 @@ extension From: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
public var coreStoreDumpString: String {
var info: DumpInfo = [("entityClass", self.entityClass)]
if let extraInfo = self.dumpInfo {
if let configurations = self.configurations {
info.append(extraInfo)
info.append(("configurations", configurations))
}
return createFormattedString(
"(", ")",

View File

@@ -37,6 +37,32 @@ import CoreData
@objc
public final class CSFrom: NSObject, CoreStoreObjectiveCType {
/**
The associated `NSManagedObject` entity class
*/
@objc
public var entityClass: AnyClass {
return self.bridgeToSwift.entityClass
}
/**
The `NSPersistentStore` configuration names to associate objects from.
May contain `NSString` instances to pertain to named configurations, or `NSNull` to pertain to the default configuration
*/
@objc
public var configurations: [AnyObject]? {
return self.bridgeToSwift.configurations?.map {
switch $0 {
case nil: return NSNull()
case let string as NSString: return string
}
}
}
/**
Initializes a `CSFrom` clause with the specified entity class.
```
@@ -58,14 +84,24 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
MyPersonEntity *people = [transaction fetchAllFrom:[CSFrom entityClass:[MyPersonEntity class] configuration:@"Configuration1"]];
```
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `[NSNull null]` to use the default configuration.
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
- returns: a `CSFrom` clause with the specified configurations
*/
@objc
public static func entityClass(entityClass: AnyClass, configuration: String?) -> CSFrom {
public static func entityClass(entityClass: AnyClass, configuration: AnyObject) -> CSFrom {
return self.init(From(entityClass, configuration))
switch configuration {
case let string as String:
return self.init(From(entityClass, string))
case is NSNull:
return self.init(From(entityClass, nil))
default:
CoreStore.abort("The configuration argument only accepts NSString and NSNull values")
}
}
/**
@@ -81,7 +117,22 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
@objc
public static func entityClass(entityClass: AnyClass, configurations: [AnyObject]) -> CSFrom {
return self.init(From(entityClass, configurations.map { $0 is NSNull ? nil : ($0 as! String) }))
var arguments = [String?]()
for configuration in configurations {
switch configuration {
case let string as String:
arguments.append(string)
case is NSNull:
arguments.append(nil)
default:
CoreStore.abort("The configurations argument only accepts NSString and NSNull values")
}
}
return self.init(From(entityClass, arguments))
}

View File

@@ -37,6 +37,14 @@ import CoreData
@objc
public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
/**
The list of key path strings to group results with
*/
public var keyPaths: [KeyPath] {
return self.bridgeToSwift.keyPaths
}
/**
Initializes a `CSGroupBy` clause with a list of key path strings

View File

@@ -38,15 +38,12 @@ import CoreData
public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType {
/**
Initializes a `CSWhere` clause with an `NSPredicate`
- parameter predicate: the `NSPredicate` for the fetch or query
- returns: a `CSWhere` clause with an `NSPredicate`
The internal `NSPredicate` instance for the `Where` clause
*/
@objc
public static func predicate(predicate: NSPredicate) -> CSWhere {
public var predicate: NSPredicate {
return self.init(Where(predicate))
return self.bridgeToSwift.predicate
}
/**
@@ -100,6 +97,18 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
return self.init(Where(keyPath, isMemberOf: list))
}
/**
Initializes a `CSWhere` clause with an `NSPredicate`
- parameter predicate: the `NSPredicate` for the fetch or query
- returns: a `CSWhere` clause with an `NSPredicate`
*/
@objc
public static func predicate(predicate: NSPredicate) -> CSWhere {
return self.init(Where(predicate))
}
// MARK: NSObject

View File

@@ -0,0 +1,152 @@
//
// CoreStoreBridge.h
// CoreStore
//
// Copyright © 2016 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#import <Foundation/Foundation.h>
#ifndef CoreStoreBridge_h
#define CoreStoreBridge_h
#if !__has_feature(objc_arc)
#error CoreStore Objective-C utilities require ARC be enabled
#endif
#if !__has_extension(attribute_overloadable)
#error CoreStore Objective-C utilities can only be used on platforms that support C function overloading
#endif
#define CS_OBJC_EXTERN extern
#define CS_OBJC_OVERLOADABLE __attribute__((__overloadable__))
#define CS_OBJC_REQUIRES_NIL_TERMINATION(A, B) __attribute__((sentinel(A, B)))
// MARK: - From
@class CSFrom;
/**
@abstract
Initializes a <tt>CSFrom</tt> clause with the specified entity class.
@code
MyPersonEntity *people = [transaction fetchAllFrom:From([MyPersonEntity class])];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@result
a <tt>CSFrom</tt> clause with the specified entity class
*/
CS_OBJC_EXTERN CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull From(Class _Nonnull entityClass);
/**
@abstract
Initializes a <tt>CSFrom</tt> clause with the specified configurations.
@code
MyPersonEntity *people = [transaction fetchAllFrom:From([MyPersonEntity class], @[@"Configuration1"])];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@param configurations
an array of the <tt>NSPersistentStore</tt> configuration names to associate objects from. This parameter is required if multiple configurations contain the created <tt>NSManagedObject</tt>'s entity type. Set to <tt>[NSNull null]</tt> to use the default configuration.
@result
a <tt>CSFrom</tt> clause with the specified configurations
*/
CS_OBJC_EXTERN CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull From(Class _Nonnull entityClass, NSArray<id> *_Nonnull configurations);
// MARK: - Where
@class CSWhere;
/**
@abstract
Initializes a <tt>CSWhere</tt> clause with a predicate that always evaluates to the specified boolean value
@param value
the boolean value for the predicate
@result
a <tt>CSWhere</tt> clause with a predicate that always evaluates to the specified boolean value
*/
CS_OBJC_EXTERN CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(BOOL value);
/**
@abstract
Initializes a <tt>CSWhere</tt> clause with a predicate using the specified string format and arguments
@param format
the format string for the predicate
@param argumentArray
the arguments for <tt>format</tt>
@result
a <tt>CSWhere</tt> clause with a predicate using the specified string format and arguments
*/
CS_OBJC_EXTERN CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(NSString *_Nonnull format, ...);
/**
@abstract
Initializes a <tt>CSWhere</tt> clause with an <tt>NSPredicate</tt>
@param predicate
the <tt>NSPredicate</tt> for the fetch or query
@result
a <tt>CSWhere</tt> clause with an <tt>NSPredicate</tt>
*/
CS_OBJC_EXTERN CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(NSPredicate *_Nonnull predicate);
// MARK: - GroupBy
@class CSGroupBy;
/**
@abstract
Initializes a <tt>CSGroupBy</tt> clause with a list of key path strings
@param keyPaths
a list of key path strings to group results with
@result
a <tt>CSGroupBy</tt> clause with a list of key path strings
*/
CS_OBJC_OVERLOADABLE
CSGroupBy *_Nonnull GroupBy(NSArray<NSString *> *_Nonnull keyPaths);
#endif /* CoreStoreBridge_h */

View File

@@ -0,0 +1,76 @@
//
// CoreStoreBridge.m
// CoreStore
//
// Copyright © 2016 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#import "CoreStoreBridge.h"
#import <CoreStore/CoreStore-Swift.h>
CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull From(Class _Nonnull entityClass) {
return [CSFrom entityClass:entityClass];
}
CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull From(Class _Nonnull entityClass, NSArray<id> *_Nonnull configurations) {
return [CSFrom entityClass:entityClass configurations:configurations];
}
// MARK: - Where
CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(BOOL value) {
return [CSWhere value:value];
}
CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(NSString *_Nonnull format, ...) {
CSWhere *where;
va_list args;
va_start(args, format);
where = [CSWhere predicate:[NSPredicate predicateWithFormat:format arguments:args]];
va_end(args);
return where;
}
CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(NSPredicate *_Nonnull predicate) {
return [CSWhere predicate:predicate];
}
// MARK: - GroupBy
CS_OBJC_OVERLOADABLE
CSGroupBy *_Nonnull GroupBy(NSArray<NSString *> *_Nonnull keyPaths) {
return [CSGroupBy keyPaths:keyPaths];
}

View File

@@ -158,6 +158,17 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
]
}
/**
Checks if the `ListMonitor` has at least one section
- returns: `true` if at least one section exists, `false` otherwise
*/
@warn_unused_result
public func hasSections() -> Bool {
return self.sections().count > 0
}
/**
Checks if the `ListMonitor` has at least one object in any section.