TheM4hd1 / SwiftyInsta

Instagram Private API Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

avatar arbitrarily picks the first available entry in hdProfilePicVersions

mycroftcanner opened this issue · comments

avatar arbitrarily picks the first available entry in hdProfilePicVersions

    public var avatar: URL? {
        return rawResponse.hdProfilePicVersions
            .array?
            .first?
            .url
    }

The main issue is that it can be the lowest available quality :

image

This will select the profile picture url that has the highest quality:

    public var avatar: URL? {
        return rawResponse.hdProfilePicVersions
            .array?.sorted(
        by: {
            guard case .number(let lhs) = $0["width"], case .number(let rhs) = $1["width"] else { return false }
            return lhs.intValue > rhs.intValue
        }
        ).first?["url"].url

It does, you're right 💪
I was under the impression avatars were sorted like generic Media by size, but apparently they're not.
Definitely fixing it in #96.