All Projects → wickwirew → Runtime

wickwirew / Runtime

Licence: mit
A Swift Runtime library for viewing type info, and the dynamic getting and setting of properties.

Programming Languages

swift
15916 projects
swift4
162 projects
reflection
70 projects

Projects that are alternatives of or similar to Runtime

Io Ts
Runtime type system for IO decoding/encoding
Stars: ✭ 5,086 (+591.03%)
Mutual labels:  runtime
Sysbox
Sysbox repository
Stars: ✭ 596 (-19.02%)
Mutual labels:  runtime
Orogene
A next-generation platform and package manager for Node.js-compatible and frontend JavaScript projects!
Stars: ✭ 695 (-5.57%)
Mutual labels:  runtime
Go Runtime Metrics
Collect Golang Runtime Metrics, outputting to a stats handler
Stars: ✭ 501 (-31.93%)
Mutual labels:  runtime
Pl Compiler Resource
程序语言与编译技术相关资料(持续更新中)
Stars: ✭ 578 (-21.47%)
Mutual labels:  runtime
Druntime
Low level runtime library for the D programming language
Stars: ✭ 608 (-17.39%)
Mutual labels:  runtime
Ph7
An Embedded Implementation of PHP (C Library)
Stars: ✭ 422 (-42.66%)
Mutual labels:  runtime
Raftlib
The RaftLib C++ library, streaming/dataflow concurrency via C++ iostream-like operators
Stars: ✭ 717 (-2.58%)
Mutual labels:  runtime
Reflection
DEPRECATED
Stars: ✭ 592 (-19.57%)
Mutual labels:  runtime
Runq
run regular Docker images in KVM/Qemu
Stars: ✭ 616 (-16.3%)
Mutual labels:  runtime
Erlangrt
Erlang Replacement Therapy. Another attempt to make Erlang runtime (BEAM emulator) in Rust. Good news: I know what to do. Bad news: I have no clue how to Rust
Stars: ✭ 531 (-27.85%)
Mutual labels:  runtime
Dart native
Write iOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.
Stars: ✭ 564 (-23.37%)
Mutual labels:  runtime
Kube Rs
kubernetes rust client and futures controller runtime
Stars: ✭ 613 (-16.71%)
Mutual labels:  runtime
Enforce
Python 3.5+ runtime type checking for integration testing and data validation
Stars: ✭ 502 (-31.79%)
Mutual labels:  runtime
Reflow
A language and runtime for distributed, incremental data processing in the cloud
Stars: ✭ 706 (-4.08%)
Mutual labels:  runtime
Vercel Php
▲ Vercel PHP runtime • vercel-php • now-php • 🐘+ λ = ❤
Stars: ✭ 429 (-41.71%)
Mutual labels:  runtime
Typescript Is
Stars: ✭ 595 (-19.16%)
Mutual labels:  runtime
Spirit
🙌 Play Spirit animations on the web
Stars: ✭ 719 (-2.31%)
Mutual labels:  runtime
Messagethrottle
A lightweight Objective-C message throttle and debounce library.
Stars: ✭ 710 (-3.53%)
Mutual labels:  runtime
Iosproject
iOS project of collected some demos for iOS App, use Objective-C
Stars: ✭ 5,357 (+627.85%)
Mutual labels:  runtime

Runtime

Build Swift 5.0 CocoaPods compatible License

Runtime is a Swift library to give you more runtime abilities, including getting type metadata, setting properties via reflection, and type construction for native swift objects.

TypeInfo

TypeInfo exposes metadata about native Swift structs, protocols, classes, tuples and enums. It captures the properties, generic types, inheritance levels, and more.

Example

Lets say you have a User struct:

struct User {
  let id: Int
  let username: String
  let email: String
}

To get the TypeInfo of User, all that you have to do is:

let info = try typeInfo(of: User.self)

Property Info

Within the TypeInfo object, it contains a list of PropertyInfo which represents all properties for the type. PropertyInfo exposes the name and type of the property. It also allows the getting and setting of a value on an object.

Example

Using the same User object as before first we get the TypeInfo and the property we want.

let info = try typeInfo(of: User.self)
let property = try info.property(named: "username")

To get a value:

let username = try property.get(from: user)

To set a value:

try property.set(value: "newUsername", on: &user)

It's that easy! 🎉

Factory

Runtime also supports building an object from it's Type. Both structs and classes are supported.

To build a User object:

let user = try createInstance(type: User.self)

Function Info

FunctionInfo exposes metadata about functions. Including number of arguments, argument types, return types, and whether it can throw an error.

Example

func doSomething(a: Int, b: Bool) throws -> String { 
  return "" 
}

let info = functionInfo(of: doSomething)

FAQ

Q: When getting and setting a value does it work typeless? (i.e. object casted as Any)

A: Yes! The whole library was designed with working typeless in mind.

Q: When creating a new instance of a class is it still protected by ARC?

A: Yes! The retain counts are set properly so ARC can do its job.

Installation

Cocoapods

Runtime is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Runtime'

Swift Package Manager

You can install Runtime via Swift Package Manager by adding the following line to your Package.swift:

import PackageDescription

let package = Package(
    [...]
    dependencies: [
        .Package(url: "https://github.com/wickwirew/Runtime.git", majorVersion: XYZ)
    ]
)

Contributions

Contributions are welcome and encouraged!

Learn

Want to know how it works? Here's an article on how it was implemented.

Want to learn about Swift memory layout? Mike Ash gave and awesome talk on just that.

License

Runtime is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].