{"id":3024,"url":"https://github.com/LeonardoCardoso/SwiftLinkPreview","last_synced_at":"2025-08-06T16:32:35.594Z","repository":{"id":37359205,"uuid":"60773287","full_name":"LeonardoCardoso/SwiftLinkPreview","owner":"LeonardoCardoso","description":"It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.","archived":false,"fork":false,"pushed_at":"2023-08-31T02:55:44.000Z","size":13457,"stargazers_count":1374,"open_issues_count":27,"forks_count":198,"subscribers_count":28,"default_branch":"main","last_synced_at":"2024-11-30T07:04:59.436Z","etag":null,"topics":["carthage","cocoapods","crawler","flow","ios","macos","preview","regular-expressions","relevant-texts","swift","swift-package-manager","tvos","url","watchos","website"],"latest_commit_sha":null,"homepage":"https://leocardz.com/swift-link-preview-5a9860c7756f","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/LeonardoCardoso.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","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":"2016-06-09T12:32:25.000Z","updated_at":"2024-11-23T14:16:20.000Z","dependencies_parsed_at":"2024-01-05T20:21:46.984Z","dependency_job_id":"c83bfbc6-e092-4e09-b574-7465e5389fde","html_url":"https://github.com/LeonardoCardoso/SwiftLinkPreview","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeonardoCardoso%2FSwiftLinkPreview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeonardoCardoso%2FSwiftLinkPreview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeonardoCardoso%2FSwiftLinkPreview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeonardoCardoso%2FSwiftLinkPreview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeonardoCardoso","download_url":"https://codeload.github.com/LeonardoCardoso/SwiftLinkPreview/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228576786,"owners_count":17939645,"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":["carthage","cocoapods","crawler","flow","ios","macos","preview","regular-expressions","relevant-texts","swift","swift-package-manager","tvos","url","watchos","website"],"created_at":"2024-01-05T20:16:29.259Z","updated_at":"2025-08-06T16:32:35.581Z","avatar_url":"https://github.com/LeonardoCardoso.png","language":"Swift","funding_links":[],"categories":["Utility","Libs","Swift","HarmonyOS","Utilities and Extensions","Utility [🔝](#readme)","UI Component"],"sub_categories":["Web View","Utility","Other free courses","Windows Manager"],"readme":"![Swift Link Preview](Images/badge.png)\n\n**Link Previewer** for **iOS**, **macOS**, **watchOS** and **tvOS**\n\n\u003e It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.\n\n\u003e Update 2025: I've decided to archive this repo due to the fact that any AI integration performs a job better than SLP. It was a nice concept at the beginning and it served its purpose. 🫡\n\n[![Platform](https://img.shields.io/badge/platform-iOS%20|%20macOS%20|%20watchOS%20|%20tvOS-orange.svg)](https://github.com/LeonardoCardoso/SwiftLinkPreview#requirements-and-details)\n[![CocoaPods](https://img.shields.io/badge/pod-v3.5.0-red.svg)](https://github.com/LeonardoCardoso/SwiftLinkPreview#cocoapods)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/LeonardoCardoso/SwiftLinkPreview#carthage)\n[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-orange.svg)](https://github.com/LeonardoCardoso/SwiftLinkPreview#swift-package-manager)\n[![Build Status](https://travis-ci.org/LeonardoCardoso/SwiftLinkPreview.svg?branch=master)](https://travis-ci.org/LeonardoCardoso/SwiftLinkPreview)\n\n#### Index\n\n* [Visual Examples](#visual-examples)\n* [Requirements and Details](#requirements-and-details)\n* [Installation](#installation)\n\t* [CocoaPods](#cocoapods)\n\t* [Carthage](#carthage)\n\t* [Swift Package Manager](#swift-package-manager)\n\t* [Manually](#manually)\n* [Usage](#usage)\n\t* [Instatiating](#instatiating)\n\t* [Requesting preview](#requesting-preview)\n\t* [Cancelling a request](#cancelling-a-request)\n* [Flow](#flow)\n* [Important](#important)\n* [Tips](#tips)\n* [Information and Contact](#information-and-contact)\n* [Related Projects](#related-projects)\n* [License](#license)\n\n\u003chr /\u003e\n\n## Visual Examples\n\n**UTF-8** | **Extended UTF-8**\t | **Gallery**\n:--:|:--:|:--:|\n![UTF-8](Images/default.gif \"UTF-8\") | ![Extended UTF-8](Images/langs.gif \"Extended UTF-8\") |![Gallery](Images/gallery.gif \"Gallery\")\n**Video Websites** | **Images**\n![Video Websites](Images/videos.gif \"Video Websites\") | ![Images](Images/images.gif \"Images\") |\n\n## Requirements and Details\n\n* iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+\n* Xcode 8.0+\n* Built with Swift 5\n\n## Installation\n\n### CocoaPods\n\nTo use **SwiftLinkPreview** as a pod package just add the following in your **Podfile** file.\n\n```ruby\n\tsource 'https://github.com/CocoaPods/Specs.git'\n\tplatform :ios, '9.0'\n\n\ttarget 'Your Target Name' do\n\t  \tuse_frameworks!\n\t  \t// ...\n\t  \tpod 'SwiftLinkPreview', '~\u003e 3.5.0'\n\t  \t// ...\n\tend\n```\n\n### Carthage\n\nTo use **SwiftLinkPreview** as a Carthage module package just add the following in your **Cartfile** file.\n\n```ruby\n  \t// ...\n\tgithub \"LeonardoCardoso/SwiftLinkPreview\" ~\u003e 3.5.0\n  \t// ...\n```\n\n### Swift Package Manager\n\nTo use **SwiftLinkPreview** as a Swift Package Manager package just add the following in your **Package.swift** file.\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n  name: \"Your Target Name\",\n  dependencies: [\n  \t// ...\n    .Package(url: \"https://github.com/LeonardoCardoso/SwiftLinkPreview.git\", \"3.5.0\")\n  \t// ...\n  ]\n)\n```\n\n### Manually\n\nYou just need to drop all contents in `Sources` folder, **but .plist files**, into Xcode project (make sure to enable \"Copy items if needed\" and \"Create groups\").\n\n\n## Usage\n\n#### Instatiating\n```swift\nimport SwiftLinkPreview\n\n// ...\n\nlet slp = SwiftLinkPreview(session: URLSession.shared,\n\t\t\t   workQueue: SwiftLinkPreview.defaultWorkQueue,\n\t\t\t   responseQueue: DispatchQueue.main,\n\t\t           cache: DisabledCache.instance)\n```\n\n#### Requesting preview\n```swift\nlet preview = slp.preview(\"Text containing URL\",\n                          onSuccess: { result in print(\"\\(result)\") },\n                          onError: { error in print(\"\\(error)\")})\n// preview.cancel() to cancel it.\n```\n**result** is a struct ```Response```:\n\n```swift\nResponse {\n\tlet baseURL: String? // base\n\tlet url: URL? // URL\n\tlet finalUrl: URL? // unshortened URL\n\tlet canonicalUrl: String? // canonical URL\n\tlet title: String? // title\n\tlet description: String? // page description or relevant text\n\tlet images: [String]? // array of URLs of the images\n\tlet image: String? // main image\n\tlet icon: String? // favicon\n\tlet video: String? // video\n\tlet price: String? // price\n}\n```\n\n#### Cancelling a request\n```swift\nlet cancelablePreview = slp.preview(...,\n\t\t\t\t    onSuccess: ...,\n\t\t\t\t    onError: ...)\n\ncancelablePreview.cancel()\n```\n\n#### Enabling and accessing cache\n\nSLP has a built-in memory cache, so create your object as the following:\n\n```swift\nlet slp = SwiftLinkPreview(cache: InMemoryCache())\n```\n\nTo get the cached response:\n\n```swift\nif let cached = self.slp.cache.slp_getCachedResponse(url: String) {\n    // Do whatever with the cached response\n} else {\n\t// Perform preview otherwise\n\tslp.preview(...)\n}\n```\n\nIf you want to create your own cache, just implement this protocol and use it on the object initializer.\n\n```swift\npublic protocol Cache {\n\n    func slp_getCachedResponse(url: String) -\u003e SwiftLinkPreview.Response?\n\n    func slp_setCachedResponse(url: String, response: SwiftLinkPreview.Response?)\n}\n```\n\n# FLOW\n\n![flow](http://i.imgur.com/SMueQkA.png)\n\n## Important\n\nYou need to set ```Allow Arbitrary Loads``` to ```YES``` on your project's Info.plist file.\n\n![app security](http://i.imgur.com/41hGjCC.png)\n\nIf you don't want to use the option above and you are using ```SwiftLinkPreview``` for services of your knowledge, you can whitelist them on Info.plist file as well. You can read more about it [here](http://stackoverflow.com/questions/30739473/nsurlsession-nsurlconnection-http-load-failed-on-ios-9), [here](https://github.com/Alamofire/Alamofire#app-transport-security) and [here](https://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/).\n\n![app security](http://i.imgur.com/INEp6q5.png)\n\n## Tips\n\nNot all websites will have their info brought, you can treat the info that your implementation gets as you like. But here are two tips about posting a preview:\n\n* If some info is missing, you can offer the user to enter it. Take for example the description.\n* If more than one image is fetched, you can offer the user the feature of picking one image.\n\n## Tests\n\nFeel free to fork this repo and add URLs on [SwiftLinkPreviewTests/URLs.swift](SwiftLinkPreviewTests/URLs.swift) to test URLs and help improving this lib. The more URLs the better the reliability.\n\n## Information and Contact\n\nDeveloped by [@LeonardoCardoso](https://github.com/LeonardoCardoso).\n\nContact me either by Twitter [@leocardz](https://twitter.com/leocardz) or emailing me to [contact@leocardz.com](mailto:contact@leocardz.com).\n\n## Related Projects\n\n* [Link Preview (PHP + Angular + Bootstrap)](https://github.com/LeonardoCardoso/Link-Preview)\n* [Android Link Preview](https://github.com/LeonardoCardoso/Android-Link-Preview)\n\n\n## License\n\n    The MIT License (MIT)\n\n\tCopyright (c) 2016 Leonardo Cardoso\n\n\tPermission is hereby granted, free of charge, to any person obtaining a copy\n\tof this software and associated documentation files (the \"Software\"), to deal\n\tin the Software without restriction, including without limitation the rights\n\tto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\tcopies of the Software, and to permit persons to whom the Software is\n\tfurnished to do so, subject to the following conditions:\n\n\tThe above copyright notice and this permission notice shall be included in all\n\tcopies or substantial portions of the Software.\n\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\tSOFTWARE.\n\n### Follow me for the latest updates\n\u003ca href=\"https://goo.gl/UC8B8o\"\u003e\u003cimg src=\"https://i.imgur.com/pac7UMq.png/\" width=\"179\" height=\"26\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLeonardoCardoso%2FSwiftLinkPreview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLeonardoCardoso%2FSwiftLinkPreview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLeonardoCardoso%2FSwiftLinkPreview/lists"}