Code Monkey home page Code Monkey logo

cwlutils's Introduction

CwlUtils

A collection of utilities written as part of articles on Cocoa with Love

Included functionality

The following features are included in the library.

Adding to your project

The CwlUtils library requires the Swift Package Manager. Minimum requirements are iOS 8 or macOS 10.10 and Swift 5.0.

Add the following to the dependencies array in your "Package.swift" file:

.package(url: "https://github.com/mattgallagher/CwlUtils.git", from: Version(3, 0, 0)),

NOTE: even though this git repository includes its dependencies in the Dependencies folder, building via the Swift Package manager fetches and builds these dependencies independently.

CocoaPods and Carthage

Up to version 2.2.1, this library supported CocoaPods and Carthage. If you wish to use these package managers, you can check out the CwlUtils 2.2.1 tag

cwlutils's People

Contributors

antiraum avatar aufflick avatar benstiglitz avatar mattgallagher avatar monyschuk avatar morozkin avatar nettlep avatar toshi0383 avatar xjki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cwlutils's Issues

Occasional crashes on pthread_mutex_lock(&unsafeMutex)

I am experiencing occasional crashes when using this method, this is the relevant part of the stack trace:

Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Triggered by Thread:  0
Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x0000000185e41e64 __psynch_mutexwait + 8
1   libsystem_pthread.dylib         0x0000000185f0bda4 _pthread_mutex_lock_wait + 96
2   SolutoHomeKit                   0x0000000100fcda34 0x100f84000 + 301620
3   SolutoHomeKit                   0x0000000101064994 0x100f84000 + 919956
4   SolutoHomeKit                   0x000000010106556c 0x100f84000 + 922988
5   SolutoHomeKit                   0x0000000101080f80 0x100f84000 + 1036160
6   SolutoHomeKit                   0x0000000101080f00 0x100f84000 + 1036032

I am trying to google it right now, see if someone experience something simillar - but thought it might be also good to ask here, in case someone already familiar with that issue. If I'll find something useful, I will update.
Thanks,
Omer

CwlSysctl: adding structFromSysctl or intArrayFromSysctl

Hello!

First of all, thanks for making CwlSysctl! Great tool :).

I wrote two helper functions that could be useful: one to convert the result of your sysctl into a struct and the other into an array of Int64. My goal was to be able to retrieve the result of sysctl kernel.boottime.

I have no idea if the following code is the correct way to do it, or if it can be improved... I usually don't go that "far" down the rabbit hole :).

public func structFromSysctl<S>(levels: Int32..., as: S.Type = S.self) throws -> S {

    let buffer = try sysctl(levels: levels)

    return buffer.withUnsafeBytes() {
        $0.load(as: S.self)
    }
}

Usage:

let bootTime = try structFromSysctl(levels: CTL_KERN, KERN_BOOTTIME, as: timeval.self) // or
let bootTime: timeval = try structFromSysctl(levels: CTL_KERN, KERN_BOOTTIME)
print(bootTime) // timeval(tv_sec: 1499259206, tv_usec: 122778)

And for Int64 arrays:

public func intArrayFromSysctl(levels: Int32...) throws -> [Int64] {

    let buffer = try sysctl(levels: levels)

    if buffer.count % 8 != 0 {
        throw SysctlError.invalidSize
    }

    return buffer.withUnsafeBytes { pointer in
        (0..<(buffer.count / 8)).map { i in
            pointer.load(fromByteOffset: i * 8, as: Int64.self)
        }
    }
}
let bootTime = try intArrayFromSysctl(levels: CTL_KERN, KERN_BOOTTIME)
print(bootTime) // [1499259206, 122778]

I can submit a pull request if my solution is acceptable.

Static version required to use with Swift PM

Any framework (say F) that depends on https://github.com/mattgallagher/CwlUtils.git will use a dynamic link library if the CwlUtils is consumed as a swift package.

