Home > Back-end >  Swift searchRecentTweets function expected parameter Set<Tweet.Field>
Swift searchRecentTweets function expected parameter Set<Tweet.Field>

Time:09-14

hello I am using swift on xcode 13.4.1 with Twift library for twitter (https://github.com/daneden/Twift) trying to send a request to fetch tweets with a query this is the code :

import UIKit
import Twift
import SwiftyJSON

class ViewController: UIViewController {

@IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var sentimentLabel: UILabel!

let twift = Twift(appOnlyBearerToken: myToken)
override func viewDidLoad() {
    super.viewDidLoad()
    Task {
        let result =  try await **twift.searchRecentTweets**(query: "Apple",
        fields: Set<weet.Field>, 
        maxResults: 100).data
        for r in result{
          print(r.text)
           }
         }
      }
    }

i am having a problem on this line (fetching the tweets) :

 let result =  try await twift.searchRecentTweets(query: "Apple",fields: , 
 maxResults: 100).data

I need my tweets to return as english language only. the fields parameter is expecting Set<Tweet.Field> , I don`t know how to accomplish that. this is what i found out via sources about the type field declarationfield

My aim is to change the lang in the query field to english -"en"

please help

CodePudding user response:

The fields parameter is a set of additional fields to be returned on the tweet objects. If you don't need any additional fields, you can supply an empty set [].

To return only English language tweets, you need to modify the query you are sending to Twitter:

let result =  try await twift.searchRecentTweets(query: "Apple lang:en",fields:[] ,maxResults: 100).data
  • Related