Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0a38f0

Browse files
committed
Start implementation of composite attributes
1 parent 0c6f79f commit f0a38f0

16 files changed

+170
-22
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// MomCompositeAttribute+Equatable.swift
3+
//
4+
//
5+
// Created by phimage(Eric Marchand) on 10/06/2023.
6+
//
7+
8+
import Foundation
9+
10+
extension MomCompositeAttribute: Equatable {
11+
12+
public static func == (lhs: MomCompositeAttribute, rhs: MomCompositeAttribute) -> Bool {
13+
guard lhs.name == rhs.name else {
14+
return false
15+
}
16+
if lhs.elements.count != rhs.elements.count {
17+
return false
18+
}
19+
let lattributes = lhs.elements.sorted { $0.name < $1.name }
20+
let rattributes = rhs.elements.sorted { $0.name < $1.name }
21+
if lattributes != rattributes {
22+
return false
23+
}
24+
return true
25+
}
26+
27+
}

Sources/FromCoreData/NSAttributeDescription+MomXML.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extension NSAttributeDescription {
2525
}
2626
mom.isIndexedBySpotlight = self.isIndexedBySpotlight
2727
mom.valueTransformerName = self.valueTransformerName
28+
mom.customClassName = self.attributeValueClassName
2829
return mom
2930
}
3031

@@ -63,6 +64,8 @@ extension NSAttributeType {
6364
return .undefined
6465
case .objectIDAttributeType:
6566
return .objectID
67+
case .compositeAttributeType:
68+
return .composite
6669
default:
6770
if #available(iOS 11, *), #available(macOS 10.13, *) {
6871
switch self {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// NSCompositeAttributeDescription+MomXml.swift
3+
//
4+
//
5+
// Created by phimage(Eric Marchand) on 10/06/2023.
6+
//
7+
8+
import Foundation
9+
import CoreData
10+
11+
@available(iOS 17.0, *)
12+
@available(macOS 14.0, *)
13+
extension NSCompositeAttributeDescription {
14+
15+
public var momComposite: MomCompositeAttribute {
16+
var mom = MomCompositeAttribute(name: self.name)
17+
mom.elements = self.elements.compactMap({ $0 as? NSAttributeDescription}).map({ $0.mom })
18+
19+
// let momAttr = self.mom : TODO parse and set in mom composite?
20+
21+
return mom
22+
}
23+
24+
}

Sources/FromCoreData/NSManagedObjectModel+MomXML.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extension NSManagedObjectModel {
1717
mom.entities = self.entities.map { $0.mom }
1818
mom.elements = self.entities.map { $0.momElement }
1919
mom.configurations = self.configurations.map { MomConfiguration(name: $0, memberEntities: []) }
20+
// mom.composites = ??
2021

2122
for var configuration in mom.configurations {
2223
if let entities = self.entities(forConfigurationName: configuration.name) {

Sources/FromXML/MomAttribute+XMLObject.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ extension MomAttribute: XMLObject {
3030
self.maxValueString = element.attribute(by: "maxValueString")?.text
3131
self.derivationExpression = element.attribute(by: "derivationExpression")?.text
3232
self.valueTransformerName = element.attribute(by: "valueTransformerName")?.text
33+
self.customClassName = element.attribute(by: "customClassName")?.text
34+
self.composite = element.attribute(by: "composite")?.text
3335

3436
for xml in xml.children {
3537
if let object = MomUserInfo(xml: xml) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// MomCompositeAttribute+XMLObject.swift
3+
//
4+
//
5+
// Created by phimage(Eric Marchand) on 10/06/2023.
6+
//
7+
8+
import Foundation
9+
10+
extension MomCompositeAttribute: XMLObject {
11+
12+
public init?(xml: XML) {
13+
guard let element = xml.element, element.name == "composite" else {
14+
return nil
15+
}
16+
guard let name = element.attribute(by: "name")?.text else {
17+
return nil
18+
}
19+
20+
self.init(name: name)
21+
22+
for xml in xml.children {
23+
if let object = MomAttribute(xml: xml) {
24+
self.elements.append(object)
25+
} else {
26+
MomXML.orphanCallback?(xml, [MomAttribute.self, MomRelationship.self, MomUserInfo.self, MomFetchedProperty.self, MomFetchIndex.self, MomUniquenessConstraints.self])
27+
}
28+
}
29+
30+
}
31+
32+
}

Sources/FromXML/MomElement+XMLObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension MomElement: XMLObject {
1616
let width = element.attribute(by: "width")?.text.fromXMLToInt else {
1717
return nil
1818
}
19-
let height = element.attribute(by: "height")?.text.fromXMLToInt ?? 0 //optional
19+
let height = element.attribute(by: "height")?.text.fromXMLToInt ?? 0 // optional
2020
self.init(name: name, positionX: positionX, positionY: positionY, width: width, height: height)
2121
}
2222

File renamed without changes.

Sources/FromXML/MomModel+XMLObject.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ extension MomModel: XMLObject {
2020
for xmlChildren in xml.children {
2121
if let entity = MomEntity(xml: xmlChildren) {
2222
self.entities.append(entity)
23+
} else if let composite = MomCompositeAttribute(xml: xmlChildren) {
24+
self.composites.append(composite)
2325
} else if xmlChildren.element?.name == "elements" {
2426
for xmlSubChildren in xmlChildren.children {
2527
if let element = MomElement(xml: xmlSubChildren) {

Sources/Model/MomAttribute.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public struct MomAttribute {
2323
public var isDerived: Bool = false
2424
public var derivationExpression: String?
2525
public var valueTransformerName: String?
26+
public var customClassName: String?
27+
public var composite: String?
2628

2729
public var userInfo = MomUserInfo()
2830

@@ -49,6 +51,7 @@ public struct MomAttribute {
4951
case objectID = "ObjectID"
5052
case uuid = "UUID"
5153
case uri = "URI"
54+
case composite = "Composite"
5255
}
5356

5457
}

0 commit comments

Comments
 (0)