Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage in swift raises exception #132

Open
mradke opened this issue May 15, 2016 · 4 comments
Open

Usage in swift raises exception #132

mradke opened this issue May 15, 2016 · 4 comments

Comments

@mradke
Copy link

mradke commented May 15, 2016

I am trying to connect to a local owncloud instance with swift using this library.
The app example you are providing is working fine with my local setup. I have successfully imported the libownCloudiOS.a library and header files as per the Readme instructions.

Now when I try to invoke the readFolder method, an exception is raised:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString encodeString:]: unrecognized selector sent to instance

The function provoking this error looks like:

let com = OCCommunication()
com.setCredentialsWithUser("admin", andPassword: "password")

var path = "http://cloud.local.dev/remote.php/webdav/"
path = path.stringByRemovingPercentEncoding!
print(path)

com.readFolder(path, withUserSessionToken: UtilsFramework.getUserSessionToken(), onCommunication: com, successRequest: { (response: NSHTTPURLResponse!, items: [AnyObject]!, token: String!, redirectServer:String!) in
        print("success")
                }, failureRequest: { (response: NSHTTPURLResponse!, error: NSError!, token: String!, redirectServer: String!) in
        print("failure")
    })
}

Am I missing some arcane "this does not work in swift/objc that way" gotchas?

@sumomoneko
Copy link

Exception rised here.

- (void) readFolder: (NSString *) path withUserSessionToken:(NSString *)token
    onCommunication:(OCCommunication *)sharedOCCommunication
     successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest
     failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{

    if (!token){
        token = @"no token";
    }

    path = [path encodeString:NSUTF8StringEncoding];  // HERE...

The method is defined in NSString+Encode.h and NSString+Encode.m ,
you might add these files to your project.

@TinkerToysCodeManufaktur

Has there been a solution or fix for this yet? I'm also trying to integrate this library into a Swift project but running into the exact same issue. Exposing NSString+Encode.h in the bridging header didn't make a difference, unfortunately. Thanks!

@zero0cool0
Copy link
Contributor

Did you set the -ObjC flag as advised in the installation notes?

@rvilarl
Copy link

rvilarl commented Oct 2, 2017

The installation notes advise -Obj-C. The problem disappears once -Obj-C is replaced by -ObjC. Could you fix the installation notes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants