2 ms·
Will absolutely cosign this. So many of Apple's components for both iOS and MacOS development are dreadfully over-complicated and the documentation if anything,
by ToucanLoucan 3y ago
Will absolutely cosign this. So many of Apple's components for both iOS and MacOS development are dreadfully over-complicated and the documentation if anything, makes it worse with no examples provided, no use cases, nothing. And of course is subject to change at the whim's of Apple's engineers.
So often as a developer I end up just creating a single-line static wrapper function that does something that interfaces with Apple code, then call that instead. Things like a share sheet are incredibly complicated for seemingly little if any actual need. Example: I have a static wrapper function for sharing that accepts the following parameters:
- The View Controller to present the share sheet from
- The originating view/button that it should be presented from (on iPad)
- The URL of the file
- A subject and message, either one, both or neither, appropriate to the share
And that's it. Five pieces of information. Inside that function I:
- Load the data from the file into a Data object, and confirm the URL is good
- Save a second copy of the file to the file system with the appropriate name I'd like it to show the user
- Convert the "Any" object passed into the button (view, button, bar button item, etc.) as a set of coordinates from which to spawn the popover, because Apple's code does not do this reliably
- Instantiate a Share Sheet Subject Body Provider, which is an object you have to provide the share sheet which contains... 2 strings
- Instantiate a UIActivityViewController, which is a subclass of View Controller using the subject/body provider and the URL to the file copy I created as the arguments for that
- Set the source view of that controller to an arbitrary View I've placed that's just the coordinates from earlier, with a height and width of 1, placed onto the view controller
- UNLESS it's a bar button item, in which case I set the bar button item property to that and skip the coordinates altogether
- Then I present this view controller on the origin view controller
And I'm sorry, I'm willing to grant that some of this complexity is down to engineering concerns I'm not aware of, or taking into account things I've never done. But holy. Shit. What a process to go through. To simply share a file as Apple intends, I need a class that is fifty lines of code, and a second class of another 20-ish lines, to provide subject and body. Which again, I cannot stress this enough, is TWO. STRINGS.
SURELY. SURELY SOMEHOW we could make this easier.