user1764386
user1764386

Reputation: 5621

Dropbox iOS API - Simple Questions / DBRestClient Problems

EDIT:

I think I have fixed my issues. Thank you for the help - I really appreciate it.


Original Question:

I am new to objective-c and iOS programming, so hopefully my issues are not difficult to correct. I am trying to add the ability to open a file from Dropbox to my simple iOS application. I have been following the tutorial here:

http://www.mathiastauber.com/integration-of-dropbox-in-your-ios-application-making-api-calls/

I have so far successfully gotten my app to link to my Dropbox account and display the "link successful" message.

Now I am having trouble using the DBRestClient. I have the following code currently:

myviewcontroller.h

...
@end
DBRestClient *restClient;

myviewcontroller.m

- (DBRestClient *)restClient {
    if (!restClient) {
        restClient =
        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        restClient.delegate = self;
    }
    return restClient;
}

I am getting an error on the line

restClient.delegate = self;

that says "Assigning to 'id<DBRestClientDelegate>' from incompatible type 'myviewcontroller'"

What could be going wrong? I have read through every example I can find and can see no issues with what I am trying to do.

If I try to cast by doing the following, it does not work

restClient.delegate = (id)self;

I have also found that if I remove the code in myviewcontroller.m and only have the variable declaration in the header file (as shown above) I get an error that says "Apple Mach-O Linker Error"

I would greatly appreciate any help you can provide. I am very much stuck with this problem.

Upvotes: 0

Views: 1220

Answers (2)

John Parker
John Parker

Reputation: 54445

In your header file you need to specify that you adhere to the DBRestClientDelegate's protocol.

For example:

@interface MyViewController: UIViewController <DBRestClientDelegate>

If you're already adhering to other protocols, simply add the DBRestClientDelegate and comma seperate, such as...

@interface MyViewController: UIViewController <UITableViewDelegate, DBRestClientDelegate>

For more information, I'd recommend a read of the Delegation section of Cocoa Core Competencies, especially as you'll be encountering delegates (and indeed perhaps defining your own protocols, etc.) a lot in Cocoa.

Upvotes: 3

Jesse Black
Jesse Black

Reputation: 7986

The error is because the right side of restClient.delegate = self; is not of type id<DBRestClientDelegate>

id<DBRestClientDelegate> is basically any object that conforms to the DBRestClientDelegate protocol

The first step (maybe only step) to removing the error is in your Myviewcontroller.h file

change

@interface Myviewcontroller : UIViewController   //<-- my best guess at your interface line

to

@interface Myviewcontroller : UIViewController <DBRestClientDelegate>

Upvotes: 2

Related Questions