对于想了解如何在OSX上使用Swift获取目录大小的读者,本文将提供新的信息,我们将详细介绍swift读取文件,并且为您提供关于ios–使用swift4.0编译的模块无法在swift3.1中导入、io
对于想了解如何在OS X上使用Swift获取目录大小的读者,本文将提供新的信息,我们将详细介绍swift 读取文件,并且为您提供关于ios – 使用swift 4.0编译的模块无法在swift 3.1中导入、ios – 使用Swift 4.0编译的模块无法在Swift 4.0.1中导入、ios – 使用Swift与Swift构建聊天功能的教程?、ios – 在Swift 2.3中使用swift 3框架的有价值信息。
本文目录一览:- 如何在OS X上使用Swift获取目录大小(swift 读取文件)
- ios – 使用swift 4.0编译的模块无法在swift 3.1中导入
- ios – 使用Swift 4.0编译的模块无法在Swift 4.0.1中导入
- ios – 使用Swift与Swift构建聊天功能的教程?
- ios – 在Swift 2.3中使用swift 3框架
如何在OS X上使用Swift获取目录大小(swift 读取文件)
我正在尝试获取目录的大小以及使用Swift在OS
X上的内容。到目前为止,我只能获得目录本身的大小,而没有内容。对于我的大多数目录,它通常显示6148个字节的值,但它的确有所不同。
我已经尝试了下面文件中的directorySize()函数,但它也返回了6,148个字节。
https://github.com/amosavian/ExtDownloader/blob/2f7dba2ec1edd07282725ff47080e5e7af7dabea/Utility.swift
我尝试了该问题的前2个答案,但不确定将Swift传递给Objective-C函数所需的参数。我相信它需要一个指针(我是学习的入门程序员)。
我正在使用Xcode 7.0并运行OS X 10.10.5。
答案1
小编典典更新: Xcode 11.4.1•Swift 5.2
extension URL { /// check if the URL is a directory and if it is reachable func isDirectoryAndReachable() throws -> Bool { guard try resourceValues(forKeys: [.isDirectoryKey]).isDirectory == true else { return false } return try checkResourceIsReachable() } /// returns total allocated size of a the directory including its subFolders or not func directoryTotalAllocatedSize(includingSubfolders: Bool = false) throws -> Int? { guard try isDirectoryAndReachable() else { return nil } if includingSubfolders { guard let urls = FileManager.default.enumerator(at: self, includingPropertiesForKeys: nil)?.allObjects as? [URL] else { return nil } return try urls.lazy.reduce(0) { (try $1.resourceValues(forKeys: [.totalFileAllocatedSizeKey]).totalFileAllocatedSize ?? 0) + $0 } } return try FileManager.default.contentsOfDirectory(at: self, includingPropertiesForKeys: nil).lazy.reduce(0) { (try $1.resourceValues(forKeys: [.totalFileAllocatedSizeKey]) .totalFileAllocatedSize ?? 0) + $0 } } /// returns the directory total size on disk func sizeOnDisk() throws -> String? { guard let size = try directoryTotalAllocatedSize(includingSubfolders: true) else { return nil } URL.byteCountFormatter.countStyle = .file guard let byteCount = URL.byteCountFormatter.string(for: size) else { return nil} return byteCount + " on disk" } private static let byteCountFormatter = ByteCountFormatter()}
用法:
do { let documentDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) if let sizeOnDisk = try documentDirectory.sizeOnDisk() { print("Size:", sizeOnDisk) // Size: 3.15 GB on disk }} catch { print(error)}
ios – 使用swift 4.0编译的模块无法在swift 3.1中导入
Module compiled with swift 4.0 cannot be imported in swift 3.1
当我在Xcode 8中运行项目时.我的模块中的模块是Alamofire.我试图重新启动Xcode,但没有任何想法如何解决这个问题?
解决方法
清理项目,然后尝试重新构建解决方案,看看它是否有效.
如果它不起作用,您仍然会收到相同的错误消息,请执行以下步骤,它应该适合您:
>打开您的podfile并删除Alamofire>运行pod更新>将Alamofire重新添加到您的podfile中>运行pod更新>完成后,清理项目并运行它
ios – 使用Swift 4.0编译的模块无法在Swift 4.0.1中导入
>基础SDK iOS 11.1
> Swift语言版本Swift 4.0
>不使用Pods / Carthage
我希望有人知道
解决方法
对于Xcode的发布版本:
当使用Xcode 9.1,9.2,9.3,9.4,10等打开使用早期Xcode工具构建的框架的项目时,将发生此错误(以及涉及Swift 4.1,4.2等的类似错误).
要解决此问题,请使用Carthage(carthage update –platform iOS),Cocoapods(pod更新或pod安装)或使用新更新的Xcode工具手动更新和重建框架.更新Xcode时应自动更新这些工具,但如果没有,您可以按照原始答案中列出的步骤进行操作.
您可能还需要清理项目cmd shift k以及可能的构建文件夹cmd选项shift k以使Xcode不使用缓存的框架构建.
在某些情况下,您可能还需要删除派生数据文件夹(通过转到Xcode首选项 – >位置 – >派生数据文件夹轻松找到
(谢谢特纳)
对于Xcode的beta版本:
请参阅以下原始答案,然后按照上述步骤操作
原答案:
您可能仍然将xcodebuild工具设置为使用Swift 4.0构建的Xcode 9.0,并且与Xcode 9.1 beta的Swift 4.0.1不兼容.
使用以下命令检入终端:
xcodebuild -version
或者只是进入Xcode首选项 – >位置并检查/更改命令行工具到Xcode 9.1.你应该设置好.
ios – 使用Swift与Swift构建聊天功能的教程?
解决方法
ios – 在Swift 2.3中使用swift 3框架
解决方法
Swift 3 is the primary development language supported within Xcode 8
so there are a couple notes to consider if you chose to continue using
Swift 2.3. First,Swift 2.3 and Swift 3 are not binary compatible so
your app’s entire code base needs to pick one version of Swift.
Source and more informations on the Apple Swift Blog.
您必须在2.3和3.0之间进行选择.如果可以,我认为最好的想法是直接转向3.0(因为2.3只是一个“暂时”版本).
今天关于如何在OS X上使用Swift获取目录大小和swift 读取文件的介绍到此结束,谢谢您的阅读,有关ios – 使用swift 4.0编译的模块无法在swift 3.1中导入、ios – 使用Swift 4.0编译的模块无法在Swift 4.0.1中导入、ios – 使用Swift与Swift构建聊天功能的教程?、ios – 在Swift 2.3中使用swift 3框架等更多相关知识的信息可以在本站进行查询。
本文标签: