相关疑难解决方法(0)

如何从Swift调用Objective-C代码

在Apple的新Swift语言中,如何调用Objective-C代码?

Apple提到它们可以在一个应用程序中共存,但这是否意味着可以在技术上重用Objective-C中的旧类,同时在Swift中构建新类?

推理

Objective-C是一种独立于平台的语言,而Swift则依赖于平台.因此,在Swift中编写非平台相关代码(业务逻辑库)并不明智.但是,在其中编写与平台相关的代码(例如,与接口相关)将非常好.不是说这是一个好主意,但它肯定是一种兴趣.

objective-c swift

936
推荐指数
13
解决办法
27万
查看次数

dispatch_after - Swift中的GCD?

我从Apple那里浏览了iBook,找不到任何定义:

有人可以解释结构dispatch_after吗?

dispatch_after(<#when: dispatch_time_t#>, <#queue: dispatch_queue_t?#>, <#block: dispatch_block_t?#>)
Run Code Online (Sandbox Code Playgroud)

grand-central-dispatch ios swift

548
推荐指数
12
解决办法
24万
查看次数

创建一个分页的PDF-Mac OS X.

我正在制作Mac应用程序(在Swift 3中使用Xcode 8,Beta 5),用户可以使用该应用程序进行长注并将其导出为PDF.

要创建此PDF,我使用Cocoa的dataWithPDF:方法,使用以下代码:

do {
   // define bounds of PDF as the note text view
   let rect: NSRect = self.noteTextView.bounds
   // create the file path for the PDF
   if let dir = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true).first {
        // add the note title to path
        let path = NSURL(fileURLWithPath: dir).appendingPathComponent("ExportedNote.pdf")
        // Create a PDF of the noteTextView and write it to the created filepath
        try self.noteTextView.dataWithPDF(inside: rect).write(to: path!)  
   } else {
        print("Path format incorrect.") // never happens to …
Run Code Online (Sandbox Code Playgroud)

pdf macos cocoa swift swift3

10
推荐指数
1
解决办法
2141
查看次数

标签 统计

swift ×3

cocoa ×1

grand-central-dispatch ×1

ios ×1

macos ×1

objective-c ×1

pdf ×1

swift3 ×1