Skip To Content

Access your content

In this topic

After you successfully connect to a portal or subscription within a portal using valid credentials, the user property on AGSPortal contains a valid AGSPortalUser object representing a registered user.

Your items

An item is a unit of content in the portal. It is represented by an object of type AGSPortalItem. An item contains binary or textual data, and metadata describing the item. Items can be of various types such as web maps, tile packages, feature collections, and so on. Some types, such as globe documents or map templates, may only be relevant to desktop systems.

Based on item ID

Each item has a unique identifier. If you know the identifier, instantiate an AGSPortalItem object using it as follows:

let portal:AGSPortal = ... //The portal where the item resides
let portalItem = AGSPortalItem(portal: portal, itemId: "<item_id>")
When you instantiate the AGSPortalItem object, the item's metadata is fetched from the portal in the background. To verify the metadata was fetched properly, set one of your classes as the item's delegate:
portalItem.delegate = self

Your class must also adopt the <AGSPortalItemDelegate> protocol in the swift file and implement the relevant methods:

class MyViewController: NSViewController, AGSPortalItemDelegate {

 func portalItemDidLoad(portalItem: AGSPortalItem!) {
  //now it is safe to access the item's properties
 func portalItem(portalItem: AGSPortalItem!, didFailToLoadWithError error: NSError!) {
  //handle or report the error


Even when the item's metadata is loaded, the item's data is not retrieved. The binary or textual data needs to be explicitly fetched using fetchData. This allows a developer to work with an item using a minimum amount of memory and delay fetching the data until when it is needed.

Based on ownership

If you dont know the item's unique identifier, or if you want to access all items that belong to you, use the method fetchContent on AGSPortalUser. This returns a list of your folders and items you own that reside outside these folders. You can then use fetchContentInFolder: to retrieve items within a specific folder.

let portalUser:AGSPortalUser = ...  //The user who own the items


Portals do not currently allow sub-folders within a folder.

The results of fetchContent and fetchContentInFolder: are provided to the delegate of AGSPortalUser. Set one of your classes as the delegate to get these results or be informed of errors that occurred.

portalUser.delegate = self

Your class must also adopt the <AGSPortalUserDelegate> protocol in the swift file and implement the relevant methods:

class MyViewController: NSViewController, AGSPortalUserDelegate {

	func portalUser(portalUser: AGSPortalUser!, operation: NSOperation!, didFetchContent items: [AnyObject]!, folders: [AnyObject]!, inFolder folderId: String!) {
  //process the items
  for item in items as [AGSPortalItem] {
  //also iterate through the folders and fetch items within them
  for folder in folders as [String] {
 func portalUser(portalUser: AGSPortalUser!, operation op: NSOperation!, didFailToFetchContentInFolder folderId: String!, withError error: NSError!) {
  //handle or report the error

Your groups

You can get information about the groups you belong to from the groups property on AGSPortalUser. This property contains an array of AGSPortalGroup objects that contain information about each group. Each group has a unique group identifier. You can use this identifier to search the portal for items belonging to that group.

let groups = portalUser.groups
for group in groups as [AGSPortalGroup] {
 //display group to the user
 //or fetch items within each group