{"id":13902874,"url":"https://github.com/rjstelling/Swift-Gists","last_synced_at":"2025-07-18T00:32:24.381Z","repository":{"id":73607753,"uuid":"164103632","full_name":"rjstelling/Swift-Gists","owner":"rjstelling","description":"A list of Gists containing simple but useful Swift code written by Richard Stelling - @rjstelling ","archived":false,"fork":false,"pushed_at":"2020-06-04T09:34:50.000Z","size":32,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-27T17:56:22.151Z","etag":null,"topics":["swift"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rjstelling.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-04T12:15:15.000Z","updated_at":"2020-12-09T14:43:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec6d4ff3-6858-40d6-80fa-e0a88c3ce3a8","html_url":"https://github.com/rjstelling/Swift-Gists","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjstelling%2FSwift-Gists","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjstelling%2FSwift-Gists/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjstelling%2FSwift-Gists/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjstelling%2FSwift-Gists/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjstelling","download_url":"https://codeload.github.com/rjstelling/Swift-Gists/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":214260308,"owners_count":15707075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swift"],"created_at":"2024-08-06T22:01:28.707Z","updated_at":"2025-07-18T00:32:24.365Z","avatar_url":"https://github.com/rjstelling.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"# Swift Gists\n\nThis is a continiously expanding list of GitHub Gists (and repos) containing simple but useful Swift code. Nothing here realy warrents a Framework or Library but can be copied and pasted.\n\n## Gists \u0026 Repositories\n\n### [Fixing Linker Errors in Xcode (`___llvm_profile_runtime` Missing Symbol)](https://gist.github.com/rjstelling/be644d7d3061ac6e53894f2953385f3c)\n\nThis tutorial explains how to resolve the linker error ___llvm_profile_runtime missing symbol in Xcode, typically occurring when code coverage settings (CLANG_COVERAGE_MAPPING) are inadvertently enabled. The issue is common when using Swift Packages like PocketSVG. It guides you through verifying the problematic setting via command-line comparison of build settings, then demonstrates the solution—deleting the auto-generated test plan in Xcode’s test plan manager. After performing this simple step and cleaning your build, the linker error should be fixed.\n\n### [How to Create and Use Multiple Apple IDs for iOS Simulator Testing](https://gist.github.com/rjstelling/bd783f50416f424c6080db911080a177)\n\nCreating multiple Apple IDs for testing your app in the iOS Simulator can help isolate user experiences and troubleshoot issues effectively. Follow this easy guide to set up and successfully use multiple Apple IDs.\n\n### [Creating a UIBarButtonItem That Ignores Smart Invert](https://gist.github.com/rjstelling/db5c49bf97a17ab7100233f807dd26d0)\n\nThis tutorial shows how to create a custom UIBarButtonItem that ignores the Smart Invert accessibility feature (using `accessibilityIgnoresInvertColors`). It also covers why using a UIImageView as the custom view will not trigger an action, and offers a helpful example of an accessibility hint.\n\n### [Semantic Versioning](https://gist.github.com/rjstelling/dfa3e6ac491806a63e359259a9a06dc3)\n\nA `Version` type that supports [Semantic Versioning](https://semver.org) with labels.\n\n```swift\nlet version1: Version = \"1.0.0\"\nlet version2: Version = \"2.0.0\"\n\nversion1 == version2 // false\nversion2 \u003e version1 // true\n\nlet version1point1 = \"1.1\"\n\nversion1.isCompatible(version1point1) // true\nversion2.isCompatible(version1point1) // false\n\nlet version2Prerelease = \"2.0-beta\"\n\nversion2Prerelease \u003e= version2 //false\n```\n\n### [Swifty Uniform Type Identifier Extensions](https://gist.github.com/rjstelling/0e3298a42c2a2bca2f75f193578521c3)\n\nA `URL` extension to make working with [UTIs](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_intro/understand_utis_intro.html#//apple_ref/doc/uid/TP40001319-CH201-SW1) in Swift less painful.\n\n```swift\nlet documentUrl = URL(fileURLWithPath: \"/Volumes/MyDisk/Projects/Project1/Report.pages\"\nlet uti = try doumentUrl.uniformTypeIdentifier()\n\nprint(\"\\(uti)\") // Pages Document\n```\n\n### [RegularExpressionValidation Property Wrapper](https://gist.github.com/rjstelling/649ff0e848af4e03f461386f4548b72d)\n\nA `@propertyWrapper` that validates a string using a regular expression. If the string matches then it is assigned to the property if it does not then the property is net to nil. Also included is an example of validating email addresses.\n\nExample:\n\n```swift\nstruct Example {\n    \n    /* This will be set to nil unless the string assigned to it matches the regular expression \n    \"^(?:[a-z0-9!#$%\u0026'*+/=?^_`{|}~-]+(?:\\\\.[a-z0-9!#$%\u0026'*+/=?^_`{|}~-]+)*|\\\"(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21\\\\x23-\\\\x5b\\\\x5d-\\\\x7f]|\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])*\\\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21-\\\\x5a\\\\x53-\\\\x7f]|\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])+)\\\\])$\"\n    */\n    @EmailValidation\n    var email: String?\n    \n    // The string must be in the format $1,000,000.00 or £1,000,000.00\n    // Missing $ or £ will fail, `.` and `,` are optional\n    @RegularExpressionValidation(\"^[£$][0-9,]*$\")\n    var currency: String?    \n}\n```\n\n### [Standard Streams](https://github.com/rjstelling/StandardStreams.swift)\n\nA protocol based approach to writing to `Standard Out` and `Standard Error`.\n\n```swift\nlet console = StandardOut()\nlet error = StandardErr()\n\nconsole.print(\"Hello World! - This will print to stdout and can be piped or redirect to a file.\")\n\nerror.print(\"Errors are by standard printed to the console even if your redirect, useful!\")\n```\n\n### [Base Functions](https://gist.github.com/rjstelling/0216a4f9bfaec87dec44d30ac65399b1)\n\nA set of extensions on `String` and `FixedWidthInteger` to encode and decode unsigned integers with custom character sets. \n\n```swift\n// Encode integer to a string\nlet encodedValue = try 1973.encode() // \"PZ\"\n\n// Decode the string back to an integer\nlet decodedValue: UInt = try encodedValue.decode() // 1973\n\n// Using a custom string\nlet rosetta = \"🤖❤️☠️🤓🦁🍆🧀😎🙄🤢🧠🧶🙈🙉🙊🔥🥕⚽️💊🎶🧶👏🔡\"\nlet emojiEncoded = try 1024.encode(rosetta.count, using: rosetta) // \"❤️👏🙈\"\n\nlet emojiDecoded: UInt = try \"❤️👏🙈\".decode(UInt(rosetta.count), using: rosetta) // 1024\n```\n\n### [Fowler–Noll–Vo Hash](https://gist.github.com/rjstelling/fc695f5c37beeefd2a810179b723b29f)\n\nData Extension for Fowler–Noll–Vo hash function.\n\n```swift\nlet data = \"Hello World!\".data(using: .utf8)!\nlet fnvValue = data.fnv32HashString() // \"12a9a41c\"\n\n// Adding a single byte has a large affect on the hash\nlet fnvValue2 = (data + Data(repeating: 255, count: 1)).fnv32HashString() // \"7d0d58eb\"\n```\n\n### [Two Label UIButton](https://gist.github.com/rjstelling/70c4d0ad6934df99246c0f56e3494f38)\n\nA simple Auto Layout solution for a UIButton with 2 labels.\n\n```swift\nlet tlButton = TwoLabelButton()\ntlButton.setTitles( (\"Title:\", \"value\") )\n```\n\n### [Print Binary String of Integers](https://gist.github.com/rjstelling/3be83e4b5dbdb8b6278e324780938400)\n\nA generic function to print the \"binary string\" of any `FixedWidthInteger`.\n\nExample:\n\n```swift\nlet smallNumber: UInt16 = 7\nprint(asBinary: smallNumber) //output: 0b0000000000000111\n```\n\n## Future Improvements\n\n1. Comments.\n2. Examples.\n\n## Pull Requests\n\nIf you feel like you want to, thats cool! However, I'm not promising to be speedy or meritocratic.\n\n## Licence\n\nAll code, including this file are covered by the MIT Licence.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjstelling%2FSwift-Gists","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjstelling%2FSwift-Gists","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjstelling%2FSwift-Gists/lists"}