TweetieFeed - Twitter feeds for SwiftUI

Overview

TweetieFeed

Swift 5.3 Platforms License

Twitter feeds for SwiftUI

Supports:

  • Twitter API v1.1 and v2
  • iOS 14+
  • Xcode 13+

Installation

Add the package to Package.swift dependencies:

dependencies: [
    .package(url: "https://github.com/ugalek/TweetieFeed.git", from: "0.1.0")
]

Usage

Import TweetieFeed:

import TweetieFeed

In your App struct, initialize a TweetieFeedUISettings instance as StateObject, then give this instance to environmentObject:

struct MyApp: App {
    @StateObject var uiSettings = TweetieFeedUISettings()
    
    var body: some Scene {
        WindowGroup {
            ContentView(viewModel: ExampleViewModel())
                .environmentObject(uiSettings)
        }
    }
}

TweetieFeedUISettings takes the following optional parameters to customize the view:

Parameter Description
backgroundDark Color change background color UI at the dark mode
backgroundLight Color change background color UI at the light mode
tweetBackgroundDark Color change tweet background at the dark mode
tweetBackgroundLight Color change tweet background at the light mode
tweetBorderDark Color change tweet border at the dark mode
tweetBorderLight Color change tweet border at the light mode
retweetedStatusTextColor Color.secondary by default: change retweeted status text
footerTextColor Color.gray by default: change text in the footer (retweet & favorite)
tweetBodyCornerRadius CGFloat 15 by default: change corner radius tweet card
localeIdentifier String by default "en_US": change locale to display the date

In your view model, use TweetieFeedDecoder to decode the data according the API version:

class YourViewModel: ObservableObject {
    var feedDecoder: TweetieFeedDecoder?
    
    init(feedDecoder: TweetieFeedDecoder? = nil) {
        self.feedDecoder = feedDecoder
    }
    
    func getData(version: TwitterAPIVersion = .v1) {
        // Fetch Twitter API data here
        ...
        let task = URLSession.shared.dataTask(with: request) { data, _, _ in
            DispatchQueue.main.async {
                self.feedDecoder = TweetieFeedDecoder(data: data, version: version)
            }
        }
        task.resume()
        ...
    }
}

In your SwiftUI view, declare a TweetieFeedView with the TweetieFeedDecoder instance created before:

VStack {
    ...
    TweetieFeedView(tweetieDecoder: viewModel.feedDecoder)
    ...
}
.onAppear {
    viewModel.getData()
}

Don't forget to add the onAppear modifier that calls the view model method that handles data fetching and decoding.

You can find an example in the Example folder.

Twitter API fields (required / recommended)

v1.1

tweet_mode=extended is required.

v2

These fields are recommended for best display but not required.

expansions:

  • attachments.media_keys
  • author_id is required
  • entities.mentions.username
  • in_reply_to_user_id
  • referenced_tweets.id

tweet.fields:

  • attachments
  • author_id
  • created_at is required
  • entities
  • id
  • in_reply_to_user_id
  • possibly_sensitive
  • public_metrics
  • reply_settings
  • text

user.fields:

  • created_at
  • description
  • entities
  • id
  • name
  • profile_image_url
  • username

media.fields:

  • heigh
  • media_key
  • preview_image_url
  • type
  • url
  • width

Buy Me A Coffee

License

TweetieFeed is under MIT license. See the LICENSE file for more info.

You might also like...
SwiftUI Projects from Udemy SwiftUI Masterclass

SwiftUI Masterclass Repos: AsyncImage (N/A) Fructus (finished): an app for getting information about different fruits. Data comes from json files. Afr

Best architecture for SwiftUI + CombineBest architecture for SwiftUI + Combine

Best architecture for SwiftUI + Combine The content of the presentation: First of the proposed architectures - MVP + C Second of the proposed architec

Weather-swiftui - An example of using SwiftUI

