Bump swift-actions/setup-swift from 1.22.0 to 1.23.0
Bumps swift-actions/setup-swift from 1.22.0 to 1.23.0.
updated-dependencies:
- dependency-name: swift-actions/setup-swift dependency-type: direct:production update-type: version-update:semver-minor …
Signed-off-by: dependabot[bot] support@github.com
Swift Sysctl
A Swift interface for reading (and writing)
sysctlvalues.Installation
Add the following dependency to your
Package.swift:Or add it via Xcode (as of Xcode 11).
Usage
Using Swift Sysctl is really easy. You just create a
SystemControlinstance and start accessing values. That’s it:Swift Sysctl contains a few common values and will also grow over time. If you find that you need a value that’s not yet present, you can easily add them. Just read through the following sections:
SysctlNamespaceAs you might now,
sysctladdresses values using a name that has dots in it. Swift Sysctl calls the parts between these dots “namespace” and represents them in Swiftstructs. So for example, there’sHardwarerepresenting thehwnamespace insysctl. Each namespace has a parent. If the namespace is located at the root, use theSysctlRootNamespaceas parent.When implementing your own namespaces, simply conform them to
SysctlNamespace, define the parent and implementstatic var namePart: String { /*...*/ }, returning the name part of your namespace (e.g.hwforHardware).Here’s an example for a new (imaginary) namespace that also has a child namespace:
SysctlNamespace.FieldTo access a value from
sysctl, there are (computed) properties on the namespaces. So for example forhw.machinethere’s a propertymachineon theHardwarenamespace. To access new values, simply declare a new (computed) property on the namespace the field is in (either in a namespace that you implemented on your own or by extending an existing one). The value type of these properties needs to beField<T>whereTis the type of value.Fieldis a typealias forSysctlNamedFieldinside a namespace. A field contains the last name part of the value’s name. Thus you simply return the name as string. If the value is writable, you also provide anonmutating setimplementation, which can be left empty.Continuing our example, here’s how fields on
Superpowerwould look like:SysctlValueandSysctlValueRepresentableFor Swift Sysctl to know how to read (or write) a value into
sysctl, it needs to conform toSysctlValue. However,sysctlonly supports very few value types, so it’s very unlikely that you need to conform another type to it.A bit more likely (but still not very likely) is that you want to have custom type that is represented by a value that already conforms to
SysctlValue. In this case, theSysctlValueRepresentableprotocol is what your type needs to conform to. It behaves very similar to Swift’sRawRepresentableprotocol. You need to declare which underlyingSysctlValuetype your type will be using and implement the read-only propertyvar syctlValue: SysctlValue { get }in which you return the underlyingSysctlValueof your type. Then you ned to implementinit(sysctlValue:)on your type. Swift Sysctl will pass the underlylingSysctlValueto this initializer and you are left with initializing your type from it. With these requirements fulfilled, Swift Sysctl will provide the implementation forSysctlValuefor you and you can read and write your type from/tosysctl.Again continuing our example, here’s how you would read a new type from
sysctl:Possible Features
While not yet integrated, the following features might provide added value and could make it into this package in the future:
sysctl(e.g. names depending on the number of cpus or network interfaces).sysctlfails.Documentation
The API is documented using header doc. If you prefer to view the documentation as a webpage, there is an online version available for you.
Contributing
If you find a bug / like to see a new feature there are a few ways of helping out:
License
See LICENSE file.