Giter Site home page Giter Site logo

otcore's Introduction

About Me

My name is Steffan Andrews and I hail from beautiful Vancouver, Canada.

I'm a professional composer for film and TV with over 16 years of experience specializing in animated series.

I'm also a life-long coder since 1995. I have helped build numerous commercial Mac applications including Audio Design Desk and Dipper. In my spare time I build and maintain open-source packages for Swift and SwiftUI.

Featured Swift Packages

Modern multi-platform Swift CoreMIDI wrapper with MIDI 2.0 support.
Open Sound Control (OSC) library written in Swift.
A robust and precise Swift library for working with SMPTE timecode.
Translate integers to/from radix strings (binary, hex, etc.) using convenient syntax.

Featured SwiftUI Packages

SwiftUI menu builder DSL & controls that mimic macOS Control Center.
Show/hide SwiftUI MenuBarExtra menu using Bindings.
Open your macOS app's Settings scene programmatically without needing SettingsLink.

otcore's People

Contributors

orchetect avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ryanfrancesconi

otcore's Issues

Xcode 14.1: Preview fails

Hey,

don't if this is really related to OTCore or a result of summed up errors... anyways, I use OSCKit in project and Xcodes preview crashes with the following error:

SettingsError: noExecutablePath(<IDESwiftPackageStaticLibraryProductBuildable:ObjectIdentifier(0x0000600007508cc0):'OTCore'>)

Do you have an hint?

NSArray: add [safe:] subscripts

Objective

On NSArray and NSMutableArray, add a custom subscript that duplicates the [safe:] subscript that OTCore already implements on standard Swift collections.

Interface

extension NSArray {
    open subscript(safe index: Int) -> Any? { get }
}

extension NSMutableArray {
    open subscript(safe index: Int) -> Any? { get set }
}

Implementation

  1. The implementation checks that the passed index is safe (it is not out-of-bounds).
  2. If the index is valid, then the element at that index is returned.
  3. If the index is not valid, then nil is returned.

Problem

I could not find a way to make the compiler happy when both subscripts use the same label "safe:". The nature of Objective-C objects is making this elusive to figure out.

The following implementation does function as expected (with unique subscript labels) but the goal is to use the same labels.

extension NSArray {
    open subscript(safe index: Int) -> Any? {
        (0..<count).contains(index) ? self[index] : nil
    }
}

extension NSMutableArray {
    open subscript(safeMutable index: Int) -> Any? {
        get {
            (0..<count).contains(index) ? self[index] : nil
        }
        set {
            guard (0..<count).contains(index) else { return }
            self[index] = newValue!
        }
    }
}

As soon as you make the subscript labels the same, it will not compile.

extension NSArray {
    open subscript(safe index: Int) -> Any? { get }
}

extension NSMutableArray {
    // Compiler Error: "Overriding non-@objc declarations from extensions is not supported"
    open subscript(safe index: Int) -> Any? { get set }
}

However, making both subscripts @objc and having the NSMutableArray declared override will allow the code to compile, but the functions are never actually executed when the subscript is called. Instead, the underlying subscript executes (which of course produces EXC_BAD_INSTRUCTION when an index is out-of-bounds since that is default behavior of NSArray and NSMutableArray.

extension NSArray {
    @objc open subscript(safe index: Int) -> Any? { get }
}

extension NSMutableArray {
    @objc open override subscript(safe index: Int) -> Any? { get set }
}

Next Steps

I believe the goal of implementing this with identical subscript labels [safe:] for both NSArray and NSMutableArray is possible, but it will require more research and assistance.

preprocessor commands don't work in packages

I've been meaning to deal with this for a while, but ever since switching to OTCore logging, all release builds print all debug info as well.

 Log.debug("๐ŸŽน Started MIDI")
07:33:17.448884-0700	ADD	General	debug	ADD+Initialization.swift:initMIDI():103:๐ŸŽน Started MIDI	com.audiodesigndesk.ADD

The logging needs to use a different method to determine what application build it is as the preprocessors such as RELEASE only work in the application.

Doesn't work:

        #if RELEASE
        
        // do not post debug messages to the log in a Release build
        
        #else

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.