diff --git a/AlecrimCoreData.podspec b/AlecrimCoreData.podspec index bf854df..d219a40 100644 --- a/AlecrimCoreData.podspec +++ b/AlecrimCoreData.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "AlecrimCoreData" - s.version = "5.0" + s.version = "5.1" s.summary = "A powerful and simple Core Data wrapper framework written in Swift." s.homepage = "https://github.com/Alecrim/AlecrimCoreData" diff --git a/Examples/ACD Alarm (iOS)/ACD Alarm.xcodeproj/project.pbxproj b/Examples/ACD Alarm (iOS)/ACD Alarm.xcodeproj/project.pbxproj index 84ebfd4..48bf2aa 100644 --- a/Examples/ACD Alarm (iOS)/ACD Alarm.xcodeproj/project.pbxproj +++ b/Examples/ACD Alarm (iOS)/ACD Alarm.xcodeproj/project.pbxproj @@ -160,7 +160,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = Alecrim; TargetAttributes = { 14B2B1D81D5D285A0073C1C2 = { @@ -253,7 +253,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -261,7 +263,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; @@ -304,7 +310,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -312,7 +320,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; diff --git a/README.md b/README.md index f0df088..284dc67 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![AlecrimCoreData](https://raw.githubusercontent.com/Alecrim/AlecrimCoreData/master/AlecrimCoreData.png) -[![Language: Swift](https://img.shields.io/badge/lang-Swift 3-orange.svg?style=flat)](https://developer.apple.com/swift/) +[![Language: Swift](https://img.shields.io/badge/Swift-3.2-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Platform](https://img.shields.io/cocoapods/p/AlecrimCoreData.svg?style=flat)](http://cocoadocs.org/docsets/AlecrimCoreData) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/Alecrim/AlecrimCoreData/develop/LICENSE) [![CocoaPods](https://img.shields.io/cocoapods/v/AlecrimCoreData.svg?style=flat)](http://cocoapods.org) diff --git a/Source/AlecrimCoreData.xcodeproj/project.pbxproj b/Source/AlecrimCoreData.xcodeproj/project.pbxproj index b7fb4c4..f06f6a6 100644 --- a/Source/AlecrimCoreData.xcodeproj/project.pbxproj +++ b/Source/AlecrimCoreData.xcodeproj/project.pbxproj @@ -238,7 +238,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0810; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = Alecrim; TargetAttributes = { 1447ADCB1B52B2F000ADEAED = { @@ -318,14 +318,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -357,6 +363,7 @@ SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator watchos watchsimulator appletvos appletvsimulator"; SWIFT_INSTALL_OBJC_HEADER = NO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.0; VALID_ARCHS = "x86_64 arm64 armv7 armv7s armv7k"; VERSIONING_SYSTEM = "apple-generic"; @@ -373,14 +380,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/Source/AlecrimCoreData.xcodeproj/xcshareddata/xcschemes/AlecrimCoreData.xcscheme b/Source/AlecrimCoreData.xcodeproj/xcshareddata/xcschemes/AlecrimCoreData.xcscheme index 33ca2ec..5cc2a2f 100644 --- a/Source/AlecrimCoreData.xcodeproj/xcshareddata/xcschemes/AlecrimCoreData.xcscheme +++ b/Source/AlecrimCoreData.xcodeproj/xcshareddata/xcschemes/AlecrimCoreData.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Source/AlecrimCoreData/Core/Classes/CustomPersistentContainer.swift b/Source/AlecrimCoreData/Core/Classes/CustomPersistentContainer.swift index 2afee28..aaf7bb1 100644 --- a/Source/AlecrimCoreData/Core/Classes/CustomPersistentContainer.swift +++ b/Source/AlecrimCoreData/Core/Classes/CustomPersistentContainer.swift @@ -96,7 +96,7 @@ internal class CustomPersistentContainer: NSObject, UnderlyingPersistentContaine // MARK: - - internal required init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type) { + internal required init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type, directoryURL: URL) { self.contextType = contextType self.name = name @@ -105,7 +105,7 @@ internal class CustomPersistentContainer: NSObject, UnderlyingPersistentContaine self.viewContext = self.contextType.init(concurrencyType: .mainQueueConcurrencyType) self.viewContext.persistentStoreCoordinator = self.persistentStoreCoordinator - self.alc_persistentStoreDescriptions = [CustomPersistentStoreDescription(url: type(of: self).defaultDirectoryURL().appendingPathComponent("\(name).sqlite"))] + self.alc_persistentStoreDescriptions = [CustomPersistentStoreDescription(url: directoryURL.appendingPathComponent("\(name).sqlite"))] } // MARK: - diff --git a/Source/AlecrimCoreData/Core/Classes/NativePersistentContainer.swift b/Source/AlecrimCoreData/Core/Classes/NativePersistentContainer.swift index f48c5f6..d549487 100644 --- a/Source/AlecrimCoreData/Core/Classes/NativePersistentContainer.swift +++ b/Source/AlecrimCoreData/Core/Classes/NativePersistentContainer.swift @@ -20,12 +20,12 @@ internal class NativePersistentContainer: NSPersistentContainer, UnderlyingPersi internal override var viewContext: NSManagedObjectContext { return self._viewContext } - internal required init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type) { + internal required init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type, directoryURL: URL) { self.contextType = contextType self._viewContext = self.contextType.init(concurrencyType: .mainQueueConcurrencyType) super.init(name: name, managedObjectModel: model) - + self.persistentStoreDescriptions = [NSPersistentStoreDescription(url: directoryURL.appendingPathComponent("\(name).sqlite"))] self._viewContext.persistentStoreCoordinator = self.persistentStoreCoordinator } diff --git a/Source/AlecrimCoreData/Core/Classes/PersistentContainer.swift b/Source/AlecrimCoreData/Core/Classes/PersistentContainer.swift index 29e56b0..2d97039 100644 --- a/Source/AlecrimCoreData/Core/Classes/PersistentContainer.swift +++ b/Source/AlecrimCoreData/Core/Classes/PersistentContainer.swift @@ -55,7 +55,7 @@ internal protocol UnderlyingPersistentContainer: class { func configureDefaults(for context: NSManagedObjectContext) - init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type) + init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type, directoryURL: URL) } // MARK: - @@ -64,7 +64,7 @@ open class GenericPersistentContainer { // MARK: - - open class func defaultDirectoryURL() -> URL { + open class func directoryURL() -> URL { if #available(iOS 10.0, macOSApplicationExtension 10.12, iOSApplicationExtension 10.0, tvOSApplicationExtension 10.0, watchOSApplicationExtension 3.0, *) { return NativePersistentContainer.defaultDirectoryURL() } @@ -122,12 +122,20 @@ open class GenericPersistentContainer { public init(name: String, managedObjectModel model: NSManagedObjectModel, automaticallyLoadPersistentStores: Bool) { + let directoryURL = type(of: self).directoryURL() + + do { + try FileManager.default.createDirectory(atPath: directoryURL.path, withIntermediateDirectories: true, attributes: nil) + } catch { + AlecrimCoreDataError.handleError(error) + } + // if #available(iOS 10.0, macOSApplicationExtension 10.12, iOSApplicationExtension 10.0, tvOSApplicationExtension 10.0, watchOSApplicationExtension 3.0, *) { - self.underlyingPersistentContainer = NativePersistentContainer(name: name, managedObjectModel: model, contextType: ContextType.self) + self.underlyingPersistentContainer = NativePersistentContainer(name: name, managedObjectModel: model, contextType: ContextType.self, directoryURL: directoryURL) } else { - self.underlyingPersistentContainer = CustomPersistentContainer(name: name, managedObjectModel: model, contextType: ContextType.self) + self.underlyingPersistentContainer = CustomPersistentContainer(name: name, managedObjectModel: model, contextType: ContextType.self, directoryURL: directoryURL) } // diff --git a/Source/AlecrimCoreData/Core/Extensions/NSManagedObjectExtensions.swift b/Source/AlecrimCoreData/Core/Extensions/NSManagedObjectExtensions.swift index b3eaa5c..6642d3e 100644 --- a/Source/AlecrimCoreData/Core/Extensions/NSManagedObjectExtensions.swift +++ b/Source/AlecrimCoreData/Core/Extensions/NSManagedObjectExtensions.swift @@ -22,7 +22,7 @@ extension NSManagedObject { let otherManagedObject = try otherContext.existingObject(with: self.objectID) - return unsafeBitCast(otherManagedObject, to: type(of: self)) + return unsafeDowncast(otherManagedObject, to: type(of: self)) } } diff --git a/Source/AlecrimCoreData/Core/Extensions/UICollectionViewExtensions.swift b/Source/AlecrimCoreData/Core/Extensions/UICollectionViewExtensions.swift index 7239a4e..70d4926 100644 --- a/Source/AlecrimCoreData/Core/Extensions/UICollectionViewExtensions.swift +++ b/Source/AlecrimCoreData/Core/Extensions/UICollectionViewExtensions.swift @@ -113,7 +113,12 @@ } } } - .didChangeContent { [unowned collectionView] in + .didChangeContent { [weak collectionView] in + guard let collectionView = collectionView else { + reset() + return + } + if reloadData { collectionView.reloadData() reset() diff --git a/Source/AlecrimCoreData/Core/Protocols/AttributeProtocol.swift b/Source/AlecrimCoreData/Core/Protocols/AttributeProtocol.swift index caeadef..505df2a 100644 --- a/Source/AlecrimCoreData/Core/Protocols/AttributeProtocol.swift +++ b/Source/AlecrimCoreData/Core/Protocols/AttributeProtocol.swift @@ -63,7 +63,7 @@ public protocol NullableAttributeProtocol: AttributeProtocol { extension AttributeProtocol { - public final var ___expression: NSExpression { + public var ___expression: NSExpression { return NSExpression(forKeyPath: self.___name) } @@ -73,7 +73,7 @@ extension AttributeProtocol { extension AttributeProtocol { - internal final var ___comparisonPredicateOptions: NSComparisonPredicate.Options { + internal var ___comparisonPredicateOptions: NSComparisonPredicate.Options { if Self.ValueType.self is AlecrimCoreData.StringProtocol.Type { return PersistentContainerOptions.defaultComparisonPredicateOptions } @@ -88,7 +88,7 @@ extension AttributeProtocol { extension AttributeProtocol where Self.ValueType: Equatable { - public final func isEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -98,7 +98,7 @@ extension AttributeProtocol where Self.ValueType: Equatable { ) } - public final func isEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func isEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -108,7 +108,7 @@ extension AttributeProtocol where Self.ValueType: Equatable { ) } - public final func isNotEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isNotEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -118,7 +118,7 @@ extension AttributeProtocol where Self.ValueType: Equatable { ) } - public final func isNotEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func isNotEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -132,7 +132,7 @@ extension AttributeProtocol where Self.ValueType: Equatable { extension NullableAttributeProtocol where Self.ValueType: Equatable { - public final func isEqualTo(_ value: ValueType?) -> NSComparisonPredicate { + public func isEqualTo(_ value: ValueType?) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -142,7 +142,7 @@ extension NullableAttributeProtocol where Self.ValueType: Equatable { ) } - public final func isNotEqualTo(_ value: ValueType?) -> NSComparisonPredicate { + public func isNotEqualTo(_ value: ValueType?) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -156,7 +156,7 @@ extension NullableAttributeProtocol where Self.ValueType: Equatable { extension AttributeProtocol where Self.ValueType: Comparable { - public final func isGreaterThan(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isGreaterThan(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -166,7 +166,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { ) } - public final func isGreaterThan(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func isGreaterThan(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -176,7 +176,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { ) } - public final func isGreaterThanOrEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isGreaterThanOrEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -186,7 +186,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { ) } - public final func isGreaterThanOrEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func isGreaterThanOrEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -196,7 +196,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { ) } - public final func isLessThan(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isLessThan(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -206,7 +206,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { ) } - public final func isLessThan(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func isLessThan(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -216,7 +216,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { ) } - public final func isLessThanOrEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isLessThanOrEqualTo(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -226,7 +226,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { ) } - public final func isLessThanOrEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func isLessThanOrEqualTo(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -240,7 +240,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol { - public final func isLike(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isLike(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -250,7 +250,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol ) } - public final func isIn(_ value: Self.ValueType) -> NSComparisonPredicate { + public func isIn(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -264,7 +264,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol extension AttributeProtocol { - public final func isIn(_ values: [Self.ValueType]) -> NSComparisonPredicate { + public func isIn(_ values: [Self.ValueType]) -> NSComparisonPredicate { let rightExpressionConstanteValue = values.map { toNSObject($0) } let rightExpression = NSExpression(forConstantValue: rightExpressionConstanteValue) @@ -281,7 +281,7 @@ extension AttributeProtocol { extension AttributeProtocol where Self.ValueType: Comparable { - public final func isBetween(_ range: Range) -> NSComparisonPredicate { + public func isBetween(_ range: Range) -> NSComparisonPredicate { let rightExpressionConstanteValue = [toNSObject(range.lowerBound), toNSObject(range.upperBound)] as NSArray let rightExpression = NSExpression(forConstantValue: rightExpressionConstanteValue) @@ -298,7 +298,7 @@ extension AttributeProtocol where Self.ValueType: Comparable { extension AttributeProtocol where Self.ValueType: ExpressibleByBooleanLiteral { - public final func not() -> NSComparisonPredicate { + public func not() -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: NSExpression(forConstantValue: NSNumber(value: false)), @@ -312,7 +312,7 @@ extension AttributeProtocol where Self.ValueType: ExpressibleByBooleanLiteral { extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol { - public final func contains(_ value: Self.ValueType) -> NSComparisonPredicate { + public func contains(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -322,7 +322,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol ) } - public final func contains(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func contains(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -332,7 +332,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol ) } - public final func beginsWith(_ value: Self.ValueType) -> NSComparisonPredicate { + public func beginsWith(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -342,7 +342,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol ) } - public final func beginsWith(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func beginsWith(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -352,7 +352,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol ) } - public final func endsWith(_ value: Self.ValueType) -> NSComparisonPredicate { + public func endsWith(_ value: Self.ValueType) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: expressionForValue(value), @@ -362,7 +362,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol ) } - public final func endsWith(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { + public func endsWith(_ otherAttribute: T) -> NSComparisonPredicate where T.ValueType == Self.ValueType { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: otherAttribute.___expression, @@ -376,7 +376,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol { - public final func matches(_ regularExpressionString: String) -> NSComparisonPredicate { + public func matches(_ regularExpressionString: String) -> NSComparisonPredicate { return NSComparisonPredicate( leftExpression: self.___expression, rightExpression: NSExpression(forConstantValue: regularExpressionString), @@ -392,7 +392,7 @@ extension AttributeProtocol where Self.ValueType: AlecrimCoreData.StringProtocol extension AttributeProtocol where Self.ValueType: Collection { - public final func any(_ predicateClosure: (Self.ValueType.Iterator.Element.Type) -> NSComparisonPredicate) -> NSComparisonPredicate { + public func any(_ predicateClosure: (Self.ValueType.Iterator.Element.Type) -> NSComparisonPredicate) -> NSComparisonPredicate { let p = predicateClosure(Self.ValueType.Iterator.Element.self) var leftExpression = p.leftExpression @@ -414,7 +414,7 @@ extension AttributeProtocol where Self.ValueType: Collection { ) } - public final func all(_ predicateClosure: (Self.ValueType.Iterator.Element.Type) -> NSComparisonPredicate) -> NSComparisonPredicate { + public func all(_ predicateClosure: (Self.ValueType.Iterator.Element.Type) -> NSComparisonPredicate) -> NSComparisonPredicate { let p = predicateClosure(Self.ValueType.Iterator.Element.self) var leftExpression = p.leftExpression @@ -436,7 +436,7 @@ extension AttributeProtocol where Self.ValueType: Collection { ) } - public final func none(_ predicateClosure: (Self.ValueType.Iterator.Element.Type) -> NSComparisonPredicate) -> NSPredicate { + public func none(_ predicateClosure: (Self.ValueType.Iterator.Element.Type) -> NSComparisonPredicate) -> NSPredicate { let p = predicateClosure(Self.ValueType.Iterator.Element.self) var leftExpression = p.leftExpression diff --git a/Source/AlecrimCoreData/Core/Protocols/AttributeQueryProtocol.swift b/Source/AlecrimCoreData/Core/Protocols/AttributeQueryProtocol.swift index 286bebd..1be804e 100644 --- a/Source/AlecrimCoreData/Core/Protocols/AttributeQueryProtocol.swift +++ b/Source/AlecrimCoreData/Core/Protocols/AttributeQueryProtocol.swift @@ -77,7 +77,7 @@ extension AttributeQueryProtocol where Self.Element: NSDictionary { extension AttributeQueryProtocol where Self.Element: NSDictionary { - public final func toFetchRequest() -> NSFetchRequest { + public func toFetchRequest() -> NSFetchRequest { let fetchRequest = NSFetchRequest() fetchRequest.entity = self.entityDescription diff --git a/Source/AlecrimCoreData/Core/Protocols/CoreDataQueryable.swift b/Source/AlecrimCoreData/Core/Protocols/CoreDataQueryable.swift index 3e62f1d..bea9851 100644 --- a/Source/AlecrimCoreData/Core/Protocols/CoreDataQueryable.swift +++ b/Source/AlecrimCoreData/Core/Protocols/CoreDataQueryable.swift @@ -26,7 +26,7 @@ public protocol CoreDataQueryable: GenericQueryable { extension CoreDataQueryable { - public final func count() -> Int { + public func count() -> Int { do { let c = try self.context.count(for: self.toFetchRequest() as NSFetchRequest) @@ -48,33 +48,33 @@ extension CoreDataQueryable { extension CoreDataQueryable { - public final func sum(_ closure: (Self.Element.Type) -> Attribute) -> U { + public func sum(_ closure: (Self.Element.Type) -> Attribute) -> U { let attribute = closure(Self.Element.self) return self.aggregate(withFunctionName: "sum", attribute: attribute) } - public final func min(_ closure: (Self.Element.Type) -> Attribute) -> U { + public func min(_ closure: (Self.Element.Type) -> Attribute) -> U { let attribute = closure(Self.Element.self) return self.aggregate(withFunctionName: "min", attribute: attribute) } - public final func max(_ closure: (Self.Element.Type) -> Attribute) -> U { + public func max(_ closure: (Self.Element.Type) -> Attribute) -> U { let attribute = closure(Self.Element.self) return self.aggregate(withFunctionName: "max", attribute: attribute) } // same as average, for convenience - public final func avg(_ closure: (Self.Element.Type) -> Attribute) -> U { + public func avg(_ closure: (Self.Element.Type) -> Attribute) -> U { let attribute = closure(Self.Element.self) return self.aggregate(withFunctionName: "average", attribute: attribute) } - public final func average(_ closure: (Self.Element.Type) -> Attribute) -> U { + public func average(_ closure: (Self.Element.Type) -> Attribute) -> U { let attribute = closure(Self.Element.self) return self.aggregate(withFunctionName: "average", attribute: attribute) } - private final func aggregate(withFunctionName functionName: String, attribute: Attribute) -> U { + private func aggregate(withFunctionName functionName: String, attribute: Attribute) -> U { let attributeDescription = self.entityDescription.attributesByName[attribute.___name]! let keyPathExpression = NSExpression(forKeyPath: attribute.___name) diff --git a/Source/AlecrimCoreData/Core/Protocols/Enumerable.swift b/Source/AlecrimCoreData/Core/Protocols/Enumerable.swift index b6081a1..039cf6b 100644 --- a/Source/AlecrimCoreData/Core/Protocols/Enumerable.swift +++ b/Source/AlecrimCoreData/Core/Protocols/Enumerable.swift @@ -21,14 +21,14 @@ public protocol Enumerable: Sequence { extension Enumerable { - public final func skip(_ count: Int) -> Self { + public func skip(_ count: Int) -> Self { var clone = self clone.offset = count return clone } - public final func take(_ count: Int) -> Self { + public func take(_ count: Int) -> Self { var clone = self clone.limit = count @@ -39,11 +39,11 @@ extension Enumerable { extension Enumerable { - public final func any() -> Bool { + public func any() -> Bool { return self.take(1).count() == 1 } - public final func none() -> Bool { + public func none() -> Bool { return !self.any() } diff --git a/Source/AlecrimCoreData/Core/Protocols/GenericQueryable.swift b/Source/AlecrimCoreData/Core/Protocols/GenericQueryable.swift index 3faf6c0..d744a1a 100644 --- a/Source/AlecrimCoreData/Core/Protocols/GenericQueryable.swift +++ b/Source/AlecrimCoreData/Core/Protocols/GenericQueryable.swift @@ -10,7 +10,7 @@ import Foundation public protocol GenericQueryable: Queryable { - associatedtype Element = Self.Iterator.Element + //associatedtype Element = Self.Iterator.Element func execute() -> [Self.Element] @@ -20,29 +20,29 @@ public protocol GenericQueryable: Queryable { extension GenericQueryable { - public final func orderBy(ascending: Bool = true, _ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { + public func orderBy(ascending: Bool = true, _ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { return self.sort(using: orderingClosure(Self.Element.self), ascending: ascending) } // convenience methods - public final func orderByAscending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { + public func orderByAscending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { return self.orderBy(ascending: true, orderingClosure) } - public final func orderByDescending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { + public func orderByDescending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { return self.orderBy(ascending: false, orderingClosure) } - public final func thenBy(ascending: Bool = true, _ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { + public func thenBy(ascending: Bool = true, _ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { return self.orderBy(ascending: ascending, orderingClosure) } - public final func thenByAscending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { + public func thenByAscending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { return self.orderBy(ascending: true, orderingClosure) } - public final func thenByDescending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { + public func thenByDescending(_ orderingClosure: (Self.Element.Type) -> A) -> Self where A.ValueType == V { return self.orderBy(ascending: false, orderingClosure) } @@ -52,7 +52,7 @@ extension GenericQueryable { extension GenericQueryable { - public final func filter(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Self { + public func filter(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Self { return self.filter(using: predicateClosure(Self.Element.self)) } @@ -62,7 +62,7 @@ extension GenericQueryable { extension GenericQueryable { - public final func count(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Int { + public func count(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Int { return self.filter(using: predicateClosure(Self.Element.self)).count() } @@ -70,11 +70,11 @@ extension GenericQueryable { extension GenericQueryable { - public final func any(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Bool { + public func any(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Bool { return self.filter(using: predicateClosure(Self.Element.self)).any() } - public final func none(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Bool { + public func none(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Bool { return self.filter(using: predicateClosure(Self.Element.self)).none() } @@ -82,7 +82,7 @@ extension GenericQueryable { extension GenericQueryable { - public final func first(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Self.Element? { + public func first(_ predicateClosure: (Self.Element.Type) -> NSPredicate) -> Self.Element? { return self.filter(using: predicateClosure(Self.Element.self)).first() } @@ -92,7 +92,7 @@ extension GenericQueryable { extension GenericQueryable { - public final func first() -> Self.Element? { + public func first() -> Self.Element? { return self.take(1).execute().first } @@ -102,7 +102,7 @@ extension GenericQueryable { extension GenericQueryable { - public final func makeIterator() -> AnyIterator { + public func makeIterator() -> AnyIterator { return AnyIterator(self.execute().makeIterator()) } diff --git a/Source/AlecrimCoreData/Core/Protocols/Queryable.swift b/Source/AlecrimCoreData/Core/Protocols/Queryable.swift index 8ad7c3a..b11097b 100644 --- a/Source/AlecrimCoreData/Core/Protocols/Queryable.swift +++ b/Source/AlecrimCoreData/Core/Protocols/Queryable.swift @@ -20,11 +20,11 @@ public protocol Queryable: Enumerable { extension Queryable { - public final func sort(using attribute: A, ascending: Bool = true) -> Self { + public func sort(using attribute: A, ascending: Bool = true) -> Self { return self.sort(usingAttributeName: attribute.___name, ascending: ascending, options: attribute.___comparisonPredicateOptions) } - public final func sort(usingAttributeName attributeName: String, ascending: Bool = true, options: NSComparisonPredicate.Options = PersistentContainerOptions.defaultComparisonPredicateOptions) -> Self { + public func sort(usingAttributeName attributeName: String, ascending: Bool = true, options: NSComparisonPredicate.Options = PersistentContainerOptions.defaultComparisonPredicateOptions) -> Self { let sortDescriptor: NSSortDescriptor if options.contains(.caseInsensitive) && options.contains(.diacriticInsensitive) { @@ -43,7 +43,7 @@ extension Queryable { return self.sort(using: sortDescriptor) } - public final func sort(using sortDescriptor: NSSortDescriptor) -> Self { + public func sort(using sortDescriptor: NSSortDescriptor) -> Self { var clone = self if clone.sortDescriptors != nil { @@ -56,7 +56,7 @@ extension Queryable { return clone } - public final func sort(using sortDescriptors: [NSSortDescriptor]) -> Self { + public func sort(using sortDescriptors: [NSSortDescriptor]) -> Self { var clone = self if clone.sortDescriptors != nil { @@ -75,7 +75,7 @@ extension Queryable { extension Queryable { - public final func filter(using predicate: NSPredicate) -> Self { + public func filter(using predicate: NSPredicate) -> Self { var clone = self if let existingPredicate = clone.predicate { diff --git a/Source/AlecrimCoreData/Core/Protocols/TableProtocol.swift b/Source/AlecrimCoreData/Core/Protocols/TableProtocol.swift index b35a6f6..18751c5 100644 --- a/Source/AlecrimCoreData/Core/Protocols/TableProtocol.swift +++ b/Source/AlecrimCoreData/Core/Protocols/TableProtocol.swift @@ -17,15 +17,15 @@ public protocol TableProtocol: CoreDataQueryable { extension TableProtocol where Self.Element: NSManagedObject { - public final func create() -> Self.Element { + public func create() -> Self.Element { return Self.Element(entity: self.entityDescription, insertInto: self.context) } - public final func delete(_ entity: Self.Element) { + public func delete(_ entity: Self.Element) { self.context.delete(entity) } - public final func refresh(_ entity: Self.Element, mergeChanges: Bool = true) { + public func refresh(_ entity: Self.Element, mergeChanges: Bool = true) { self.context.refresh(entity, mergeChanges: mergeChanges) } @@ -33,7 +33,7 @@ extension TableProtocol where Self.Element: NSManagedObject { extension TableProtocol { - public final func deleteAll() { + public func deleteAll() { do { let fetchRequest = self.toFetchRequest() as NSFetchRequest fetchRequest.resultType = .managedObjectIDResultType @@ -54,7 +54,7 @@ extension TableProtocol { extension TableProtocol where Self.Element: NSManagedObject { - public final func firstOrCreated(_ predicateClosure: (Self.Element.Type) -> NSComparisonPredicate) -> Self.Element { + public func firstOrCreated(_ predicateClosure: (Self.Element.Type) -> NSComparisonPredicate) -> Self.Element { let predicate = predicateClosure(Self.Element.self) if let entity = self.filter(using: predicate).first() { @@ -79,7 +79,7 @@ extension TableProtocol where Self.Element: NSManagedObject { extension TableProtocol { - public final func execute() -> [Self.Element] { + public func execute() -> [Self.Element] { do { return try self.context.fetch(self.toFetchRequest() as NSFetchRequest) } @@ -94,7 +94,7 @@ extension TableProtocol { extension TableProtocol { - public final func toFetchRequest() -> NSFetchRequest { + public func toFetchRequest() -> NSFetchRequest { let fetchRequest = NSFetchRequest() fetchRequest.entity = self.entityDescription