I want to use indexPath.row in realm swift.

Asked 2 years ago, Updated 2 years ago, 293 views

As per the title, I want to use indexPath.row, but the property I want to use is .self, so I can't use it.

private values=Results<Tweet>?.self{
        DidSet {collectionView.reloadData()}
}

I want to display as much as I have saved, but I can't do it because it's a meta type.

override function collectionView(_collectionView:UICollectionView, cellForItemAtindexPath:IndexPath) ->UICollectionViewCell{
        letcell=collectionView.dequeueReusableCell(withReuseIdentifier:reuseIdentifier, for:indexPath) as!TweetCell
//        lettweetObject = Tweet(value:type(of:tweets[indexPath.row]))
//        letweetObject = tweets.map (indexPath.row)
        lettweetObject=type(of:tweets) [indexPath.row]
        cell.tweets=tweetObject
        return cell
}

Value of type'Results?.Type.Type'hasno subscripts
I can't use it because I got an error.
How can I use indexPath.row?
If you are familiar with Realm, please let me know.

swift realm

2022-09-30 21:50

1 Answers

I think that writing vartweets=... made it a less common code to substitute a type into a variable, so that the compiler did not auto-correct well and only corrected the compilation error as the compiler said, resulting in a code that uses meta-types.

Perhaps what I wanted to do was to define variables as type annotations using vartweets:Results<Tweet>? and colon instead of substituting.

private values:Results<Tweet>?{
    DidSet {collectionView.reloadData()}
}

This way, the tweets variable can be defined as a variable of type Results<Tweet>?.

Results complies with the array protocol so that it can be treated the same way as an array, so you can honestly use indexPath.row to retrieve the value of the specified location.

let tweetObject=tweets?[indexPath.row]

You can write like this.


2022-09-30 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.