How to get spplaylist id? - cocoalibspotify-2.0

How do I have id of spplaylist ?
currently it returns
return [NSString stringWithFormat:#"%#: %# (%# items)", [super description], [self name], [NSNumber numberWithUnsignedInteger:[[self valueForKey:#"items"] count]]];
because of [self name] it contains it returns playlist name. What to do if I want it to return spplaylist id?
For playlist name keyvalue is #"name" , may I know what is the key value for id?

The unique identifier for a playlist is its URI, which can is in the spotifyURL property of all metadata objects, including SPPlaylist.

Related

Trying to add data from parse to an NSMutableArray in IOS

So, I am able to successfully perform a query of my parse database. This query matches the logged in user with all objects that have the logged in user in the key user. The object I'm querying has keys "email" "firstName" "lastName" "friendUserName" and "phoneNumber"
I would like to be able to store all the phone numbers into a mutable array named phoneNumbers. The code I am trying to use to do this is.
int i=0;
for (PFObject *object in objects) {
NSLog(#"%#", objects[i]);
phonenumber = object[#"phoneNumber"];
NSLog(#"%#", phonenumber);
[phoneNumbers[i] addObject:phonenumber];
NSLog(#"%#", phoneNumbers[i]);
i=i+1;
}
When I run this code the output for the code NSLog(#"%#", phoneNumbers[i]);
comes out a null both times. All other outputs are as expected.
The following should work for you:
NSMutableArray *phoneNumbers = [NSMutableArray new];
for (PFObject *object in objects) {
NSLog(#"%#", object);
// Assuming your phone numbers are stored as strings - use a different data type if necessary
NSString *phoneNumber = object[#"phoneNumber"];
NSLog(#"%#", phoneNumber);
[phoneNumbers addObject:phoneNumber];
}
NSLog(#"%#", phoneNumbers);
If you're just adding items to the end of a mutable array, you don't need to worry about the index of the items.
The place you were going wrong was when trying to add the object to your array. You were doing this:
[phoneNumbers[i] addObject:phonenumber];
Which is actually saying "fetch the object at index i in the phoneNumbers array, and tell it to add the phone number object". However, presumably your array is empty or not initialised, which means addObject will be sent to a nil object and so not have any effect. Instead, you simply need to tell the phoneNumbers array itself to add the object.

How to access first element of NSDictionnary

I wrote a method that takes in parameter a SQL requests (SELECT name FROM table) and return a NSDictionnary with first letter of word as key
Dictionnary
{
A = ("Arbre", "Armoise");
B = ("Bob", "Bill") ;
...
}
So I'm stuck with that, Now if my request look like SELECT name_en FROM table WHERE name_fr LIKE "Bob"
My dictionnary will look like :
Dic {
B = ("Bob");
}
And I just want to display Bob. So How can I get this value ? I already tried objectAtIndex and [[dic allKeys] objectAtIndex:0];
But I got nothing
Thanks !
There is no such thing as the "first object" in a dictionary. A dictionary is an unordered collection.
I'm not 100% certain what you're asking but what you could do is take the array of keys...
NSArray *keys = [dictionary allKeys];
and then sort the array
NSArray *sortedKeys = [keys sortedArrayUsing... // choose your own method for sorting
Then get the object related to the first sorted key...
id firstObject = dictionary[[sortedKeys firstObject]];

How can I get the NSManagedObjectID of an object directly after saving?

How can I get the NSManagedObjectID of an object directly after saving?
I've tried using the NSNotification NSManagedObjectContextDidSaveNotification and getting the updated/inserted values and getting the object id from one (the only) managed object, but it's giving me "Unrecognized Selector" when I try to grab the object id.
Can I even get the Object Id right after I save?
- (void)handleDidSaveNotification:(NSNotification *)note
{
NSDictionary *dict = [note userInfo];
NSDictionary *updatedDict = [dict valueForKey:#"updated"];
NSLog(#"Notification: %#", dict);
NSLog(#"Updated Info: %#", updatedDict);
NSManagedObject *core = [updatedDict valueForKey:#"entity"];
NSManagedObjectID *objectId = [core objectID];
}
You are trying to set a dictionary (updatedDict) when the returned data is a NSSet.
you might simply need to get it from the set collection it is in ...
NSSet* s = [dict valueForKey:#"updated"];
[s valueForKey:#"objectID"]
This will return a set of NSManagedObjectIDs.
See NSSet on how to access objects.

How do I store this object in my iOS class?

I am creating my first Master-Detail application for iOS.
I want to store the following
Name
Web URL
In my UITableView, I plan on displaying only the name (sorted) but when the name is tapped, another view will load with a button that will launch Safari with the WebURL
I tried using an MSMutableArray but discovered it's not sortable. Same is true with an NSDictionary.
Any ideas (or sample or links to samples) would be appreciated
I am trying to use methods that are not deprecated in iOS 7.0
and plan on supporting iOS 6
earlier versions are a + but I can live without support for 3,4,5.
An NSMutableArray with an NSDictionary for each item is perfectly fine. You can sort it.
NSMutableArray *rows = #[].mutableCopy;
[rows addObject:#{#"name": #"Bob", #"url": [NSURL URLWithString:#"http://bob.com"]}];
[rows addObject:#{#"name": #"Alice", #"url": [NSURL URLWithString:#"http://alice.net"]}];
NSLog(#"%#", rows);
[rows sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [[obj1 valueForKey:#"name"] compare:[obj2 valueForKey:#"name"] options:NSNumericSearch];
}];
NSLog(#"%#", rows);
Output:
2013-07-20 00:33:31.682 MyApp[28496:303] (
{
name = Bob;
url = "http://bob.com";
},
{
name = Alice;
url = "http://alice.net";
}
)
2013-07-20 00:33:31.682 MyApp[28496:303] (
{
name = Alice;
url = "http://alice.net";
},
{
name = Bob;
url = "http://bob.com";
}
)
You can sort NSArrays, you just have to write the comparison function yourself because NSArrays store objects, and how to you sort objects that contain potentially thousands of values. There is a good post about it here. That should hopefully get the job done.
How to sort an NSMutableArray with custom objects in it?

getting the object value in key in dictionary

I have a dictionary with key-value pair populated from JSON returned data.What I wish to do is use the dictionary to populate UITableView.
I have this structure for table:
[Product Name]
By [Manufacturer Name]
What this means is that key is Product Name and Value is Manufacturer Name. I need to get the name of the key and the name of the value. How can this be done? and is it possible without for-loop?
I'd use the enumerateKeysAndObjectsUsingBlock: method. The following code builds a list of the strings you require.
NSMutableArray *names = [NSMutableArray array];
[dictionary enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSString *object, BOOL *stop) {
[names addObject[NSString stringWithFormat:#"%# By %#",key, object]];
}];
You can use the keyEnumerator of NSDictionary and for each key look up the value. This could look something like this:
for (NSString *p in dict)
{
NSString *m = [dict objectForKey:p];
// do something with (p,m)
}
You should not be concerned with avoiding for-loops. After all, something like a for loop will always happen somewhere underneath.
If your keys are dynamic from json then you can use
NSArray *keys = [dictionary allkeys];
Then in the table View Cell for row at index path method you can populate the table view with the corresponding keys and their values.
NSArray * keys = [results allKeys];
for (int i = 0;i<[keys count];c++){
NSString* productName = [key objectAtIndex:i];
NSString* manufacturerName = [results objectForKey:productName];
}
Hope this helps...
I have assumed the name as strings, you can change the type according to your situation..

Resources