我的CoreData中有(n)个数据(UIImage JPEG)。
let imageData: [Data]...
Run Code Online (Sandbox Code Playgroud)
我已经有了这两个框架/ Pod:Zip和ZIPFoundation
我对此有一些疑问:
tempURL.appendingPathExtension("jpg")在呼叫之前或之后添加到每个临时URL data.write(to: tempURL)。在那之后,我有了一个URL数组,所以我只需要创建一个Zip文件并共享它。但这不起作用,我的Mac上出现一个.zip-.cpgz循环。
private func createURLsFrom(imageData: [ImageData]?) {
var urlArray = [URL]()
imageData?.forEach { imData in
if let data = imData.imageData,
let tempURL = NSURL.fileURL(withPathComponents: [NSTemporaryDirectory(), NSUUID().uuidString])?.appendingPathExtension("jpg") {
do {
try data.write(to: tempURL)
urlArray.append(tempURL)
} catch {...}
}
}
self.createZipFile(urlArray: urlArray)
}
private func createZipFile(urlArray: [URL]) {
if let zipURL = try? Zip.quickZipFiles(urlArray, fileName: "ZIP_Test1") {
self.sendEmailWith(dataURL: zipURL)
} else {...}
}
private …Run Code Online (Sandbox Code Playgroud) 我想将字符串转换为数组或字符串或字符列表,例如:Array<String>或Array<Char>。
例子:
\nval myText = "Ab+2#\xe2\x9c\x85'\xc3\xbc{" // Parse and print to Log\nRun Code Online (Sandbox Code Playgroud)\n应该:
\n[ "A", "b", "", "+", "", "2", "", "#", "\xe2\x9c\x85", "'", "", "\xc3\xbc", "", "{" ] // Array contains Strings or Chars\nRun Code Online (Sandbox Code Playgroud)\nJava/Kotlin 方法由于 Android 上的表情符号而不起作用:
\nmyText.toList() // \xe2\x9d\x8c Fails because of Emojis\nmyText.toMutableList() // \xe2\x9d\x8c Fails because of Emojis\nRun Code Online (Sandbox Code Playgroud)\n 在 RecyclerView.Adapter 类中注册点击监听器后,我必须滚动到位置 X!
class MyAdapter(context: Context, mRV: RecyclerView, mLayoutm: LinearLayoutManager) {
...
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.itemView.XY_button.setOnClickListener { // Button inside a cell
mRV.layoutManager.scrollToPosition(x) // Not work
mRV.scrollToPosition(x) // Not work
mLayoutm.scrollToPosition(x) // Not work
(context as MyRVClass).mRV.mLayoutm.scrollToPosition(x) // Not work
(context as MyRVClass).mRV.scrollToPosition(x) // Not work
// it does't work with smoothScrollToPosition() too
}
}
}
Run Code Online (Sandbox Code Playgroud)
PS:我在 swift/iOS 中使用委托协议解决了这个问题,我们在 android/Kotlin 中是否有等效的东西?