Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

io.outfoxx:swiftpoet

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io.outfoxx:swiftpoet

SwiftPoet is a Kotlin and Java API for generating .swift source files.

  • 1.6.5
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

SwiftPoet

GitHub Workflow Status Maven Central Sonatype Nexus (Snapshots) codebeat badge

SwiftPoet is a Kotlin and Java API for generating .swift source files.

Source file generation can be useful when doing things such as annotation processing or interacting with metadata files (e.g., database schemas, protocol formats). By generating code, you eliminate the need to write boilerplate while also keeping a single source of truth for the metadata.

Example

Here's a HelloWorld file:

import RxSwift


class Greeter {

  private let name: String

  init(name: String) {
    self.name = name
  }

  func greet() -> Observable<String> {
    return Observable.from("Hello \(name)")
  }

}

And this is the code to generate it with SwiftPoet:

val observableTypeName = DeclaredTypeName.typeName("RxSwift.Observable")

val testClass = TypeSpec.classBuilder("Greeter")
   .addProperty("name", STRING, Modifier.PRIVATE)
   .addFunction(
      FunctionSpec.constructorBuilder()
         .addParameter("name", STRING)
         .addCode("self.name = name\n")
         .build()
   )
   .addFunction(
      FunctionSpec.builder("greet")
         .returns(observableTypeName.parameterizedBy(STRING))
         .addCode("return %T.from(\"Hello \\(name)\")\n", observableTypeName)
         .build()
   )
   .build()

val file = FileSpec.builder("Greeter")
   .addType(testClass)
   .build()

val out = StringWriter()
file.writeTo(out)

The KDoc catalogs the complete SwiftPoet API, which is inspired by JavaPoet.

Download

Download the latest .jar or depend via Maven:

<dependency>
  <groupId>io.outfoxx</groupId>
  <artifactId>swiftpoet</artifactId>
  <version>1.6.5</version>
</dependency>

or Gradle:

implementation 'io.outfoxx:swiftpoet:1.6.5'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2017 Outfox, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

FAQs

Package last updated on 21 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc