小编Cod*_*der的帖子

CocoaPod 中的 C++ 头文件无法从框架导入

我的情况涉及一个私人开发的 CocoaPod,它包含 OpenCV 框架,以及用于使用它的包装器和接口文件。此设计旨在简化我们其他应用程序的跨平台共享。

这是一个有点粗糙的图表,显示了这些部分:

opencv2.framework -> c++ interface file -> objective-c wrapper -> application
Run Code Online (Sandbox Code Playgroud)

如果我取前三个部分,并将它们直接放在目标应用程序中,一切都会按预期进行。然而,我们失去了跨平台轻松共享的能力,我们需要在更改从 c++ 接口传播时手动更新文件。

我目前看到的问题是,当框架、接口和包装器在 CocoaPod 中时,一旦导入到应用程序中,接口文件就失去了从框架(以及从标准 C++ 库)导入的能力。

这是我正在处理相关部分的 podspec 文件:

Pod::Spec.new do |s|

s.name                  = 'PodName'
s.source                = { :path => "." }
s.source_files          = "path/to/source/files/Classes/**/*.{h,mm}", "c++libraryPath/**/*.{h,cpp}"
s.vendored_frameworks   = 'path/to/framework/file/Frameworks/opencv2.framework'
s.frameworks            = 'Accelerate', 'AssetsLibrary', 'AVFoundation', 'CoreGraphics', 'CoreImage', 'CoreMedia', 'CoreVideo', 'Foundation', 'opencv2', 'QuartzCore', 'UIKit'
s.libraries             = 'stdc++'

end
Run Code Online (Sandbox Code Playgroud)

在 C++ 库文件头中,我们有以下内容:

#include <string>
#include <map>
#include <vector>
#include <memory>

#include "opencv2/core.hpp"
Run Code Online (Sandbox Code Playgroud)

当该文件放入目标项目时,一切正常。但是,在 CocoaPod 中,它无法在 include …

c++ opencv objective-c ios cocoapods

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

使用 Swift 3 中的操作类覆盖默认值

我正在尝试使用 Swift 3 中的 Operation 类覆盖某些值,作为 2.2 转换过程的一部分,但我遇到了覆盖类属性的问题。

这是在 Swift 2.2 中正常工作的代码的简化版本:

class ViewController: UIViewController {
    lazy var operationQueue: NSOperationQueue = {
        let queue = NSOperationQueue()
        queue.maxConcurrentOperationCount = 1

        return queue
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        callOperation()
    }

