Skip to content

Commit a770de5

Browse files
committed
Consider default parameters in generated functions
When appropriate, e.g. for fetchRequest, but not for `entity()` (which maps to a specific ObjC selector).
1 parent aa075cc commit a770de5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/ManagedModelMacros/ModelMacro/ModelMembers.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ extension ModelMacro: MemberMacro { // @attached(member, names:...)
5050
)
5151

5252
if classDecl.findFunctionWithName("fetchRequest", isStaticOrClass: true,
53-
parameterCount: 0) == nil
53+
numberOfParametersWithoutDefaults: 0)
54+
== nil
5455
{
5556
let modelClassName = modelClassName.text
5657
newMembers.append(

Sources/ManagedModelMacros/Utilities/ClassDeclSyntax+Extras.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ extension ClassDeclSyntax {
3535
extension ClassDeclSyntax {
3636

3737
func findFunctionWithName(_ name: String, isStaticOrClass: Bool,
38-
parameterCount: Int? = nil)
38+
parameterCount: Int? = nil,
39+
numberOfParametersWithoutDefaults: Int? = nil)
3940
-> FunctionDeclSyntax?
4041
{
4142
for member : MemberBlockItemSyntax in memberBlock.members {
@@ -48,6 +49,10 @@ extension ClassDeclSyntax {
4849
if let parameterCount {
4950
guard parameterCount == funcDecl.parameterCount else { continue }
5051
}
52+
if let numberOfParametersWithoutDefaults {
53+
guard numberOfParametersWithoutDefaults ==
54+
funcDecl.numberOfParametersWithoutDefaults else { continue }
55+
}
5156

5257
// filter out operators and different names
5358
guard case .identifier(let idName) = funcDecl.name.tokenKind,

0 commit comments

Comments
 (0)