AppDeveloperKit-String: A Swift library for subscripting, regular expression matching and substitutions

String shortcomings

I really enjoy programming in Swift, but I’ve always been bothered a bit by what I perceived as a couple of shortcomings related to the String class.

Subscripting

There is no support for subscripting a String.

Try the following in a Playground and you’ll get an error:

 let str = "Hello"

 str[1]   // 'subscript' is unavailable: cannot subscript String with an Int
 str[1..<3] // 'subscript' is unavailable: cannot subscript String with an integer range

You can find a mention of this restriction in some source code comments.

Continue reading

Advertisements

Solving a HackerRank algorithm problem – Matrix Layer Rotation

Matrix Layer Rotation

I enjoy solving interesting HackerRank algorithm problems.  I came across one recently called Matrix Layer Rotation – appropriately labeled “hard” by the author.

I posted my solution as a playground on GitHub.

The problem is to print out a rotated representation of a m x n  matrix given the parameters:

m – number of rows
n – number of columns
r – number of rotations

Looking at the constraints

2 <= m, n <= 300
1 <= r <= 10^^9
min(m,n) % 2 = 0

Continue reading

AppDeveloperKit – reusable, configurable Swift classes for iOS

Introducing AppDeveloperKit

I’ve completed the initial release of a project I’ve been working on called AppDeveloperKit.   It is a tool for iOS developers to assist in developing reusable, configurable Swift classes.

Properties are declared in classes and coded to affect appearance and behavior. The values for these properties are stored in a property list (plist) file. A macOS app provides a UI to edit these properties in real-time as an app is actively running on a device or simulator.  An iOS framework coordinates access to the plist file and communication to the macOS app.

 

Features

This is a list of the main features that AppDeveloperKit offers:

Continue reading

Leave Swift Error Propagation Enabled

A harmless Database update

I was debugging a Swift Mac app that I’m developing that uses Realm for a database.  The version of RealmSwift I was currently using was 2.10.0 as specified in my Podfile.

I opened Realm Browser to inspect a record in my database.   Having been recently updated to version 3.0.1, it alerted me that my database was using an older file format and offered to upgrade it.   I accepted without thinking much of it.

An unexpected error

Continue reading

Error reporting for complex unit tests

System level unit testing

I was recently putting together the structure for some system level unit tests of a Swift project.   The structure extended beyond a single file for these tests.   I currently have:

  • SystemTests – Base class for a suite of system level unit tests.
  • BasicSystemTests – Class for my first group of unit tests.  Derives from SystemTests.
  • Various utility classes, each specific to a major section of the project.

Here is an example chain of calls coming from a test case:

BasicSystemTests

   func testModified () {
        
        // Test modification to Project
        //
        createProject(name: "Test Project", bundleId: "TestBundleId", appDelegate: "TestAppDelegate", fsConfig: "TestFsConfig", description: "Test Project Description")
        

SystemTests


   func createProject(name: String, bundleId: String, appDelegate: String?, fsConfig: String?, description: String?) -> String? {
        
        // Is Add New button enabled?
        project.verifyAddNewButton(enabled: false)

ProjectTestUtils

    func verifyAddNewButton(enabled: Bool) {
        XCTAssertEqual(addNewButton.isEnabled, enabled, "Add New button enabled = \(enabled)")
    }
  

The problem – what is the path?

My test case has a bug.  When I run the test case, I see the following in Issue Navigator and the source code editor:

Continue reading