Set, remove, edit, increment, or decrement Profiles attributes on iOS

Use the following example code to interact with Profiles attributes.

The Localytics SDK sets an anonymous customer ID for app installs where there is no customer ID explicitly set. If Profiles values are set prior to setting a customer ID, the profile information will be set to the anonymous customer ID for the install and is still available for targeting.
Note: Allowable property names must be NSStrings and cannot be nil, empty strings, or begin with an underscore ("_"). Property values must be either single instances or an NSArray of: NSString, NSNumber, NSDate, NSNull, or nil.

If you're going to collect dates, add the following dateFormatter to your code.

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
// to set a profile attribute:
[Localytics setValue:@45 forProfileAttribute:@"Age" withScope:LLProfileScopeOrganization];
[Localytics setValue:@[@8, @13] forProfileAttribute:@"Lucky numbers" withScope:LLProfileScopeApplication];
[Localytics setValue:[dateFormatter dateFromString:@"11-23-1962"] forProfileAttribute:@"Birthday" withScope:LLProfileScopeOrganization];
[Localytics setValue:@[[dateFormatter dateFromString:@"10-01-2015"], [dateFormatter dateFromString:@"03-17-2016"]] forProfileAttribute:@"Upcoming sales calls" withScope:LLProfileScopeApplication];
[Localytics setValue:@"New York, New York" forProfileAttribute:@"Hometown" withScope:LLProfileScopeOrganization];
[Localytics setValue:@[@"New York", @"California", @"South Dakota"] forProfileAttribute:@"States visited" withScope:LLProfileScopeApplication];

// to remove a profile attribute:
[Localytics deleteProfileAttribute:@"Days until graduation" withScope:LLProfileScopeApplication];

// to add a set of values to an already-defined set of values:
[Localytics addValues:@[@222] toSetForProfileAttribute:@"Lucky numbers" withScope:LLProfileScopeApplication];
[Localytics addValues:@[[dateFormatter dateFromString:@"04-19-2015"], [dateFormatter dateFromString:@"12-24-2015"]] toSetForProfileAttribute:@"Upcoming sales calls" withScope:LLProfileScopeApplication];
[Localytics addValues:@[@"North Dakota"] toSetForProfileAttribute:@"States visited" withScope:LLProfileScopeApplication];

// to remove a set of values from an already-defined set of values:
[Localytics removeValues:@[@8, @222] fromSetForProfileAttribute:@"Lucky numbers" withScope:LLProfileScopeApplication];
[Localytics removeValues:@[[dateFormatter dateFromString:@"03-17-2016"]] fromSetForProfileAttribute:@"Upcoming sales calls" withScope:LLProfileScopeApplication];
[Localytics removeValues:@[@"California"] fromSetForProfileAttribute:@"States visited" withScope:LLProfileScopeApplication];

// to increment or decrement an already-defined value:
[Localytics incrementValueBy:1 forProfileAttribute:@"Age" withScope:LLProfileScopeOrganization];
[Localytics decrementValueBy:3 forProfileAttribute:@"Days until graduation" withScope:LLProfileScopeApplication];