测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可协议 | MIT |
发布日期最后发布日期 | 2017年3月 |
Swift版Swift版本 | 3.0 |
SPM支持SPM | ✗ |
由Daniel Amaral维护。
依赖 | |
Parse | >= 0 |
Kingfisher | >= 0 |
使用ISParseBind,您可以使用Xcode Interface Builder资源的力量来保存、更新和查询PFObjects。
https://www.youtube.com/watch?v=WCZRNC_mHNQ
在AppDelegate中设置Parse Server凭据,在“didFinishLaunchingWithOptions”方法中
let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = "applicationID"
ParseMutableClientConfiguration.clientKey = "clientKey"
ParseMutableClientConfiguration.server = "serverURL"
})
Parse.initialize(with: parseConfiguration)
在某个UIViewController中,执行以下操作
1:
import ISParseBind
2:
@IBOutlet var parseBindView:ISParseBindView!
3: 实现ISParseBindViewDelegate。
这不是强制性的,但如果您需要在处理前后截取某些方法,请实现
parseBindView.delegate = self
extension yourViewController : ISParseBindViewDelegate {
func willSave(view: ISParseBindView, object: PFObject) -> PFObject? {
//If you need, you can intercept the current PFObject that will be saved and change some attributes before that. For example:
//if object.parseClassName == "Car" {
// object["color"] = "Yellow"
//}
return object
}
func didSave(view: ISParseBindView, object: PFObject, isMainEntity:Bool, error: Error?) {
}
func didFetch(view: ISParseBindView, error: Error?) {
print("finish fetch")
}
func willFill(component: Any, value: Any) -> Any? {
//Check wich component will be filled and return a custom value
if let component = component as? UITextField, component == txtName {
return "\(value as! String) Smith"
//Return nil if you want to ignore the fill
}else if let component = component as? UIImageView, component == imgPicture {
return nil
}
return value
}
func didFill(component: Any, value: Any) { }
func willSet(component: Any, value: Any) -> Any? {
//Check wich component will be setup and return a custom value
if let component = component as? UIImageView, component == imgPicture {
return getImageInGrayScale(imgPicture.image)
}
return value
}
func didSet(component: Any, value: Any) { }
}
4:
self.parseBindView.save()
5: 可选获取/查询数据。在viewDidLoad()中执行
self.parseBindView.parseObject = PFObject(withoutDataWithClassName: "SomeClass", objectId: "YYYYXXX")
了解如何使用ISParseBindable协议的变量。
变量 | 类型 | 描述 |
---|---|---|
必需的 | Bool(可选) | 填充组件是必须的 |
必需的 | String(可选) | 组件未填时的错误消息 |
字段类型 | 字符串: 'Text', 'Number', 'Logic' 或 'Image' | 这对于算法在 Parse 中正确地将相应字段类型转换为必须是必要的。 |
字段类型错误 | String(可选) | 转换错误信息 |
字段路径 | 字符串 | 字段路径为您类结构,例如: 'vehicle.brand.car.model’,Vehicule 将是您的主体实体,'Brand' 和 'Car' 将是会自动创建的关系类,而 'model' 将是 'Car' 类的字段。 |
持久化 | 布尔值 | 如果 persist = false,则此字段将仅使用“只读”模式。 |
开发者可以使用可选的 ISParseBindable 变量来创建自己的字段验证器。
FieldTypeError, Required 和 Required Error 在 ISParseBind 算法中不使用。您可以用作辅助程序来制作自己的验证规则。
字段路径输入示例:“vehicle.brand.car.model”,将生成此类结构
{
vehicle = {
brand = {
car = {
model:
}
}
}
}