小编nat*_*han的帖子

在Fluent + Vapor中查询子项

我对如何查询模型对象的子项并立即使用它感到困惑.我ClientStation儿子很多

final class Client: PostgreSQLModel {
    var stations: Children<Client, Station> {
        return children(\.clientID)
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的控制器中,我有一个客户列表,我想看看并抓住他们的电台.

func clientIndexHandler(_ req: Request) throws -> Future<View> {
    return Client.query(on: req).all().flatMap(to: View.self) { clients in
        let sorted = clients.sorted { ... }
        let content = try sorted.map { client in
            let stations = try client.stations
                                       .query(on: req)
                                       .all()
                                       .map(to: [String].self) { stations in
                return stations.map { $0.name }
            }

            // Now I want to use the stations for other stuff. …
Run Code Online (Sandbox Code Playgroud)

fluent vapor

8
推荐指数
1
解决办法
422
查看次数

无法识别的选择器发送到实例_UIAlertControllerAlertPresentationController

errors我的iOS应用程序中有几个实时场景.我无法理解这个Core Foundation影响我的应用程序中多个用户的特定错误.我的任何项目文件中的流程都没有中断,我不确定导致此崩溃的原因.

附加崩溃日志.任何建议或帮助都会给你很大的帮助.

CoreFoundation _CF_forwarding_prep_0

致命异常:NSInvalidArgumentException - [_ UIAlertControllerAlertPresentationController adaptivePresentationController]:无法识别的选择器发送到实例0x133e29870

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x18ff391b8 __exceptionPreprocess
1  libobjc.A.dylib                0x18e97055c objc_exception_throw
2  CoreFoundation                 0x18ff40268 __methodDescriptionForSelector
3  CoreFoundation                 0x18ff3d270 ___forwarding___
4  CoreFoundation                 0x18fe3680c _CF_forwarding_prep_0
5  UIKit                          0x19689708c -[UISearchController _searchPresentationController]
6  UIKit                          0x19648f8cc -[_UISearchControllerTransplantSearchBarAnimator animateTransition:]
7  UIKit                          0x19613d464 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke
8  UIKit                          0x19607ffdc _runAfterCACommitDeferredBlocks
9  UIKit                          0x196071d50 _cleanUpAfterCAFlushAndRunDeferredBlocks
10 UIKit                          0x195de10b4 _afterCACommitHandler
11 CoreFoundation                 0x18fee60c0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
12 CoreFoundation                 0x18fee3cf0 __CFRunLoopDoObservers
13 CoreFoundation                 0x18fee4180 __CFRunLoopRun
14 CoreFoundation                 0x18fe122b8 …
Run Code Online (Sandbox Code Playgroud)

selector core-foundation ios invalidargumentexception swift

7
推荐指数
1
解决办法
1355
查看次数

适用于iOS 11的Vision Framework条形码检测

我一直在实施Apple在WWDC2017中引入的新Vision框架的测试.我特别关注条形码检测 - 我从相机/图库扫描图像后得知这是条形码图像.但是,在查看barcodeDescriptor时,我无法看到实际的条形码值或有效负载数据.https://developer.apple.com/documentation/coreimage/cibarcodedescriptor页面上似乎没有任何内容可以识别任何属性.

我收到这些错误:

  • 无法连接到远程服务:错误域= NSCocoaErrorDomain代码= 4097"连接到名为
    com.apple.BarcodeSupport.BarcodeNotificationService的服务"
  • libMobileGestalt MobileGestalt.c:555:无法访问InverseDeviceID(请参阅问题/ 11744455>)
  • 连接到名为com.apple.BarcodeSupport.BarcodeNotificationService的服务错误
    域= NSCocoaErrorDomain代码= 4097

有没有办法从VNBarcodeObservation访问条形码值?任何帮助将不胜感激.谢谢!这是我正在使用的代码:

@IBAction func chooseImage(_ sender: Any) {
        imagePicker.allowsEditing = true
        imagePicker.sourceType = .photoLibrary

        present(imagePicker, animated: true, completion: nil)
    }

    @IBAction func takePicture(_ sender: Any) {
        if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)){
            imagePicker.sourceType = UIImagePickerControllerSourceType.camera
            self .present(imagePicker, animated: true, completion: nil)
        }
        else{
            let alert = UIAlertController(title: "Warning", message: "Camera not available", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
    }

    //PickerView …
Run Code Online (Sandbox Code Playgroud)

barcode swift4 ios11 xcode9-beta apple-vision

7
推荐指数
2
解决办法
4418
查看次数

原因:' - [_ UIFullscreenPresentationController adaptivePresentationController]:

我已将搜索栏添加到我的tableview.But当我在我的表视图中搜索一些东西,如果我按下取消默认按钮搜索栏以解除我的键盘意味着我的应用程序崩溃.

崩溃报告:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIFullscreenPresentationController adaptivePresentationController]: unrecognized selector sent to instance 0x7ff10a88cd80'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010b18ed85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010ca8adeb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010b197d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010b0ddcfa ___forwarding___ + 970
    4   CoreFoundation                      0x000000010b0dd8a8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x000000010dfda4c2 -[UISearchController _searchPresentationController] + 134
    6   UIKit                               0x000000010db8ad77 -[_UISearchControllerTransplantSearchBarAnimator animateTransition:] + 215
    7   UIKit                               0x000000010d6f148f __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 2638
    8   UIKit                               0x000000010d58ef62 …
Run Code Online (Sandbox Code Playgroud)

ios swift uisearchcontroller

6
推荐指数
1
解决办法
1934
查看次数

使用iOS11 Vision Framework时的条码字符串值

以下 Swift 代码使用新的 iOS11 Vision 框架来分析图像并查找其中的二维码。

let barcodeRequest = VNDetectBarcodesRequest(completionHandler {(request, error) in
    for result in request.results! {
        if let barcode = result as? VNBarcodeObservation {                    
            if let desc = barcode.barcodeDescriptor as? CIQRCodeDescriptor {
                let content = String(data: desc.errorCorrectedPayload, encoding: .isoLatin1)
                print(content) //Prints garbage
            }
        }
    }
}
let image = //some image with QR code...
let handler = VNImageRequestHandler(cgImage: image, options: [.properties : ""])
try handler.perform([barcodeRequest])
Run Code Online (Sandbox Code Playgroud)

然而,问题是返回的是从二维码读取的desc.errorCorrectedPayload原始编码数据。
为了从描述符中获取可打印的内容字符串,必须解码该原始数据(例如,根据前 4 位确定模式)。

它变得更加有趣,因为苹果已经在 AVFoundation 中拥有用于解码原始数据的代码。该类AVMetadataMachineReadableCodeObject已经具有.stringValue …

barcode swift ios11 apple-vision

6
推荐指数
1
解决办法
2614
查看次数

从Vapor 3中的连接查询中获取所有字段

背景

给出以下示例模型(选择2个显示1-n关系的简单示例):

final class Company: MySQLModel {
    var id: Int?
    var name: String
}

final class Client: MySQLModel {
    var id: Int?
    var attr1: Int
    var attr2: String
    var companyId: Company.ID

    static func prepare(on connection: MySQLDatabase.Connection) -> Future<Void> {

        return Database.create(self, on: connection, closure: { builder in
            try addProperties(to: builder)
            builder.addReference(from: \.companyId, to: \Company.id, actions: .update)
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法获取和返回JOINED查询的结果(例如:公司 - 客户端//一对多)而无需原始查询?我尝试使用Query和Relationships但是没有办法一次性获取所有这些.

理想情况下,返回的数据将具有如下嵌套结构:

预期:

{
  "name": "Alice",
  "id": 0000000001,
  "company": {
    "id": 11111111,
    "name": "Stack Overflow"
  }
}
Run Code Online (Sandbox Code Playgroud)

解决方案(又名解决方法) …

mysql swift vapor

6
推荐指数
1
解决办法
1317
查看次数

Spotlight搜索索引在ios11中不起作用?

我索引了我的应用程序的内容,以便我可以在聚光灯下搜索它,也可以继续在应用程序内搜索.使用iOS 10它可以工作,在iOS 11中,它似乎既不能在我的设备上也不能在模拟器中工作.我是否必须为iOS11添加任何内容,或者它是否在测试版中不起作用?

(奇怪的是,在ios11 iPhone 6s模拟器中似乎缺少搜索字段,但在带有ios11的iPhone7模拟器中可以使用.)

corespotlight ios11 xcode9-beta

5
推荐指数
0
解决办法
431
查看次数

无需使用 cocoapods 或其他外部 API 即可读取条形码图像

我正在尝试使用新的 Apple Vision API 从图像中检测条形码并返回其详细信息。我已成功检测到二维码并使用CIDetector. 但是我不能为一维条形码做这项工作。这是一个示例结果:

import UIKit
import Vision

class BarcodeDetector {

    func recognizeBarcode(for source: UIImage,
                            complete: @escaping (UIImage) -> Void) {
        var resultImage = source
        let detectBarcodeRequest = VNDetectBarcodesRequest { (request, error) in
            if error == nil {
                if let results = request.results as? [VNBarcodeObservation] {
                    print("Number of Barcodes found: \(results.count)")
                    if results.count == 0 { print("\r") }

                    var barcodeBoundingRects = [CGRect]()
                    for barcode in results {
                        barcodeBoundingRects.append(barcode.boundingBox)
                        let barcodeType = String(barcode.symbology.rawValue)?.replacingOccurrences(of: "VNBarcodeSymbology", with: "")
                        print("-Barcode …
Run Code Online (Sandbox Code Playgroud)

swift swift4 ios11 xcode9-beta apple-vision

5
推荐指数
1
解决办法
2297
查看次数

无法在Swift 3.0中关闭MFMailComposeViewController

MFMailComposeViewController不能按取消或发送按钮后,予以驳回。我已经添加MFMailComposeViewControllerDelegate了课程,但是仍然无法正常工作吗?

这是我的代码:

func sendEmail() {
    let MailVC = MFMailComposeViewController()
    MailVC.mailComposeDelegate = self
    MailVC.setToRecipients(["\(emailLabel?.text)"])
    MailVC.setSubject("Set your subject here!")
    MailVC.setMessageBody("Hello this is my message body!", isHTML: false)
    // Present the view controller modally.
    self.present(MailVC, animated: true, completion: nil)
}

func mailComposeController(controller: MFMailComposeViewController,
                           didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    // Dismiss the mail compose view controller.
    controller.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

ios swift3 mfmailcomposeviewcontroller

5
推荐指数
1
解决办法
1260
查看次数

如何停止 SDWebImage 中的 GIF 动画?

我正在使用 SDWebImage 从网络获取图像并显示它们。但有些是GIF,如何停止GIF?

sdwebimage swift

5
推荐指数
1
解决办法
2781
查看次数