Database Reference
In-Depth Information
self . startMeasuring ()
let sales =
employeeDetails. salesCountForEmployeeFast (employee)
self . stopMeasuring ()
})
}
This test is identical to the previous one, except it uses the new and, with any luck,
faster function.
Run this test. From Xcode's menu bar, select Product and then Test , or press U.
This will build the app and run the test. You'll see another performance
improvement!
Using relationships
The code above is fast, but the faster method still seems like a lot of work. You
have to create a fetch request, create a predicate, get a reference to the context,
execute the fetch request and get the results out.
The Employee entity has a sales property, which holds an NSSet of the sales. Open
EmployeeDetailViewController.swift and add another new method:
public func salesCountForEmployeeSimple(employee: Employee ) -> String {
return " \(employee. sales . count ) "
}
Doesn't that look better? By using the sales relationship on the Employee entity the
code is much simpler and easier to comprehend.
Update the view controller and tests to use this method instead, following the same
pattern as above. How's the performance now?
Search WWH ::




Custom Search