I am currently using JSch to access some files using SFTP and I also need to perform some changes in each file once it is on the remote server.
I am able to access and read the files using ChannelSftp but I would like to create a temporary file while in this remote directory as well. I cannot see a way to do this. I have the ability to make directories and remove files, but not create an empty file? Is this something you can do using ChannelSftp?
原文:https://stackoverflow.com/questions/35729047
更新时间:2022-09-13 09:09
最满意答案
奇怪的是,答案很直截了当。 这是我如何做到的:
let array = Array(results) // la fin
I found a solution. Created extension on Results.
extension Results {
func toArray<T>(ofType: T.Type) -> [T] {
var array = [T]()
for i in 0 ..< count {
if let result = self[i] as? T {
array.append(result)
}
}
return array
}
}
and using like
class func getSomeObject() -> [SomeObject]? {
let objects = Realm().objects(SomeObject).toArray(SomeObject) as [SomeObject]
return objects.count > 0 ? objects : nil
}
Realm.objectForPrimaryKey(_:key:)的第一个参数应该是您要检索的对象类型。 第二个参数应该是您要检索的对象的主键的值。 例如,以下内容将检索其id属性值为C5AD8E58-912E-4C32-B67D-748B0621266A : realm.objectForPrimaryKey(Note.self, key: "C5AD8E58-912E-4C32-B67D-748B0621266A")
The first argument to Realm.objectForPrima ...
奇怪的是,答案很直截了当。 这是我如何做到的: let array = Array(results) // la fin
I found a solution. Created extension on Results. extension Results {
func toArray(ofType: T.Type) -> [T] {
var array = [T]()
for i in 0 ..< count {
if let res ...
在Swift中,每个泛型类都表示它自己的类型,即使您有一个泛型类,其中泛型类型参数是其他泛型类的子类,并且超类作为其泛型参数,两个泛型类将不会通过继承关联。 这就是为什么即使SomeObject是Object的子类,您也无法将Results为Results SomeObject 。 下面是一个简单的例子,表示与泛型类相同的问题: class A{}
class B:A{}
class GenericClass {
let val:T
init ...
您需要映射您的响应,如下所示 configureTransformer("/models/*") {
($0.content).map(Model.instantiate)
}
为了以后再来,你可以尝试这种方式 let objects = resource.typedContent() ?? []
You need to map your response, like this configureTransformer("/models/*") {
($0.content).map(Mo ...
你不需要转换成NSArray来枚举: if let list = playerList {
for (index,value) in list.enumerate() {
// your code here
}
}
至于你的演员,你应该这样做: if let playerList = playerList,
list = playerList as? NSArray {
// use the NSArray list here
}
You don't need to cast ...
只要将CGWindowID设置为UnsafeMutablePointer ,就可以使用数组初始化CFTypeRef : var windows: [CFTypeRef] = [1, 2]
var windowsPointer = UnsafeMutablePointer>(windows)
var cfArray = CFArrayCreate(nil, windowsPointer, windows.count, nil)
You can initialize y ...
在尝试“转换为Swift 4.2”按钮(我失败了)后,我注意到了这一点。 当我切换到另一个目标,我没有运行这个,这个项目没有问题。 在正确清理项目后,失败的目标再次工作。 请注意,根据发行说明,此测试版有几个有关清洁的“已知问题” ,包括这一个(其中也列出了解决方法): 所以你可能想要尝试在Xcode清理之前手动删除DerivedData文件夹。 I noticed this after trying out the "Conversion to Swift 4.2" button (which faile ...
做这个: let entryObjects = realm.objects(Entry.self).filter(...)
let total = entryObjects.map({ $0.fieldValues.sum(ofProperty: "total") }).reduce(0, +)
当Realm支持对嵌套密钥路径的聚合操作( #3392 )时,可以使用KVC,但这仍然在进行中。 Do this: let entryObjects = realm.objects(Entry.self).fil ...