Swiftpack.co - Package - TofPlay/TProperties


Xcode Swift Version SwiftPM Carthage Plaform

WARNING: Since Swift 4.1 Apple changed how they managed metadata. Since Swift 4.1 TProperties generate a crash at runtime


  • [x] list all properties of an object
  • [x] know type of each property
  • [x] get value of a property with it's key string
  • [x] set value of a property with it's key string


  • macOS 10.12+
  • iOS 10.3+
  • watchOS 10.3+
  • tvOS 10.2+
  • Swift 4.0
  • Xcode 9.0



TProperties is available for installation using the Swift Package Manager. Add the following to your Package.swift:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "YourApp",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/TofPlay/TProperties.git", .branch("master")),
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
            name: "YourApp",
            dependencies: ["TProperties"]),


Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/TProperties.framework to an macOS, iOS, watchOS or tvOS project.

github "TofPlay/TProperties"

Usage example

import TProperties

class Base  {
  var intVal:Int = 0
  var floatVal:Float = 0.0
  var doubleVal:Double = 0.0
  var date:Date = Date()

class Class: Base {
  var string1: String = ""
  var string2: String = ""
  public init(string1 pString1:String, string2 pString2:String) {
    self.string1 = pString1
    self.string2 = pString2

let lObj = Class(string1: "Brad", string2: "Hilton")
var lProperties = TProperties(lObj)
let lKeys = lProperties.keys
let lTypes = lProperties.types
let lValues = lProperties.values
let lRaws = lProperties.raws
for lI in 0..<lRaws.count {
  print("lRaws[\(lI)] is a '\(type(of:lRaws[lI]!))'")
for lI in 0..<lKeys.count {
  var lValue = lValues[lI].string()
  if lValues[lI].isType(String.self) {
    lValue = "\"\(lValue)\""
  print("property[\"\(lKeys[lI])\"] = \(lTypes[lI]):\(lValue)")


if let lString2 = lProperties["string2"] {
  var lValue:String = lString2.value() ?? ""
  print("string2 original value: [\(lValue)]")
  lString2.value(100)     // Invalid type. Ignored.
  lValue = lString2.value() ?? ""
  print("string2 after modification: [\(lValue)]")


lRaws[0] is a 'Int'
lRaws[1] is a 'Float'
lRaws[2] is a 'Double'
lRaws[3] is a 'Date'
lRaws[4] is a 'String'
lRaws[5] is a 'String'
property["intVal"] = Int:0
property["floatVal"] = Float:0.0
property["doubleVal"] = Double:0.0
property["date"] = Date:2017-08-13 11:04:05 +0000
property["string1"] = String:"Brad"
property["string2"] = String:"Hilton"

string2 original value: [Hilton]
string2 after modification: [Pitt]

Created with XcodeTool

Component create with XcodeTool and the template ComponentCrossPlatform

Base on Swift Cross Platform Framework tutorial


Stars: 2
Help us keep the lights on


Used By



1.0.0 - Aug 13, 2017