Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Swift Package Manager support #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SystemKit",
products: [
.library(name: "SystemKit", targets: ["SystemKit"]),
],
dependencies: [],
targets: [
.target(name: "SystemKit", dependencies: [], path: "SystemKit"),
.testTarget(name: "SystemKitTests", dependencies: ["SystemKit"], path: "SystemKitTests")
],
swiftLanguageVersions: [.v5]
)
33 changes: 29 additions & 4 deletions SystemKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
4C543D381A08398500C5D9B2 /* System.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = System.swift; sourceTree = "<group>"; };
4C543D3A1A08399100C5D9B2 /* Battery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Battery.swift; sourceTree = "<group>"; };
4C6D98B71A3A8FF500BA2B36 /* IOReturn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IOReturn.swift; sourceTree = "<group>"; };
C0E9F63324CB3F5F00648277 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
C0E9F63424CB439D00648277 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -102,6 +104,8 @@
4C543D121A08396700C5D9B2 = {
isa = PBXGroup;
children = (
C0E9F63424CB439D00648277 /* Package.swift */,
C0E9F63324CB3F5F00648277 /* .gitignore */,
4C543D1E1A08396700C5D9B2 /* SystemKit */,
4C543D2B1A08396700C5D9B2 /* SystemKitTests */,
4C4BE6081A083A690085170A /* Example */,
Expand Down Expand Up @@ -231,7 +235,7 @@
4C543D131A08396700C5D9B2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0830;
LastUpgradeCheck = 1160;
ORGANIZATIONNAME = beltex;
TargetAttributes = {
4C4BE6061A083A690085170A = {
Expand All @@ -250,10 +254,11 @@
};
buildConfigurationList = 4C543D161A08396700C5D9B2 /* Build configuration list for PBXProject "SystemKit" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 4C543D121A08396700C5D9B2;
productRefGroup = 4C543D1D1A08396700C5D9B2 /* Products */;
Expand Down Expand Up @@ -335,6 +340,7 @@
4C4BE60B1A083A690085170A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "-";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -348,6 +354,7 @@
4C4BE60C1A083A690085170A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "-";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
Expand All @@ -357,18 +364,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -405,18 +421,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -459,7 +484,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -479,7 +504,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "beltex.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
24 changes: 10 additions & 14 deletions SystemKit.xcodeproj/xcshareddata/xcschemes/SystemKit.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "1160"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4C543D1B1A08396700C5D9B2"
BuildableName = "SystemKit.framework"
BlueprintName = "SystemKit"
ReferencedContainer = "container:SystemKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -39,17 +48,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4C543D1B1A08396700C5D9B2"
BuildableName = "SystemKit.framework"
BlueprintName = "SystemKit"
ReferencedContainer = "container:SystemKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -70,8 +68,6 @@
ReferencedContainer = "container:SystemKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
20 changes: 10 additions & 10 deletions SystemKit/Battery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public struct Battery {
*/
public func currentCapacity() -> Int {
let prop = IORegistryEntryCreateCFProperty(service,
Key.CurrentCapacity.rawValue as CFString!,
Key.CurrentCapacity.rawValue as CFString?,
kCFAllocatorDefault,0)
return prop!.takeUnretainedValue() as! Int
}
Expand All @@ -176,7 +176,7 @@ public struct Battery {
*/
public func maxCapactiy() -> Int {
let prop = IORegistryEntryCreateCFProperty(service,
Key.MaxCapacity.rawValue as CFString!,
Key.MaxCapacity.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Int
}
Expand All @@ -191,7 +191,7 @@ public struct Battery {
*/
public func designCapacity() -> Int {
let prop = IORegistryEntryCreateCFProperty(service,
Key.DesignCapacity.rawValue as CFString!,
Key.DesignCapacity.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Int
}
Expand All @@ -204,7 +204,7 @@ public struct Battery {
*/
public func cycleCount() -> Int {
let prop = IORegistryEntryCreateCFProperty(service,
Key.CycleCount.rawValue as CFString!,
Key.CycleCount.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Int
}
Expand All @@ -217,7 +217,7 @@ public struct Battery {
*/
public func designCycleCount() -> Int {
let prop = IORegistryEntryCreateCFProperty(service,
Key.DesignCycleCount.rawValue as CFString!,
Key.DesignCycleCount.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Int
}
Expand All @@ -230,7 +230,7 @@ public struct Battery {
*/
public func isACPowered() -> Bool {
let prop = IORegistryEntryCreateCFProperty(service,
Key.ACPowered.rawValue as CFString!,
Key.ACPowered.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Bool
}
Expand All @@ -243,7 +243,7 @@ public struct Battery {
*/
public func isCharging() -> Bool {
let prop = IORegistryEntryCreateCFProperty(service,
Key.IsCharging.rawValue as CFString!,
Key.IsCharging.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Bool
}
Expand All @@ -256,7 +256,7 @@ public struct Battery {
*/
public func isCharged() -> Bool {
let prop = IORegistryEntryCreateCFProperty(service,
Key.FullyCharged.rawValue as CFString!,
Key.FullyCharged.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Bool
}
Expand All @@ -282,7 +282,7 @@ public struct Battery {
*/
public func timeRemaining() -> Int {
let prop = IORegistryEntryCreateCFProperty(service,
Key.TimeRemaining.rawValue as CFString!,
Key.TimeRemaining.rawValue as CFString?,
kCFAllocatorDefault, 0)
return prop!.takeUnretainedValue() as! Int
}
Expand Down Expand Up @@ -312,7 +312,7 @@ public struct Battery {
*/
public func temperature(_ unit: TemperatureUnit = .celsius) -> Double {
let prop = IORegistryEntryCreateCFProperty(service,
Key.Temperature.rawValue as CFString!,
Key.Temperature.rawValue as CFString?,
kCFAllocatorDefault, 0)

var temperature = prop?.takeUnretainedValue() as! Double / 100.0
Expand Down
14 changes: 7 additions & 7 deletions SystemKit/System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public struct System {
else { name = String() }


ptr.deallocate(capacity: 1)
ptr.deallocate()

#if DEBUG
if result != 0 {
Expand Down Expand Up @@ -461,7 +461,7 @@ public struct System {
as! Double
}

status.deallocate(capacity: 1)
status.deallocate()

return (processorSpeed, processorCount, schedulerTime)
}
Expand Down Expand Up @@ -523,7 +523,7 @@ public struct System {
}

let data = hostInfo.move()
hostInfo.deallocate(capacity: 1)
hostInfo.deallocate()

#if DEBUG
if result != KERN_SUCCESS {
Expand All @@ -547,7 +547,7 @@ public struct System {
}

let data = hostInfo.move()
hostInfo.deallocate(capacity: 1)
hostInfo.deallocate()

#if DEBUG
if result != KERN_SUCCESS {
Expand All @@ -571,7 +571,7 @@ public struct System {
}

let data = hostInfo.move()
hostInfo.deallocate(capacity: 1)
hostInfo.deallocate()

#if DEBUG
if result != KERN_SUCCESS {
Expand Down Expand Up @@ -624,7 +624,7 @@ public struct System {
mach_port_deallocate(mach_task_self_, pset)

let data = info_out.move()
info_out.deallocate(capacity: 1)
info_out.deallocate()

return data
}
Expand All @@ -649,7 +649,7 @@ public struct System {
}

let data = hostInfo.move()
hostInfo.deallocate(capacity: 1)
hostInfo.deallocate()

#if DEBUG
if result != KERN_SUCCESS {
Expand Down