iOS9 Beta 2. valueForAttribute causing EXC_BAD_ACCESS

I am puzzled by this - seems to be new. Running XCode7 (beta1 and beta2 see same outcome)


I am calling...


if let metadataItem = metadataItem
        {
            if let value = metadataItem.valueForAttribute(NSMetadataUbiquitousItemIsUploadingKey) as? NSNumber  <- EXC_BAD_ACCESS
            {
                return Bool(value)
            }
        }

Seeing a hard crash when valueForAttribute is called. metadataItem appears perfectly valid.


Calling the same method with any string does the same.

Not happening in the simulator.

Replies

I can't tell if this is new because I'm using the following code:

- (BOOL)isUploading
{
    id value;
    NSError *error = nil;
   
    if ([self.document.fileURL getResourceValue:&value forKey:NSURLUbiquitousItemIsUploadingKey error:&error])
    {
        return [value boolValue];
    }
    else
    {
        return NO;
    }
}

This still works for me.


Dirk

Thanks.

I remain puzzled.

As far as I can tell, by turning on zombies...


metadataItem.valueForAttribute()


seems to be trying to access its metadataQuery object. Which is a bad idea, because in my code, the query has been deallocated at that point.


And now the log reports:


-[NSMetadataQuery _allAttributes]: message sent to deallocated instance 0x1370968a0

Hmm, that's strange.


I don't have this issue because I keep the query alive as long as the app runs.


But, I would expect either the NSMetaDataItem to hold a strong reference to it's NSMetaDataQuery if it needs it to be alive or to have ithe reference declared as weak to prevent sending messages to a deallocated instance.


I would first workaround this issue by either keeping the query alive as long your code somehow queries NSMetaDataItem or by using the code I provided in my first post.

Second I would file a bugreport with a small sampleproject to get things sorted out.


Dirk