Skip to content

Commit 6abe19f

Browse files
committed
[QuerySet] Improve documentation
1 parent 112b26d commit 6abe19f

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

QueryKit/Attribute.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public class Attribute<T> : Equatable {
2020
self.init(".".join(attributes))
2121
}
2222

23-
// Sorting
24-
2523
public var expression:NSExpression {
2624
return NSExpression(forKeyPath: name)
2725
}
2826

27+
// MARK: Sorting
28+
2929
public func ascending() -> NSSortDescriptor {
3030
return NSSortDescriptor(key: name, ascending: true)
3131
}
@@ -63,7 +63,7 @@ public func <= <T>(left: Attribute<T>, right: AnyObject) -> NSPredicate {
6363
return left.expression <= NSExpression(forConstantValue: right as NSObject)
6464
}
6565

66-
// Bool Attributes
66+
/// MARK: Bool Attributes
6767

6868
prefix public func ! (left: Attribute<Bool>) -> NSPredicate {
6969
return left == false
@@ -79,7 +79,7 @@ public extension QuerySet {
7979
}
8080
}
8181

82-
// Collections
82+
// MARK: Collections
8383

8484
public func count(attribute:Attribute<NSSet>) -> Attribute<Int> {
8585
return Attribute<Int>(attributes: [attribute.name, "@count"])

QueryKit/QuerySet.swift

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ import Foundation
1010
import CoreData
1111

1212

13+
/// Represents a lazy database lookup for a set of objects.
1314
public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
15+
/// Returns the managed object context that will be used to execute any requests.
1416
public let context:NSManagedObjectContext
17+
18+
/// Returns the name of the entity the request is configured to fetch.
1519
public let entityName:String
1620

21+
/// Returns the sort descriptors of the receiver.
1722
public let sortDescriptors = [NSSortDescriptor]()
23+
24+
/// Returns the predicate of the receiver.
1825
public let predicate:NSPredicate?
26+
1927
public let range:Range<Int>?
2028

21-
// Initialization
29+
// MARK: Initialization
2230

2331
public init(_ context:NSManagedObjectContext, _ entityName:String) {
2432
self.context = context
@@ -37,18 +45,21 @@ public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
3745
self.range = range
3846
}
3947

40-
// Sorting
48+
// MARK: Sorting
4149

50+
/// Returns a new QuerySet containing objects ordered by the given sort descriptor.
4251
public func orderBy(sortDescriptor:NSSortDescriptor) -> QuerySet<T> {
4352
return orderBy([sortDescriptor])
4453
}
4554

55+
/// Returns a new QuerySet containing objects ordered by the given sort descriptors.
4656
public func orderBy(sortDescriptors:[NSSortDescriptor]) -> QuerySet<T> {
4757
return QuerySet(queryset:self, sortDescriptors:sortDescriptors, predicate:predicate, range:range)
4858
}
4959

50-
// Filtering
60+
// MARK: Filtering
5161

62+
/// Returns a new QuerySet containing objects that match the given predicate.
5263
public func filter(predicate:NSPredicate) -> QuerySet<T> {
5364
var futurePredicate = predicate
5465

@@ -59,22 +70,25 @@ public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
5970
return QuerySet(queryset:self, sortDescriptors:sortDescriptors, predicate:futurePredicate, range:range)
6071
}
6172

73+
/// Returns a new QuerySet containing objects that match the given predicates.
6274
public func filter(predicates:[NSPredicate]) -> QuerySet<T> {
6375
let newPredicate = NSCompoundPredicate(type: NSCompoundPredicateType.AndPredicateType, subpredicates: predicates)
6476
return filter(newPredicate)
6577
}
6678

79+
/// Returns a new QuerySet containing objects that exclude the given predicate.
6780
public func exclude(predicate:NSPredicate) -> QuerySet<T> {
6881
let excludePredicate = NSCompoundPredicate(type: NSCompoundPredicateType.NotPredicateType, subpredicates: [predicate])
6982
return filter(excludePredicate)
7083
}
7184

85+
/// Returns a new QuerySet containing objects that exclude the given predicates.
7286
public func exclude(predicates:[NSPredicate]) -> QuerySet<T> {
7387
let excludePredicate = NSCompoundPredicate(type: NSCompoundPredicateType.AndPredicateType, subpredicates: predicates)
7488
return exclude(excludePredicate)
7589
}
7690

77-
// Subscripting
91+
// MARK: Subscripting
7892

7993
public subscript(index: Int) -> (object:T?, error:NSError?) {
8094
get {
@@ -89,6 +103,7 @@ public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
89103
}
90104
}
91105

106+
/// Returns the object at the specified index.
92107
public subscript(index: Int) -> T? {
93108
get {
94109
return self[index].object
@@ -107,7 +122,7 @@ public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
107122
}
108123
}
109124

110-
// Conversion
125+
// MARK: Conversion
111126

112127
public var fetchRequest:NSFetchRequest {
113128
var request = NSFetchRequest(entityName:entityName)
@@ -132,7 +147,7 @@ public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
132147
return array().objects
133148
}
134149

135-
// Count
150+
// MARK: Count
136151

137152
public func count() -> (count:Int?, error:NSError?) {
138153
var error:NSError?
@@ -145,12 +160,14 @@ public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
145160
return (count:count, error:error)
146161
}
147162

163+
/// Returns the count of objects matching the QuerySet.
148164
public func count() -> Int? {
149165
return count().count
150166
}
151167

152-
// Deletion
168+
// MARK: Deletion
153169

170+
/// Deletes all the objects matching the QuerySet.
154171
public func delete() -> (count:Int, error:NSError?) {
155172
var result = array() as (objects:([T]?), error:NSError?)
156173
var deletedCount = 0
@@ -166,7 +183,7 @@ public class QuerySet<T : NSManagedObject> : SequenceType, Equatable {
166183
return (count:deletedCount, error:result.error)
167184
}
168185

169-
// Sequence
186+
// MARK: Sequence
170187

171188
public func generate() -> IndexingGenerator<Array<T>> {
172189
var result = self.array() as (objects:([T]?), error:NSError?)

0 commit comments

Comments
 (0)