sort categories by level
This commit is contained in:
parent
105573b8a1
commit
818dcd0d4a
2 changed files with 18 additions and 11 deletions
|
|
@ -123,10 +123,14 @@ class PasswordStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updatePasswordEntityCoreData() {
|
func updatePasswordEntityCoreData() {
|
||||||
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
let passwordCategoryEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordCategoryEntity")
|
||||||
|
let passwordEntityDeleteRequest = NSBatchDeleteRequest(fetchRequest: passwordEntityFetchRequest)
|
||||||
|
let passwordCategoryEntityDeleteRequest = NSBatchDeleteRequest(fetchRequest: passwordCategoryEntityFetchRequest)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try context.execute(deleteRequest)
|
try context.execute(passwordEntityDeleteRequest)
|
||||||
|
try context.execute(passwordCategoryEntityDeleteRequest)
|
||||||
} catch let error as NSError {
|
} catch let error as NSError {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
|
|
@ -143,6 +147,7 @@ class PasswordStore {
|
||||||
for i in 0 ..< items.count - 1 {
|
for i in 0 ..< items.count - 1 {
|
||||||
let passwordCategoryEntity = PasswordCategoryEntity(context: context)
|
let passwordCategoryEntity = PasswordCategoryEntity(context: context)
|
||||||
passwordCategoryEntity.category = items[i]
|
passwordCategoryEntity.category = items[i]
|
||||||
|
passwordCategoryEntity.level = Int16(i)
|
||||||
passwordCategoryEntity.password = passwordEntity
|
passwordCategoryEntity.password = passwordEntity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -168,10 +173,11 @@ class PasswordStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchPasswordCategoryEntityCoreData(password: PasswordEntity) -> [PasswordCategoryEntity] {
|
func fetchPasswordCategoryEntityCoreData(password: PasswordEntity) -> [PasswordCategoryEntity] {
|
||||||
let passwordCategoryEntityFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordCategoryEntity")
|
let passwordCategoryEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordCategoryEntity")
|
||||||
passwordCategoryEntityFetch.predicate = NSPredicate(format: "password = %@", password)
|
passwordCategoryEntityFetchRequest.predicate = NSPredicate(format: "password = %@", password)
|
||||||
|
passwordCategoryEntityFetchRequest.sortDescriptors = [NSSortDescriptor(key: "level", ascending: true)]
|
||||||
do {
|
do {
|
||||||
let passwordCategoryEntities = try context.fetch(passwordCategoryEntityFetch) as! [PasswordCategoryEntity]
|
let passwordCategoryEntities = try context.fetch(passwordCategoryEntityFetchRequest) as! [PasswordCategoryEntity]
|
||||||
return passwordCategoryEntities
|
return passwordCategoryEntities
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("Failed to fetch employees: \(error)")
|
fatalError("Failed to fetch employees: \(error)")
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="11759" systemVersion="16D32" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="11759" systemVersion="16D32" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||||
<entity name="PasswordCategoryEntity" representedClassName="PasswordCategoryEntity" syncable="YES" codeGenerationType="class">
|
<entity name="PasswordCategoryEntity" representedClassName="PasswordCategoryEntity" syncable="YES" codeGenerationType="class">
|
||||||
<attribute name="category" optional="YES" attributeType="String" syncable="YES"/>
|
<attribute name="category" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="level" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" indexed="YES" syncable="YES"/>
|
||||||
<relationship name="password" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PasswordEntity" inverseName="categories" inverseEntity="PasswordEntity" syncable="YES"/>
|
<relationship name="password" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PasswordEntity" inverseName="categories" inverseEntity="PasswordEntity" syncable="YES"/>
|
||||||
</entity>
|
</entity>
|
||||||
<entity name="PasswordEntity" representedClassName="PasswordEntity" syncable="YES" codeGenerationType="class">
|
<entity name="PasswordEntity" representedClassName="PasswordEntity" syncable="YES" codeGenerationType="class">
|
||||||
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
|
<attribute name="name" attributeType="String" syncable="YES"/>
|
||||||
<attribute name="raw" optional="YES" attributeType="Binary" syncable="YES"/>
|
<attribute name="raw" optional="YES" attributeType="Binary" syncable="YES"/>
|
||||||
<attribute name="rawPath" optional="YES" attributeType="String" syncable="YES"/>
|
<attribute name="rawPath" attributeType="String" syncable="YES"/>
|
||||||
<relationship name="categories" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PasswordCategoryEntity" inverseName="password" inverseEntity="PasswordCategoryEntity" syncable="YES"/>
|
<relationship name="categories" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PasswordCategoryEntity" inverseName="password" inverseEntity="PasswordCategoryEntity" syncable="YES"/>
|
||||||
</entity>
|
</entity>
|
||||||
<elements>
|
<elements>
|
||||||
<element name="PasswordEntity" positionX="-63" positionY="-18" width="128" height="103"/>
|
<element name="PasswordCategoryEntity" positionX="115" positionY="-9" width="128" height="90"/>
|
||||||
<element name="PasswordCategoryEntity" positionX="115" positionY="-9" width="128" height="73"/>
|
<element name="PasswordEntity" positionX="-63" positionY="-18" width="128" height="105"/>
|
||||||
</elements>
|
</elements>
|
||||||
</model>
|
</model>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue