Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error in generated swift file when protocol have init method. How to use init in protocol? #126

Closed
1 task done
mahabaleshwarhnr opened this issue Aug 4, 2022 · 2 comments · Fixed by #127
Labels
question Further information is requested

Comments

@mahabaleshwarhnr
Copy link

mahabaleshwarhnr commented Aug 4, 2022

I have init method in my protocol. I am getting the below error when sourcery generates the code.
Keyword 'init' cannot be used as an identifier here. If this name is unavoidable, use backticks to escape it

📝 For Example

// sourcery: AutoMockable
protocol DashboardRepository: AnyObject {
    func fetchDashBoard() -> [DashboardItem]
    func updateNotification()
    init(apiclient: APIClient)
}

Sourcery generated the code as below:

public func init(apiclient: APIClient) -> DashboardRepository {
    mocked(apiclient)
  }
.......

📝 What is the Question?

How to generate the mock when protocol have init method?

@mahabaleshwarhnr mahabaleshwarhnr added the question Further information is requested label Aug 4, 2022
@mahabaleshwarhnr
Copy link
Author

@leoture can you please help here.

@leoture
Copy link
Owner

leoture commented Aug 30, 2022

Hello @mahabaleshwarhnr !
init cannot be declared in an extension Mock ... { ... }. #127 will fix that.
You should create an extension by yourself as bellow:

extension  DashboardRepository {
  init(apiclient: APIClient) {
    ...
  }
}

@leoture leoture closed this as completed Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants