问题标签 [document-based]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
531 浏览

xcode - What does "Document is distributed as a bundle" mean?

I am using Xcode 7.3.1 to create a Cocoa document based application. I notice that in the Document Types info panel there is an option that I don't understand. It says "Document is distributed as a bundle" and it looks like this.

Bundle Option Screenshot from Xcode

I found that this option controls the LSTypeIsPackage key for CFBundleDocumentTypes in the app's Info.plist file. I was able to find only two explanations of the usage of this key in Apple's official documentation. Both were very brief entries in relatively large tables.

The first explanation from the App Creation Process Overview. It is very brief and offers no more information than the screenshot above.

A Boolean value specifying whether the document is distributed as a bundle. If NO, omit this value.

The second explanation is a little more helpful. It comes from the Mac Developer Library's Information Property List Core Foundation Keys Reference.

Specifies whether the document is distributed as a bundle. If set to true, the bundle directory is treated as a file. (In OS X v10.4 and later, this key is ignored if the LSItemContentTypes key is present.)

It almost sounds as if this option affects how the application bundle itself is treated by the OS. If that's the case then I really have no idea what to make of these descriptions.

I know that many document types (such as .xcodeproj documents) are actually directories. Does this setting control whether documents are directories?

0 投票
1 回答
542 浏览

xcode - 在 Cocoa 应用程序上禁用基于文档的功能

我在 XCode 上为 MacOS 项目启动了一个基于文档的项目。我现在意识到我不需要这个功能,它可能会导致我的进度出现问题和延迟。

有没有办法禁用此功能?

0 投票
0 回答
207 浏览

swift - NSDocumentController 实例何时在基于文档的模板项目中默认实例化?

我使用 swift 3.0.1 在 maxOS 10.11.6 上的 Xocode 8.0 中创建了一个基于文档的 Cocoa 项目。我删除了mainMenu.xib、document.xib,修改了infolist,然后添加了自己的main函数。因为我根本不使用 Interface Builder。

在 Document.swift 中,我删除了 windowNibFille 变量,并覆盖了 makeWindowController() 函数,如下所示:

我没有做任何其他事情。如果我构建项目,我不应该得到菜单、窗口、运行已编译应用程序的文档,因为我没有实例化任何 NSDocumentController 实例,也没有实例化 NSDocuement 或 NSWindow 实例。

但他的现实是我运行了这个项目,显示了一个名为 untitled 的窗口。这很烦人,似乎在一个几乎空的项目中存在一些不可见的代码。我想在打开无标题文档之前做一些事情,如果 NSDocumentController 实例是在我的控制之外创建的,我应该怎么做?

0 投票
0 回答
72 浏览

macos - 关闭窗口时未释放文档?

我有一个基于文档的应用程序,当我关闭窗口时,我的 NSDocument 子类和 NSWindow 子类没有被释放。知道如何解决这个问题吗?

0 投票
1 回答
498 浏览

swift - 如何向基于文档的 Swift 3 应用程序添加简单的保存加载功能?

我目前正在研究 Swift(只是一种爱好),并试图弄清楚我应该如何在基于文档的 swift 应用程序中将函数保存和加载到 document.swift 文件?我想知道如何保存和加载简单的 txt 文件。我正在使用 NSTextView,所以我想我必须将其更改为 NSString?

以下是目前的这些功能:

0 投票
1 回答
65 浏览

xcode - 使自定义文档在 macOS Finder 中显示正确的“Kind”属性而不是“DocumentType”

在基于文档的应用程序中,我创建了具有自定义 UTI 和扩展名的文件。我在目标的 Info>Document Types 和 Info>Exported UTIs 窗格中声明了这两个,如下图所示。

我能够在 finder 中找到这些文件,它们显示正确的扩展名,并在应用程序中适当地打开。但是,他们仍然在 finder 中将其“种类”属性显示为“DocumentType”。

这是我在 xCode 中声明的问题,还是需要在我的 mac 查找器中刷新的问题?是否有人看到这些在 XCode 中的输入方式存在问题。

在此处输入图像描述

0 投票
5 回答
2534 浏览

cocoa-touch - Having Trouble Getting the UIDocumentBrowserController to open docs in a Document based app

I've been working on a new Document-based app, and was super glad about the new UIDocumentBrowserController...trying to roll my own solution for the document browser UI was tricky!

I'm having some trouble getting the browser to open documents after they've been created.

