Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed May 10, 2024
2 parents 9bfced6 + e1d08df commit f48cedd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extension CoreData.NSAttributeDescription: SchemaProperty {
if let baseType = attributeType.swiftBaseType(isOptional: isOptional) {
return baseType
}
guard let attributeValueClassName else { return Any.self }
return NSClassFromString(attributeValueClassName) ?? Any.self
guard let attributeValueClassName else { return isOptional ? Any?.self : Any.self }
return NSClassFromString(attributeValueClassName) ?? (isOptional ? Any?.self : Any.self)
}
set {
// Note: This needs to match up w/ PersistentModel+KVC.
Expand Down
24 changes: 24 additions & 0 deletions Tests/ManagedModelTests/CodablePropertiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,28 @@ final class CodablePropertiesTests: XCTestCase {
XCTAssertNotNil(attribute.valueTransformerName)
XCTAssertEqual(attribute.valueTransformerName, transformerName.rawValue)
}

func testOptionalCodablePropertyEntity() throws {
let entity = try XCTUnwrap(
container?.managedObjectModel.entitiesByName["StoredAccess"]
)

// Creating the entity should have registered the transformer for the
// CodableBox.
let transformerName = try XCTUnwrap(
ValueTransformer.valueTransformerNames().first(where: {
$0.rawValue.range(of: "CodableTransformerGSqVOO17ManagedModelTests8")
!= nil
})
)
let transformer = try XCTUnwrap(ValueTransformer(forName: transformerName))
_ = transformer // to clear unused-wraning

let attribute = try XCTUnwrap(entity.attributesByName["optionalSip"])
XCTAssertEqual(attribute.name, "optionalSip")
XCTAssertTrue(attribute.valueType == Any?.self)
// Fixtures.CodablePropertiesSchema.AccessSIP?.self)
XCTAssertNotNil(attribute.valueTransformerName)
XCTAssertEqual(attribute.valueTransformerName, transformerName.rawValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension Fixtures {
var token : String
var expires : Date
var sip : AccessSIP
var optionalSip : AccessSIP?
}

struct AccessSIP: Codable {
Expand Down

0 comments on commit f48cedd

Please sign in to comment.