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

[NSTextStorage readFromURL:options:documentAttributes:error] #21

Open
nickasd opened this issue Mar 2, 2019 · 4 comments
Open

[NSTextStorage readFromURL:options:documentAttributes:error] #21

nickasd opened this issue Mar 2, 2019 · 4 comments
Assignees

Comments

@nickasd
Copy link

nickasd commented Mar 2, 2019

The converted code generates the compiler error Cannot invoke 'read' with an argument list of type '(from: URL, options: [NSAttributedString.DocumentReadingOptionKey : String], documentAttributes: inout [AnyHashable : Any])'.
http://swiftify.me/8oosqh

@tomattoz
Copy link
Collaborator

tomattoz commented Jul 24, 2020

We need intermediate variable here, like this:

        let textStorage: NSTextStorage? = nil
        var documentAttributes: [AnyHashable : Any]?

        do {
            if let url = url {
                var nsDictionary: NSDictionary?
                
                try textStorage?.read(from: url, options: [
                    NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.plain
                ], documentAttributes: &nsDictionary)
                
                documentAttributes = nsDictionary as? [AnyHashable : Any]
            }
        } catch {
        }

But it looks like this is impossible to do in metadata. @alex-swiftify what do you think?

@tomattoz
Copy link
Collaborator

Also we can solve this by cancelling conversion of NSDictionary to swift dictionary if explicitly need NSDictionary somewhere in method calls. And the same for another types like NSArray, NSError ...

@alex-swiftify
Copy link
Member

@tomattoz I agree that looks difficult.
You could try generating multiple lines of code via metadata translations by adding \n or \t characters, but the [_textStorage readFromURL] method has a return value and that could be problematic if this call is nested.
You can still give that a try anyway - providing it works for 80% of cases and don't take "hours" of work.

We already have similar reports like https://swiftify.atlassian.net/browse/SWC-875 but they look difficult.

@alex-swiftify
Copy link
Member

Also we can solve this by cancelling conversion of NSDictionary to swift dictionary if explicitly need NSDictionary somewhere in method calls. And the same for another types like NSArray, NSError ...

This looks like the way to go here.
There are some existing mappings that cast back to NSArray/NSString/NSDictionary and call their methods.
Try reusing that approach.

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

3 participants