{"id":26275696,"url":"https://github.com/hainayanda/dummyable","last_synced_at":"2026-06-23T08:31:51.945Z","repository":{"id":280165718,"uuid":"939355959","full_name":"hainayanda/Dummyable","owner":"hainayanda","description":"Dummyable is a lightweight utility for easily generating dummy instances of Swift types for testing and prototyping.","archived":false,"fork":false,"pushed_at":"2025-09-27T01:52:10.000Z","size":137,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-15T19:18:17.703Z","etag":null,"topics":["dummy","macro","macros","mock","swift","swiftmacro","swiftmacros","testdouble","testdoubles","testing","unit-testing","unittest"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hainayanda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-26T12:10:49.000Z","updated_at":"2025-09-27T00:32:36.000Z","dependencies_parsed_at":"2025-03-01T17:51:56.000Z","dependency_job_id":"33e83b53-0089-4461-a297-a8ffa2af3b21","html_url":"https://github.com/hainayanda/Dummyable","commit_stats":null,"previous_names":["hainayanda/dummyable"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/hainayanda/Dummyable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hainayanda%2FDummyable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hainayanda%2FDummyable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hainayanda%2FDummyable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hainayanda%2FDummyable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hainayanda","download_url":"https://codeload.github.com/hainayanda/Dummyable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hainayanda%2FDummyable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34682622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dummy","macro","macros","mock","swift","swiftmacro","swiftmacros","testdouble","testdoubles","testing","unit-testing","unittest"],"created_at":"2025-03-14T10:17:37.422Z","updated_at":"2026-06-23T08:31:51.934Z","avatar_url":"https://github.com/hainayanda.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dummyable\n\n`Dummyable` is a lightweight utility for easily generating dummy instances of Swift types for testing and prototyping.\n\n![GitHub Release](https://img.shields.io/github/v/release/hainayanda/Dummyable)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/dcaa4fc883d94d6bb73abaf8a8fa5edc)](https://app.codacy.com/gh/hainayanda/Dummyable/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![Unit Test](https://github.com/hainayanda/Dummyable/actions/workflows/test.yml/badge.svg)](https://github.com/hainayanda/Dummyable/actions/workflows/test.yml)\n[![SwiftPM Compatible](https://img.shields.io/badge/SwiftPM-Compatible-brightgreen)](https://swift.org/package-manager/)\n\n## Requirements\n\n- Swift 5.9 or higher\n- iOS 15.0 or higher\n- macOS 12.0 or higher\n- tvOS 15.0 or higher\n- watchOS 8.0 or higher\n- visionOS 1.0 or higher\n- Xcode 15 or higher\n\n## Installation\n\n### Swift Package Manager (Xcode)\n\nTo install using Xcode's Swift Package Manager, follow these steps:\n\n- Go to **File \u003e Swift Package \u003e Add Package Dependency**\n- Enter the URL: **\u003chttps://github.com/hainayanda/Dummyable.git\u003e**\n- Choose **Up to Next Major** for the version rule and set the version to **1.1.6**.\n- Click \"Next\" and wait for the package to be fetched.\n\n### Swift Package Manager (Package.swift)\n\nIf you prefer using Package.swift, add Dummyable as a dependency in your **Package.swift** file:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/hainayanda/Dummyable.git\", .upToNextMajor(from: \"1.1.6\"))\n]\n```\n\nThen, include it in your target:\n\n```swift\n .target(\n    name: \"MyModule\",\n    dependencies: [\"Dummyable\"]\n)\n```\n\n## Usage\n\n### Creating Dummy Instance\n\nDummyable provides an easy way to create dummy instances of basic types:\n\n```swift\nlet intDummy = dummy(of: Int.self)\nlet intDummies = dummy(of: [Int].self, count: 10)\n```\n\nIf your type is marked with `@Dummyable` or has an associated `#Dummy` macro declaration, you can create a dummy instance by calling the `dummy(of:)` global function:\n\n```swift\nlet someDummy = dummy(of: SomeMarkedWithDummyable.self)\n```\n\n### Enabling Dummy Creation on Protocol\n\n`Dummyable` allows you to create dummy instances from a protocol by marking it with `@Dummyable`:\n\n```swift\n@Dummyable(.struct)\nprotocol SomeModelProtocol { \n    var title: String { get }\n    var description: String { get set }\n    // SomeType must be marked with @Dummyable, have #Dummy macro declaration, or provided by a `dummy(of:)` global function\n    var someType: SomeType { get }\n    init(title: String, description: String)\n    func doSomething()\n}\n```\n\nIf you want to create a class instance, you can do one of the following methods:\n\n```swift\n// Tell Dummyable to implement the protocol to a dummy class\n@Dummyable(.class)\nprotocol SomeModelProtocol { }\n\n// Tell Dummyable the protocol is an object\n@Dummyable\nprotocol SomeObjectProtocol: AnyObject { }\n\n// Tell Dummyable the protocol is a class instance\n@Dummyable\nprotocol SomeClassProtocol: class { }\n```\n\nKeep in mind that the `@Dummyable` macro will not work well on protocols with an associated type or an inheritance clause.\n\n\n### Enabling Dummy on a Struct\n\n`Dummyable` also allows you to create dummy instances from a struct by marking it with `@Dummyable`:\n\n```swift\n@Dummyable\nstruct SomeModel { \n    let title: String\n    var description: String\n        \n    // SomeType must be marked with @Dummyable, have #Dummy macro declaration, or provided by a `dummy(of:)` global function\n    let someType: SomeType\n    \n    func doSomething() { \n        // Do something\n    }\n}\n```\n\nIf you prefer the dummy to be created using some custom initializer, you can mark it with `@DummyableInit`:\n\n```swift\n@Dummyable\nstruct SomeModel { \n    let title: String\n    var description: String\n        \n    // SomeType must be marked with @Dummyable, have #Dummy macro declaration, or provided by a `dummy(of:)` global function\n    let someType: SomeType\n    \n    @DummyableInit\n    init(title: String, description: String = \"\", someType: SomeType) {\n        self.title = title\n        self.description = description\n    }\n    \n    func doSomething() { \n        // Do something\n    }\n}\n```\n\nThen it will create a dummy instance using marked init by only providing the parameter that has no default value.\n\nThe macro will still work on the struct with generic parameters as long as the mandatory type can be created using the `dummy(of:)` global function.\n\n### Enabling Dummy on a Class\n\n`Dummyable` also allows you to create dummy instances from a class by marking it with `@Dummyable`. But since a class might have a superclass, `@DummyableInit` to make it work:\n\n```swift\n@Dummyable\nclass SomeModel { \n    let title: String\n    var description: String\n    \n    let someType: SomeType\n    \n    @DummyableInit\n    init(title: String, description: String, someType: SomeType) {\n        self.title = title\n        self.description = description\n    }\n    // SomeType must be marked with @Dummyable, have #Dummy macro declaration, or provided by a `dummy(of:)` global function\n}\n```\n\nThe macro will still work on class with a generic parameter as long as the mandatory type can be created using the `dummy(of:)` global function.\n\n### Enabling Dummy on an Enum\n\n`Dummyable` also allows you to create dummy instances from an enum by marking it with `@Dummyable`:\n\n```swift\n@Dummyable\nenum SomeEnum {\n    case one\n    case two\n    case three\n}\n```\n\nIt will try to create an instance using the last case, and the one with the least associated value.\n\nIf you want to make sure the dummy instance is created with a specific case, you can mark the enum with `@DummyableCase`:\n\n```swift\n@Dummyable\nenum SomeEnum {\n    @DummyableCase case one\n    case two\n    case three\n}\n```\n\nThe macro will still work on an enum with a generic parameter as long as the mandatory type can be created using the `dummy(of:)` global function.\n\n### Dummy with no Declaration\n\nIf you want to enable dummy creation on a type that you don't have access to the declaration, you can use the `#Dummy` macro:\n\n```swift\n#Dummy(SomeType.self) { \n    SomeType()\n}\n```\n\nThis will be helpful if you have a dependency that you want to mock but don't have access to the declaration. You can also use this to create a dummy instance of Closure, Tuple, or some other type that is not a class, struct, or enum:\n\n```swift\n#Dummy((() -\u003e (Int, String)).self) {\n    { (1, \"Hello\") }\n}\n```\n\nBy default, the global `dummy(of:)` function will have no modifier and act as an internal function. To make it `public` or `fileprivate`, use the `#PublicDummy` or `#PrivateDummy` macro:\n\n```swift\n// Or #PrivateDummy for fileprivate global function\n#PublicDummy(SomeType.self) { \n    SomeType()\n}\n```\n\nIf your type has a generic parameter, you can provide the generic parameter using the `Generic` type as well:\n\n```swift\n#Dummy(TypeWithGeneric\u003cGeneric\u003e.self) {\n    TypeWithGeneric()\n}\n```\n\n\n`Generic` is a real type that implements `Hashable`, `Equatable`, `Identifiable`, `Sendable`, `Error`, and `Codable`. You can implement more if you need to. But in case you can't, you can use any generic parameter and tell the `#Dummy` macro to treat it as a generic parameter:\n\n```swift\n// Tell #Dummy to treat the generic parameter at 0 as generic\n#Dummy(TypeWithGeneric\u003cString\u003e.self, .isGeneric(0)) {\n    TypeWithGeneric()\n}\n```\n\nIf you want to add a where clause to the generic parameter, you can do so by providing the where clause:\n\n```swift\n#Dummy(TypeWithGeneric\u003cString\u003e.self, .where(0, conform: SomeProtocol.self, (any Equatable).self)) {\n    TypeWithGeneric()\n}\n```\n\nIf the Type is only available in a specific platform, you can provide the platform:\n\n```swift\n#Dummy(TypeWithGeneric\u003cString\u003e.self, .availble(.iOS(15.0))) {\n    TypeWithGeneric()\n}\n```\n\n### How Dummyable Works\n\n`Dummyable` works by assuming that the mandatory type needed can be created using the `dummy(of:)` global function:\n\n```swift\n// On the generated code\nself.title = dummy(of: String.self)\n```\n\nSo it will throw a compile-time error if the type can't be created using the `dummy(of:)` global function:\n\n```swift\n// On the generated code\nself.someType = dummy(of: SomeType.self) // Default argument value of type 'Any' cannot be converted to type 'SomeType'\n```\n\nTo fix this, you need to mark the type with `@Dummyable` or provide a `#Dummy` macro declaration. Or at least manually create a global `dummy(of:)` function that returns the type:\n\n```swift\nfunc dummy(of type: SomeType.Type) -\u003e SomeType {\n    SomeType()\n}\n```\n\nBut doing it manually will not provide you with `dummy(of:count:)` and some other global function that uses the type that is generated by the `@Dummyable` or `#Dummy` macro.\n\n## Contributing\n\nContributions are welcome! Please follow the guidelines in the [CONTRIBUTING.md](CONTRIBUTING.md) file.\n\n## License\n\nDummyable is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\n\n## Credits\n\nThis project is maintained by [Nayanda Haberty](hainayanda@outlook.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhainayanda%2Fdummyable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhainayanda%2Fdummyable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhainayanda%2Fdummyable/lists"}