Nicholas Warren
Nicholas Warren

Reputation: 1

Creating a NSURL from an NSURL instance variable - invalid pointer

I have an object that defines a property as an NSURL:

@interface fcpElement : NSObject
@property (copy) NSString* elementName;
@property (copy) NSURL* elementPath;
@property (copy) NSURL* elementParent;
@property () BOOL elementIsHidden;
@property (copy) NSString* elementType;

-(id)initWithName : (NSString*) elementName path: (NSURL*) elementPath parent: (NSURL*) elementParent hiddenValue: (BOOL) elementIsHidden type: (NSString*) elementType;

@end

In my app controller I create an NSMutableArray and populate it with my objects using my init… method. I then have a button which calls a method on the app controller which creates a new NSURL by calling the instance variable from an object in the array, as follows:

for(currentElement in _finalCutData) {
    NSURL *currentElementPath = [currentElement elementPath];

Eventually I am wanting to do a comparison to see if this new URL is equal to another, but I always get errors that stop my program if I do anything like the following:

NSURL *currentElementPathAbsolute = [currentElementPath absoluteURL];

with the error: -[__NSCFString absoluteURL]: unrecognized selector sent to instance

If I add a breakpoint it says that currentElementPath is an invalid pointer. But if I NSLog [currentElement elementPath] I get the URL contained within.

How do I get the URL from my instance variable such that I can use it? Am I using the wrong parameter types in my property declarations? Or is it something else?

Upvotes: 0

Views: 299

Answers (2)

Mike Abdullah
Mike Abdullah

Reputation: 15013

Your problem is most likely that this call:

[currentElement elementPath];

is returning a string, not a URL. How is -elementPath implemented? Are you seeing any compiler warnings?

I assume -elementPath is implemented to be a simple getter method (perhaps as an @property). In which case, the fault lies in whatever code is storing that value in the first place.

Are you using ARC or manual memory management? If the latter, there's also a chance you've got a zombie here. You're not retaining the URL, and so it's being deallocated, and later replaced with a string.

Upvotes: 1

Mark Leavenworth
Mark Leavenworth

Reputation: 61

I'm surprised it seems I can help on this forum, since I'm a bit of a beginner, but the NSURL class has initialization methods that you should use, like initFileURLWithPath: You probably shouldn't override the NSURL initialization methods.

Upvotes: 0

Related Questions