Is it possible to change scope for parts of playground (to play with access control) - swift

I curious is it possible to split Swift playground so that different parts will be in different source files, different modules?
Inside playground package I found file with format "section-1.swift", I tried to add "section-2.swift"... nothing. Any clues?
Update: I asked same question on dev forum https://devforums.apple.com/thread/239671?tstart=50

The "section" files inside a playground are all stitched together into a single implicit Swift source file, and treated as a single module.
To play with access control, you'll need to build an app project (possibly with an embedded framework target).

Related

Unable to select pre-registered files types using UIDocumentPickerViewController with with pre-iOS 14 target

I'm using a document picker to import data into an app. One of the files to import is a .GPX (it's actually an XML file of GPS data, but that's not relevant). I define a custom file type (as it's not covered by the standard file types covered within UniformTypeIdentifiers)
let documentsPicker = UIDocumentPickerViewController(documentTypes: ["com.sourceapp.gpx"], in: .open)
and register it in info.plist as a Document type, and include this in Exported type identifiers and, seeing as it is not a bespoke file type, in Imported type identifiers. These are all still required as the app target is pre-iOS 14 (for 14+ it's not necessary to add the items to info.plist).
This works fine in the simulator where it's a clean environment without any other apps installed. On a device however it doesn't work, and the file is greyed out and not selectable. I'm reasonably certain this is because a custom file type with the same extension is already registered by another app.
So how do I go about using a file type that has already been registered? There must be a "correct" way to go about this as it must be a common scenario.
My understanding was that this is what the Imported type identifiers was for, but I can't seem to get this to work. This may be because I'm not defining the imported type in exactly the same way as the first app to register it.
If so, how do I see what has already been registered, and reuse it? This would need to be a generic apprach as a scenario where a different app has already regsitered the file type but in a different way is highly likely for a common file type such as .gpx
As background, when using a pre-defined file type such as "public.comma-separated-values-text" for a CSV file all works fine.
UPDATE:
I've since seen as the bottom line of documentation that the exported type identifiers overrides imported type identifiers, so have tried deleting the exported one, butit makes no difference.

What's the difference between the library and applicationSupport directories?

xcode 9.2 ; swift 4
I want to persist some data for my ios app in the form of property lists. I don't want to use the Documents directory of the sandbox, since the user can manipulate it. I have two alternatives: the library directory and the applicationSupport directory. Is there an advantage in using one or the other?
Thanks in advance
I have two alternatives: the library directory and the applicationSupport directory. Is there an advantage in using one or the other?
Yes, Apple recommend you use Application Support.
Though a sandboxed app has its own private little file system hierarchy you are still expected to follow the guidelines as though the sandbox was not there.
Just remember, wherever you store the data the "user can manipulate it", hiding it in the sandbox is no deterrent to that.
HTH

VS Code Extension for Loading Source Code

I am interested in extending VS Code to load/edit/save project code, files, etc from a place other than the file system. For example, let's say I wanted to store my project in a database. I have looked at the extension API docs but didn't see anything obvious. Is there an API for extending VS Code in this way?
After some looking around it seems like you need to look at the "Workspace" section of the official API docs:
https://code.visualstudio.com/docs/extensionAPI/vscode-api#_workspace
The rootPath variable takes a string argument, but there's nothing saying that it needs to be a file path so perhaps there's some wiggle room there.
That being said the createFileSystemWatcher() method appears to be set up to work with an actual file system. So even if you can get VSC to find files from somewhere like a database - you probably can't use any of the events that update the UI on changing a file.

Unable to use third party Swift class extensions [duplicate]

Actually I spend around 3 hours in this simple problem and googled it a lot but no way.
My question is very simple. I want to add a directory as a "Folder Reference" to my Swift xCode project. But no way to access them.
I don't need to add then using Group Reference, any suggestions?
Update: if you are using folder references, there is no way to import them and you must reference them using the full directory path.
EX:
let image = UIImage(named: "Images/Icons/GoPago")
That is the only way. Depending on what your project requires, I would suggest using groupings like below.
The problem is that you are using folders and not grouping. There is no import needed. You just need to take everything in the folder and "group" it through xCode. Then you will be able to access it in your code. It should look as a yellow folder when you group it in there. Like so:
and it should look like this:
if you are copying over a directory, you would want to make sure to select create groups as follows. :
import TestFolder works on frameworks not on group creation , actually groups are shown only for good user experience for the developers, If you right click on groups you will not find any references.

Why don't the Target 8 files implement the project as described in the tutorial?

In Target 8: Define a Custom DOM Tag, the reader is told about custom DOM tags that can be created by extending other tags. A sample is described for an example called "x-converter" before listing the files as "These files implement the app:".
The three files are...
a drseuss.html file (not sure why there's a sudden deviation in the project name and the HTML file, as opposed to the matching names in previous tutorials...),
a converter-element.html file,
and a convertercomponent.dart file.
I tried creating a new application in the latest Dart editor, and replaced the default HTML file contents with that of drseuss.html, replaced the default dart file contents with that of convertercomponent.dart, and added converter-element.html file.
After fixing an include issue (the file from the tutorial refers to drseuss.css and not the default project name's CSS file), I only see the following in the Chromium browser.
As you can see, the element described in the tutorial (converter-element) doesn't show up. Why don't the files provided for the project result in what's shown in the tutorial?
For reference, here's what's shown in the tutorial.
Web UI requires the build.dart script which compiles the various components into the executable output HTML+Dart.
Take a look at the parent folder in the github src that you reference, and you will see the build.dart script.
In addition, you will need the pubspec.yaml from that folder, too, which includes web_ui package, which brings in the dwc tool(Dart Web Components compiler) used by build.dart.
Take a look at the article Tools for Web UI for more information about dwc and build.dart, and Target 6 - Getting Started with Web UI which covers similar ground, but in a tutorial format.