    func callOperation() {
        var error: NSError?

        let words = ["A", "B"]

        words.forEach { word in
            let operation = TestOperation(text: word)
            operation.completionBlock = {
                error = operation.error
            }
            operationQueue.addOperation(operation)
        }

        operationQueue.addOperationWithBlock { 
            if error == nil {
                print("No errors")
            } else { …
Run Code Online (Sandbox Code Playgroud)

nsoperation ios swift swift3

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

在swift 3 iOS中实现谷歌翻译api

嗨,我是iOS开发的新手,我正在尝试在我的应用程序中实现谷歌翻译API.我从GitHub https://github.com/prine/ROGoogleTranslate在线找到了一些示例代码 .我下载了示例代码并按照提供的说明从google cloud translate获取api密钥并将其放在代码中但代码无效,iv查看了GitHub网站上的评论,发现它对其他开发人员有效.我真的不知道我在代码中做错了什么.

ROGoogleTranslateParams.swift

import Foundation

public struct ROGoogleTranslateParams {

    public init() {

    }

    public init(source:String, target:String, text:String) {
        self.source = source
        self.target = target
        self.text = text
    }

    public var source = "de"
    public var target = "en"
    public var text = "Hallo"
}


/// Offers easier access to the Google Translate API
open class ROGoogleTranslate {

    /// Store here the Google Translate API Key
    public var apiKey = "YOUR_API_KEY"

    ///
    /// Initial constructor
    ///
    public …
Run Code Online (Sandbox Code Playgroud)

google-api google-translate ios swift3

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

移动UIImageView

沿着点阵移动图像的最佳方法是什么?

iphone cocoa-touch core-animation uikit ios

4
推荐指数
1
解决办法
9641
查看次数

如何确定iOS设备上是否有可用的相机闪光灯

总体而言,我的应用程序适用于所有iOS设备但是我有一个仅适用于iPhone 4的功能,因此如果用户没有iPhone 4,我想显示警告,让他们知道此功能无法在他们的设备上运行?

我怎样才能做到这一点?

我正在尝试检查设备是否有相机闪光灯

iphone ios

4
推荐指数
2
解决办法
4893
查看次数

iOS - 删除重复的EKEvent,事件再次出现

我在日历中有一个重复发生的事件.我使用此代码删除单个事件[store removeEvent:event span:EKSpanThisEvent commit:YES error:&errorThis];,此方法返回true但事件未从日历中删除.

objective-c ios ekevent ekeventkit ekeventstore

4
推荐指数
1
解决办法
1768
查看次数

如何使用Mapkit和Swift在设置的位置叠加一个圆

我在尝试弄清楚如何在用户位置唯一的所需位置显示透明圆形或矩形时遇到麻烦。我是mapkit的初学者,在此先感谢。

class FirstViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{

@IBOutlet weak var mapView: MKMapView!

let locationManager = CLLocationManager()

override func viewDidLoad()
{
    super.viewDidLoad()

    self.locationManager.delegate = self
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.locationManager.requestAlwaysAuthorization()
    self.locationManager.startUpdatingLocation()
    self.mapView.showsUserLocation = true

}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    let location = locations.last
    let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
    self.mapView.setRegion(region, animated: true)
    self.locationManager.stopUpdatingLocation()//
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
    print("Errors: " + error.localizedDescription)
}

}
Run Code Online (Sandbox Code Playgroud)

location overlay mapkit ios swift

4
推荐指数
1
解决办法
4001
查看次数

如何检测 UITextField 的 inputview 何时打开?

我已经设置了一个UIDatePicker习惯UITextField。我可以检测到它何时关闭,因为那里有“完成”按钮。如何检测它何时打开?我想在用户选择时使屏幕变暗。

uidatepicker uitextfield ios

4
推荐指数
1
解决办法
2090
查看次数

如何删除SwiftyJSON元素?

我有一个dataObjSwiftyJSON生成的JSON数组(比方说),我尝试删除它的元素:

let count=dataObj.count
for var m=x; m<count; ++m {
    dataObj[m] = nil  // there is no removeAtIndex() somehow
}

print(dataObj.count)
print(dataObj)
Run Code Online (Sandbox Code Playgroud)

执行后,dataObj.count保持不变,print现在显示dataObj变为

[null,null,null,...]

真正删除SwiftyJSON元素的方法是什么?

ios swift swifty-json

3
推荐指数
2
解决办法
3377
查看次数

符合Codable协议的类失败,带有encodeWithCoder:无法识别的选择器发送到实例

我知道有几个与此类似的问题,这些问题往往都围绕着与协议不正确相符的类展开,但这在这里不应该是紧迫的问题。

以下是当前给我这个问题的代码的精简版本:

enum Binary: Int {
    case a = 0
    case b = 1
    case c = 9
}

final class MyClass: NSCoder {
    var string: String?
    var date: Date?
    var binary: Binary = .c

    override init() { }

    enum CodingKeys: CodingKey {
        case string, date, binary
    }
}

extension MyClass: Codable {
    convenience init(from decoder: Decoder) throws {
        self.init()

        let values = try decoder.container(keyedBy: CodingKeys.self)
        string = try values.decode(String.self, forKey: .string)
        date = try values.decode(Date.self, forKey: .date)
        binary = …
Run Code Online (Sandbox Code Playgroud)

encoding nskeyedarchiver ios swift

3
推荐指数
2
解决办法
1380
查看次数