This creates a problem because when another application A consumed the framework F it doesn't get a copy of CwlUtils.

The workaround listed in the readme creates missing CwlFrameAddress issues in application A.

The solution is again to consume CwlUtils in application A. Looks like the SPM doesn't know how to deal the dynamic libraries.

I believe the line is here:
.library(name: "CwlUtils", type: .dynamic, targets: ["CwlUtils"]),

Does CwlUtils need to be dynamic?

How to invoke and wait on the main thread?

I've been looking at Exec and can not figure out how to invokeAndWait from the main thread; none of the cases seems to cover that.

(It's quite confusing that Exec.mainAsync.invokeAndWait does not wait.)

Bug in DispatchTimeInterval.toSeconds()

After a lot of head scratching earlier today I found the cause of some unexpected timer behaviour originating in code I originally copied from your DispatchTimeInterval.toSeconds() extension. The bug still seems to be there, calculations here are not correct:

case .milliseconds(let t): return (1.0 / Double(NSEC_PER_MSEC)) * Double(t)

(lldb) po DispatchTimeInterval.milliseconds(1).toSeconds()
9.9999999999999995e-07
(lldb) po DispatchTimeInterval.microseconds(1).toSeconds()
0.001

I opted by changing the relevant cases in the switch:

case .milliseconds, .microseconds, .nanoseconds:
            return (1.0 / Double(NSEC_PER_SEC)) * Double(toNanoseconds())

Thanks for sharing CwlUtils!

App Store publication issue with Carthage: Framework missing CFBundleVersion

When I go to validate my app's IPA for release with Apple, it fails due to an issue it's finding with the Carthage-built version of CwlUtils.

"This bundle Payload/My_App.app/Frameworks/CwlUtils.framework is invalid. The Info.plist file is missing the required key: CFBundleVersion. Please find more information about CFBundleVersion at https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleversion"

It looks like the Info.plist HAS CFBundleVersion set to $(CURRENT_PROJECT_VERSION), which is standard.

However, CURRENT_PROJECT_VERSION is not set in this project's build settings (project.pbxproj). I'm not well versed in setting up Carthage frameworks, but it seems like this current project version should be set.

I cannot produce a valid build for production with this issue as-is.

Typo in 'Manual Inclusion' instructions of ReadMe

In step 3 you are referencing 'CwlSignal', even though I don't think CwlSignal is in play yet. Is this a copy/paste overlook ?

  1. Drag the "CwlUtils.framework" from the "Products" folder of the "CwlSignal" project to the "Copy Files (Frameworks)" build phases of any target that you want to include this module.

README says cocoapods supported

It took me a while to figure out why all of a sudden my pods wouldn't update: your last checkin removed the podspec.
Not sure why you removed support for Pods, but, it'd be great if you could update the README to mention this -- it still says pods are supported. It'd be even better if you could point out how to "migrate" from pods to swift package manager, or whatever you recommend as a migration path.

osRev crashes

I'm testing this in iOS 11.2.1. When osRev is queried, preFlightResult is equal to -1 and a POSIXErrorCode is thrown. It's not clear to me how to debug this further.

CustomDebugStringConvertible AtomicBox

Hi,

Would you consider adding something similar to this:

extension AtomicBox<T> : CustomDebugStringConvertible 
               where T : CustomDebugStringConvertible {
    var debugDescription: String {
        let t = internalValue
        return "AtomicBox(\(t.debugDescription))"
    }
}

Scenario: I'm using AtomicBox to wrap some state in a state machine, and I need to log formatted debug info without deadlocking. The debug info is a snapshot in time, with no dependencies on it (except my understanding), so I don't need to wait for a mutex. The above would work for value types, but not class types, which is a problem - I don't know what syntax there is that would achieve where T : CustomDebugStringConvertible & !AnyObject, and diverting CustomDebugStringConvertible & AnyObjectto a different extension leads to an implementation that is unsafe. Any thoughts on this? What pattern do you use instead?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.