Skip to content

Commit

Permalink
add get length
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Sep 6, 2023
1 parent f3c95ef commit 719b931
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions contracts/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ access(all) contract ExampleNFT: NonFungibleToken, ViewResolver {
return self.ownedNFTs.keys
}

/// Helper method for getting the number of NFTs stored in the collection
///
/// @return An Integer representing the number of NFTs
///
access(all) view fun getLength(): Int {
return self.ownedNFTs.keys.length
}

/// Gets a reference to an NFT in the collection so that
/// the caller can read its metadata and call its methods
///
Expand Down
3 changes: 3 additions & 0 deletions contracts/NonFungibleToken-v2.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ access(all) contract NonFungibleToken {
/// getIDs returns an array of the IDs that are in the collection
access(all) view fun getIDs(): [UInt64]

/// Gets the amount of NFTs stored in the collection
access(all) view fun getLength(): Int

/// getIDsWithTypes returns a list of IDs that are in the collection, keyed by type
/// Should only be used by collections that can store multiple NFT types
access(all) view fun getIDsWithTypes(): {Type: [UInt64]}
Expand Down
Loading

0 comments on commit 719b931

Please sign in to comment.