当我使用方法.fileExists(atPath:)来判断文件是否存在于文件系统中时,该方法总是向我返回false.我检查了文件系统,文件确实存在.这是我的代码:
let filePath = url?.path
var isDir : ObjCBool = false
if(self.fileManager.fileExists(atPath: filePath!, isDirectory: &isDir)){
let result = NSData(contentsOfFile: filePath!)
}
Run Code Online (Sandbox Code Playgroud)
要么
let filePath = url?.path
if(self.fileManager.fileExists(atPath: filePath!)){
let result = NSData(contentsOfFile: filePath!)
}
Run Code Online (Sandbox Code Playgroud)
始终会跳过if子句.
观察和主题之间有什么区别.当我定义一个可观察的类型变量时.它可以发出onNext,onComplete,onDispose.但是主题也可以这样做.什么时候应该使用observable,在什么情况下我应该使用subject?
我有一个派生自UIView的类,但我初始化它总是显示错误说"属性'self.title'未在swift中的super.init调用中初始化"
这是我的代码
class A: UIView
{
var title : String
var recordUrl : String
var content : String
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
init(frame : CGRect ,title : String, recordUrl : String , content : String)
{
super.init(frame: frame)
self.title = title
self.recordUrl = recordUrl
self.content = content
}
}
Run Code Online (Sandbox Code Playgroud)