weather-swiftui An example of using SwiftUI Installation Get openweather api key

Orbit-swiftui - Orbit design system implemented in SwiftUI for iOS

Orbit is a SwiftUI component library which provides developers the easiest possi

SwiftUI Resume - A simple resume writed by swiftUI + Combine
SwiftUI Resume - A simple resume writed by swiftUI + Combine

SwiftUI_Resume a simple "resume" writed by swiftUI + Combine

SwiftUI-MSALSample - Sample project to login with MSAL using SwiftUI
SwiftUI-MSALSample - Sample project to login with MSAL using SwiftUI

SwiftUI-MSALSample I could not find a good walkthrough on how to implement MSAL

100-Days-of-SwiftUI - Studying through Paul Hudson's 100 Days of SwiftUI
100-Days-of-SwiftUI - Studying through Paul Hudson's 100 Days of SwiftUI

Hacking with SwiftUI 100 Days of SwiftUI Studying through Paul Hudson's "100 Day

Watchos-navlink-swiftui-bug - Example Project to demonstrate bug in SwiftUI when NavigationLink is activated inside a TabView SwiftUI-Card - Simple card ui designed using SwiftUI
SwiftUI-Card - Simple card ui designed using SwiftUI

SwiftUI - Card Simple card ui designed using SwiftUI Preview

Releases(0.1.0)
Owner
Galina
iOS Developer
Galina
small iOS & ipadOS application written in SwiftUI and Combine, that fetches twitter users and tweets using Twitter's api

HomeTwitter Small iOS & ipadOS application written in SwiftUI and Combine, that fetches twitter users and tweets using Twitter's api. This is just a s

Sorin Miroiu 1 May 13, 2022
A Safari extension that redirects Twitter, YouTube, Reddit, and more to privacy friendly alternatives.

Privacy Redirect for Safari A configurable web extension that redirects Twitter, YouTube, Reddit, Google Maps, Google Search, and Google Translate to

null 101 Dec 16, 2022
A basic twitter app to view, compose, favorite, and retweet tweets

A basic twitter app to view, compose, favorite, and retweet tweets

Kaya Yeboah 0 Nov 4, 2021
Twitter Clone With Swift

Project 3 - Twitter App Part 1 *Twitter Clone is a basic twitter app to read your tweets. Time spent: 3 hours spent in total User Stories The followin

null 0 Dec 20, 2021
Mastodon and Twitter client for iOS, iPadOS & macOS

Note: Mamoot! is under heavy development and is obviously far from complete at this moment. We're currently looking for more people to work with us, s

null 13 Nov 22, 2022
iOS Swift + Node.js app to manage and schedule twitter posts

PostManager iOS Swift + Node.js app to manage and schedule twitter posts (like buffer) Post Manager is an app built by me in free time, it's main feat

Tomasz Baranowicz 83 Aug 8, 2022
🎲 100% SwiftUI 2.0, classic 2048 game [SwiftUI 2.0, iOS 14.0+, iPadOS 14.0+, macOS 11.0+, Swift 5.3].

swiftui-2048 If you like the project, please give it a star ⭐ It will show the creator your appreciation and help others to discover the repo. ✍️ Abou

Astemir Eleev 174 Dec 17, 2022
A simple SwiftUI Application to demonstrate creation of UI using SwiftUI.

WatchShop_UI A simple SwiftUI Application to demonstrate creation of UI using SwiftUI. How to run the project ? Fork the project. Run the project usin

Shubham Kr. Singh 12 Apr 15, 2022
E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy.

Touchdown-SwiftUI E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy. Main components and concepts used: @EnvironmentOb

Jorge Martinez 5 Aug 18, 2022
A multiplatform SwiftUI project demonstrating various SwiftUI features.

WikiDemo A multiplatform SwiftUI project demonstrating various SwiftUI features, including creating a master-detail interface. It's a multiplatform ve

Swift Dev Journal 6 Oct 17, 2022