What happens now is that when I choose to create a new document in the document browser, the document is created and opened as expected, although an error message is logged. However, after the doc is closed, I cannot reopen the file, either immediately or upon subsequent launches, even though the document is displayed. However, a weird clue here is that if I stop running the app after creating the document, but without adding new information to it (triggering the save cycle), and run the project again, I can open the file correctly. Whuch makes me think that there's something in the way the files are being saved that is the issue. (Note: At this phase, I'm working on getting the local, non/icloud implentation working, before I move on to the icloud implementation.)

Here is the error message at any point in the code whenthe document is saved to disk (or at least most of the time!): 2017-06-20 13:21:58.254938-0500 Sermon Design 2 iOS[22454:5000138] [default] [ERROR] Could not get attribute values for item file:///Users/stevenhovater/Library/Developer/CoreSimulator/Devices/9A4364F2-B3A1-4AD9-B680-FB4BC876C707/data/Containers/Data/Application/DD534ED8-C4A3-40FE-9777-AED961976878/Documents/Untitled-9.sermon. Error: Error Domain=NSFileProviderInternalErrorDomain Code=1 "The reader is not permitted to access the URL." UserInfo={NSLocalizedDescription=The reader is not permitted to access the URL.}

I suspect that the issue lies somewher in my document types plists, which I've tried to set up by imitating the setup in the video for wwdc 2017 session 229.

enter image description here My docs are encapuslated by an NSData object, using what I take to be a pretty standard subclass implentation of UIDocument. (I'm omitting the code to generate the thumbnails)

In my subclass of UIDocumentBrowserViewController, Here is my code for getting a local filename and for creating the new document.

0 投票
2 回答
59 浏览

php - 如何为基于文档的数据库正确准备 XML 文件?

在 PHP 中将 XML 转换为 JSON 时,如何将 @attributes 移动到该元素的根?

我发现将 XML 文件转换为json_encode. 但是我想摆脱@attributes idname例如直接在根目录下,因为我会将所有内容直接导入数据库以进行操作和计算。(数据是从 7 天到死的好奇)。

我怎样才能轻松地将这些 XML 文件转换为 json,然后我可以将它们导入我的数据库而没有那些丑陋的@attributes?我理解他们的目的,但我在这里不需要他们,如你所见。

小样本:

非常小的应该看起来像:

0 投票
2 回答
2361 浏览

ios - iOS 11 上的 UIDocument 创建:不允许阅读器访问 URL

从 iOS 11 开始,每次使用UIDocumentAPI创建新文档时都会遇到以下错误:

[错误] 无法获取项目/var/mobile/Containers/Data/Application/XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/Documents/myDoc-XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX.myFile (n)的属性值。

错误:错误域 = NSFileProviderInternalErrorDomain 代码 = 1
“不允许读者访问 URL。”
UserInfo={NSLocalizedDescription=不允许读者访问该 URL。}

与关于 SO 的类似问题(1、2、3 不同我没有使用UIDocumentBrowserViewController. 我只是创建一个 UIDocument 并自己调用save()Documents目录。我发现的最接近的问题UIManagedDocument使用. 但是,在我的情况下,尽管出现错误消息,该文件仍然可以成功创建和写入。

这是我的保存程序的要点:

为了简单起见,我的UIDocument子类也几乎是空白的:

我总是写入Documents文件夹,我的查找例程可以验证我的文件是否已成功创建:

到目前为止我发现了什么:

  • 即使我已经设置了我的 UTI,也会出现错误。看到这个这个
  • 当我通过 AirDrop 向我的设备发送“myFile”并且它正确触发我的应用程序打开时,我可以验证我的 UTI 是否正常工作。
  • 该错误仅出现在 iOS 11 上。相同的代码不会在 iOS 10 上重现错误,就像上面的问题一样。
  • UISupportsDocumentBrowser尽管我没有使用浏览器,但我尝试添加密钥,但它并没有解决错误。

怎么了?这只是 iOS 11 上的“噪音”错误消息吗?

如果有人感兴趣,这是 我的在线 GitHub 代码。

0 投票
1 回答
389 浏览

swift - macOS 基于文档的应用程序会自动启用协作吗?

我希望使用 Xcode 在 macOS 上构建一个基于文档的应用程序,并以 macOS High Sierra 为目标。

NSDocument 是否提供类似于 Pages 的文档协作?Apple 的Document Based Apps page 表明协作是适当的基于文档的应用程序的一项功能,但我还没有看到这个问题的明确答案。