Giter Club home page Giter Club logo

swift-reflection-mirror's Introduction

ReflectionMirror - Swift Stdlib copypasta

Swift's powerful runtime reflection mechanism is gated under a System Programming Interface. To access it, you must add @_spi(Reflection) before a statement that imports the Swift Standard Library. This programming interface is removed from release toolchains, leaving developers with no choice but to use development toolchains for certain projects. Until now.

This package serves a purpose similar to philipturner/differentiation, in that it exposes a private API to the developer on release toolchains. Do not expect Apple to let any Xcode project depending on this package onto the iOS App Store. The purpose of bringing this feature to release toolchains isn't to build iOS apps, but to make it more accessible in situations where a development toolchain cannot be used. For example, iPad Swift Playgrounds.

How to use

This package copies reimplements the contents of ReflectionMirror.swift in the Swift Standard Library. It even gates the API-public functions under an SPI, although this one can be used on release toolchains. To use this library, replace all instances of the following:

@_spi(Reflection) import Swift

With an import of ReflectionMirror. This Swift module re-exports the Swift Standard Library, so you do not need a second import statement for import Swift.

@_spi(Reflection) import ReflectionMirror

You cannot SPI-import both Swift and ReflectionMirror at the same time on development toolchains, because that will cause a name collision with the following two functions. That is not an issue, because ReflectionMirror.swift contains the entire Reflection SPI of the Swift Standard Library (at least for now). This package also contains all of the SPI symbols because it reimplements that file. In other words, follow the instructions above and you'll be fine.

func _forEachField(
  of type: Any.Type,
  options: _EachFieldOptions = [],
  body: (UnsafePointer<CChar>, Int, Any.Type, _MetadataKind) -> Bool
) -> Bool

func _forEachFieldWithKeyPath<Root>(
  of type: Root.Type,
  options: _EachFieldOptions = [],
  body: (UnsafePointer<CChar>, PartialKeyPath<Root>) -> Bool
) -> Bool

Source code borrowed from apple/swift

Source code borrowed from s4tf/s4tf

swift-reflection-mirror's People

Contributors

philipturner avatar sukhrobkhakimov avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.