{"id":32143189,"url":"https://github.com/vetrek/smartstring","last_synced_at":"2025-10-21T07:54:13.866Z","repository":{"id":45839540,"uuid":"455470034","full_name":"vetrek/SmartString","owner":"vetrek","description":"Powerful Attributed String Framework in Swift","archived":false,"fork":false,"pushed_at":"2023-09-08T14:07:06.000Z","size":285,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-21T07:54:10.587Z","etag":null,"topics":["attributedstring","cocoapods","ios","nsattributedstring","smartstring","string","style","swift","swift-library","swift-package-manager","tap","tap-gestures","tapgesturerecognizer","text-formatting"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vetrek.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-02-04T08:18:53.000Z","updated_at":"2024-04-21T09:33:11.000Z","dependencies_parsed_at":"2022-09-01T00:52:44.653Z","dependency_job_id":null,"html_url":"https://github.com/vetrek/SmartString","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/vetrek/SmartString","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vetrek%2FSmartString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vetrek%2FSmartString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vetrek%2FSmartString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vetrek%2FSmartString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vetrek","download_url":"https://codeload.github.com/vetrek/SmartString/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vetrek%2FSmartString/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280225806,"owners_count":26293888,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["attributedstring","cocoapods","ios","nsattributedstring","smartstring","string","style","swift","swift-library","swift-package-manager","tap","tap-gestures","tapgesturerecognizer","text-formatting"],"created_at":"2025-10-21T07:54:09.134Z","updated_at":"2025-10-21T07:54:13.861Z","avatar_url":"https://github.com/vetrek.png","language":"Swift","readme":"# SmartString\n[![Swift 5.1](https://img.shields.io/badge/Swift-5.1-orange.svg?style=flat)](https://swift.org)\n![iOS 10.0](https://img.shields.io/badge/iOS-10.0-blue.svg?style=flat)\n\nPowerful and small library written in **Swift** that will allow you to create complex attributed strings. Easily chain Strings + SmartStrings to create the perfect style, and register substrings Tap Getures handlers.\n\n## Features\n\n- [x] Powerful and intuitive APIs\n- [x] Easily chain SmartString + Strings \n- [x] XML Tagged string styles\n- [x] Tap Gestures handlers directly on substrings\n- [x] Create and store predefined \u0026 reusable Styles\n- [x] Ideal for anyone who builds UI from code\n\n## Projects using SmartString\n- [YourVPN](https://yourvpn.world/)\n\n## Installation\n\n### Swift Package Manager\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler.\n\nIn Xcode 11+ select File \u003e Packages \u003e Add Package Dependency \u003e Enter this project's URL:\n    \n    https://github.com/vetrek/SmartString.git\n\n\n### CocoaPods\n\n```ruby\npod 'SmartString'\n```\n\n## Example\n\n* ### Usage\n```swift\nlet smartString = \"Hello world!\"\n    .font(.boldSystemFont(ofSize: 30))\n    .color(.blue)\n    .underline()\n    .shadow(SmartShadow())\n    .onTap { string in\n        print(string) // This will print \"Hello world!\"\n    }\n\nlabel.smartString = smartString\n\n// Using Closures\n\nlet smartString = \"Hello world!\"\n    .font { .boldSystemFont(ofSize: 30) }\n    .color { .blue }\n    .shadow { .default }\n    .underline()\n\nlabel.smartString = smartString\n```\n\nResult\n\n\u003cimg src=\"DocsAssets/example_1.png\" alt=\"\" width=200/\u003e\n\n* ### Predefined Style\n```swift\nlet style = SmartStringStyle { style in\n    style.font = .systemFont(ofSize: 21)\n    style.color = .red\n    style.underlined = true\n    style.shadow = .default\n    style.onTap = { string in\n        print(string)\n    }\n}\n\nlabel.smartString = \"Hello world!\".style(style)\n```\n\nResult\n\n\u003cimg src=\"DocsAssets/example_2.png\" alt=\"\" width=200/\u003e\n\n* ### String + SmartString interpolation\n```swift\nlabel.smartString = \"Hello\" + \" world!\".font(.systemFont(ofSize: 24)).color(.purple)\n```\n\nResult\n\n\u003cimg src=\"DocsAssets/example_3.png\" width=200/\u003e\n\n* ### String + SmartString interpolation using predefined Styles\n```swift\nlet style1 = SmartStringStyle { style in\n    style.color = .green\n    style.font = .boldSystemFont(ofSize: 30)\n    style.shadow = .default\n}\n        \nlabel.smartString = \"Hello\" + \" world!\".style(style1)\n```\n\nResult\n\n\u003cimg src=\"DocsAssets/example_4.png\" width=200/\u003e\n\n* ### Label substring Tap Handlers\n\n```swift\nlet smartString = \"Hello \"\n    .font { .systemFont(ofSize: 18) }\n    .onTap { string in\n        print(string) // This will print \"Hello \" when tapping the substring \"Hello \" within the label\n    }\n+ \"world\"\n    .color(.red)\n    .bold()\n    .onTap { string in\n        print(string) // This will print \"world\" when tapping the substring \"world\" within the label\n    }\n+ \"!\"\n    \nlabel.smartString = smartString\n```\n\nResult\n\n\u003cimg src=\"DocsAssets/example_5.png\" width=200/\u003e\n\n* ### Define style using XML Tags\n\n#### Styles\n```swift\n\n//  XMLStringStyles.swift \nenum XMLStringStyles: String, CaseIterable, SmartStringStylable {\n    case primary\n    case secondary\n\n    var style: SmartStringStyle {\n        switch self {\n        case .primary:\n            return SmartStringStyle { style in\n                style.font = .boldSystemFont(ofSize: 24)\n                style.color = .blue\n                style.link = URL(string: \"https://google.com\")\n            }\n        case .secondary:\n            return SmartStringStyle { style in\n                style.font = .boldSystemFont(ofSize: 24)\n                style.color = .black\n                style.backgroundColor = .systemPink\n            }\n        }\n    }\n    \n    /// Associate tags with styles. You should call this function when the app starts running\n    static func setXmlSmartStringStyles() {\n        XMLStringStyles.allCases.forEach {\n            SmartStringXMLStyles.styles[$0.rawValue] = $0.style\n        }\n    }\n\n}\n\n```\n\n#### Associate styles to tags after application launch\n```swift\n//  AppDelegate.swift File\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n    // Override point for customization after application launch.\n    \n    // Register styles\n    XMLStringStyles.setXmlSmartStringStyles()\n    \n    return true\n}\n```\n\n#### Usage\n```swift\n// ViewController.Swift File\n\n// Option 1\nlabel.smartString = \"\u003cprimary\u003eHello \u003c/primary\u003e\u003csecondary\u003eworld!\u003c/secondary\u003e\".smartStringXML\n\n// Option 2, which uses a **tag** method to apply tags\nlet xmlString = \"Hello \".tag(XMLStringStyles.primary) + \"world!\".tag(XMLStringStyles.secondary)\nlabel.smartString = xmlString.smartStringXML\n\n// Option 3, wrap **tag** method in a string extension to have an even cleaner coder\nextension String {\n    func tag(with style: XMLStringStyles) -\u003e String {\n        tag(style)\n    }\n}\n\nlet xmlString = \"Hello \".tag(with: .primary) + \"world!\".tag(with: .secondary)\nlabel.smartString = xmlString.smartStringXML\n\n```\n\nResult\n\n\u003cimg src=\"DocsAssets/example_6.png\" width=200/\u003e\n\n## Author\n\nSmartString is maintained by Valerio Sebastianelli: [valerio.alsebas@gmail.com](mailto:valerio.alsebas@gmail.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvetrek%2Fsmartstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvetrek%2Fsmartstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvetrek%2Fsmartstring/lists"}