This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// A playground to see different ways to get environment variables in Swift | |
// Foundation is the easiest way using the awesome ProcessInfo class. | |
// Get all of the environment variables for your running process in a Dictionary. | |
let foundationEnv = ProcessInfo().environment | |
print("********** ProcessInfo Environment **********") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get crazy and hook MobileGestalt in a Swift Playground! | |
// | |
// If you are a LONG time Mac developer you know that the Gestalt system | |
// used to be a way to get info about your Mac. These days it's a private | |
// thing that Apple locks away and you shouldn't really touch. Most of the info | |
// that you need can probaby be found in IOKit, but some values, like | |
// the provisioningUDID are not avaliable any other way. | |
// | |
// That said, it's a fun exersize to see how to do some various things in Swift. | |
// Things like loading a dylib or calling private C functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This playground shows you a few different ways to get device info via IOKit. | |
// If you want to explore IOKit and look for interesting data I would download | |
// the Additional Developer Tools from Apple and use the IORegistryExplorer app. | |
// It makes it super easy to poke around in the IOKit planes. | |
import IOKit | |
import Foundation | |
// For convient access we can make a computed getter for the PlatformExpert. | |
// Traditionally this has been where you go to find all sorts of data about the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension TimeInterval { | |
var seconds: TimeInterval { self } | |
var minutes: TimeInterval { self * 60 } | |
var hours: TimeInterval { self * 3_600 } | |
var days: TimeInterval { self * 86_400 } | |
var weeks: TimeInterval { self * 604_800 } | |
var months: TimeInterval { self * 2_628_000 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Activity.swift | |
// | |
// Created by Zachary Waldowski on 8/21/16. | |
// Copyright © 2016 Zachary Waldowski. Licensed under MIT. | |
// | |
import os.activity | |
private final class LegacyActivityContext { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
var isScreenLocked: Bool { | |
guard let wssProperties = CGSessionCopyCurrentDictionary() as? [String : Any], (wssProperties["CGSSessionScreenIsLocked"] != nil) else { | |
return false | |
} | |
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
// Security Session | |
// | |
// You can access bits about the security session to get some basic info. You can only get info about your own session. | |
// Other than the session id, the values are all Bools. | |
var sessionID = SecuritySessionId() | |
var sessionAttrs = SessionAttributeBits() | |
let result = SessionGetInfo(callerSecuritySession, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
// Simple class to search for things with `NSMetadataQuery`. | |
class Searcher { | |
// This is just for timing things | |
let startTime = Date() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import CoreServices | |
// Different ways of finding out about disk space on macOS. | |
// This method from CoreServices lets you find the space the OS considers "purgable" | |
// You can trigger a purge as well with `CSDiskSpaceStartRecovery` | |
let path = URL(fileURLWithPath: "/") | |
let possibleBytes = CSDiskSpaceGetRecoveryEstimate(path as NSURL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Playground for exploring memory layout in Swift. | |
// A simple struct | |
struct Foo { | |
let a: Int? | |
let b: Int? | |
var isTrue = true | |
} |
NewerOlder