ios - 在 Swift 中扩展 Google 的 MLKit 类的问题
问题描述
我正在尝试扩展 Google 的 MLKit StrokePoint 以使其可编码:
import Foundation
import MLKit
class CodableStrokePoint: StrokePoint, Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.x, forKey: .x)
try container.encode(self.y, forKey: .y)
try container.encode(self.t!.intValue, forKey: .t)
}
public required convenience init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let _x = try values.decode(Float.self, forKey: .x)
let _y = try values.decode(Float.self, forKey: .y)
let _t = try values.decode(Int.self, forKey: .t)
self.init(x: _x, y: _y, t: _t)
}
enum CodingKeys: String, CodingKey {
case x
case y
case t
}
}
但是它给了我一个链接器错误:
Undefined symbol: _OBJC_METACLASS_$_MLKStrokePoint
StrokePoint
是这样定义的:
/** A single touch point from the user. */
NS_SWIFT_NAME(StrokePoint)
@interface MLKStrokePoint : NSObject
/** Horizontal coordinate. Increases to the right. */
@property(nonatomic, readonly) float x;
/** Vertical coordinate. Increases downward. */
@property(nonatomic, readonly) float y;
/** Time when the point was recorded, in milliseconds. */
@property(nonatomic, readonly, nullable) NSNumber *t;
/** Unavailable. Use `init(x:y:t:)` instead. */
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates a `StrokePoint` object using the coordinates provided as argument.
*
* Scales on both dimensions are arbitrary but be must be identical: a displacement of 1
* horizontally or vertically must represent the same distance, as seen by the user.
*
* Spatial and temporal origins can be arbitrary as long as they are consistent for a given ink.
*
* @param x Horizontal coordinate. Increases to the right.
* @param y Vertical coordinate. Increases going downward.
* @param t Time when the point was recorded, in milliseconds.
*/
- (instancetype)initWithX:(float)x y:(float)y t:(long)t;
/**
* Creates an `MLKStrokePoint` object using the coordinates provided as
* argument, without specifying a timestamp. This method should only be used
* when it is not feasible to include the timestamp information, as the
* recognition accuracy might degrade.
*
* Scales on both dimensions are arbitrary but be must be identical: a
* displacement of 1 horizontally or vertically must represent the same
* distance, as seen by the user.
*
* Spatial origin can be arbitrary as long as it is consistent for a given ink.
*
* @param x horizontal coordinate. Increases to the right.
* @param y vertical coordinate. Increases going downward.
*/
- (instancetype)initWithX:(float)x y:(float)y;
@end
您能否建议是否可以做我想要实现的目标以及如何做到这一点?
解决方案
推荐阅读
- python - 找不到资源punkt。但是,它已下载并安装
- ajax - NGINX CORS 问题
- c++ - 我可以检测一个类是否有任何公共的非静态数据成员吗?
- c# - XElement 上的 XPath 列表
- flutter - 如何在颤振中创建自定义材质文本字段
- node.js - Firebase 云功能日志。我在日志中看不到我的所有数据
- javascript - 使用 es6 以更好的方式初始化具有未知键的对象数组
- mongodb - 命令copydb的MongoDB授权问题
- php - 如何预测或检查外部网站(不属于我)是否会向我发送 $_SERVER['HTTP_REFERER'] 的值
- flask-uploads - Flask-上传模块