我正在尝试创建一个iOS WatchOS5并发症,并看到了许多教程和Apple文档。他们谈论:
iOS WatchKit App和WatchKit App Extension有什么区别?
如果我想在手机应用程序和手表应用程序之间共享数据,是否需要同时使用手表连接框架?
apple-watch watchkit apple-watch-complication watchconnectivity watchos-5
我创建了一个协议:
public protocol MyProtocol {
func doTask()
}
Run Code Online (Sandbox Code Playgroud)
然后,我有一个MyProtocol类型为元素的数组:
var taskList: [MyProtocol] = []
Run Code Online (Sandbox Code Playgroud)
调用者可以向taskList添加元素,最终,我得到了一个非空的元素taskList.
现在,我需要一个可以删除元素的函数taskList,这是我尝试过的:
func removeTask(task: MyProtocol) {
// Compiler error: Binary operator '!==' cannot be applied to two 'MyProtocol'
taskList = taskList.filter{$0 !== task}
}
Run Code Online (Sandbox Code Playgroud)
但我收到编译器错误: Binary operator '!==' cannot be applied to two 'MyProtocol'
如何摆脱这个错误?
===更新===
谢谢@holex,在改成MyProtocol仅限课程后,它运作正常.但现在我想知道我是否需要MyProtocol不仅仅是课堂,那么解决方案是什么呢?
ARKit 很新,我很快就开始......所以我遇到了一些麻烦...
我想ARPlaneAnchor在会话期间保存检测到的并在重新启动应用程序时重新加载它们.我的手机总是在同一个地方,我想一次扫描房间.记住我每次启动应用程序时在房间里找到的Anchor.
我试过几个解决方案:
解决方案1:
使用以下方法保存ARPlaneAnchor:NSKeyedArchiver.archiveRootObject(plane, toFile: filePath)
我收到了这个错误:
因未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [ARPlaneAnchor encodeWithCoder:]:发送到实例的无法识别的选择器
我想也许我无法在本地保存这种数据
解决方案2:存储数据ARPlaneAnchor然后在我启动应用程序时对它们进行实例化.数据主要是浮动的.我可以创造ARAnchor轻松,我能投他们的ARPlaneAnchor,但我不能修改"中心"和"扩展"的参数ARPlaneAnchor,因为他们只有一个getter,而不是制定者.所以我无法创造出好的锚点.
我愿意接受解决方案.我想我需要存储ARAnchor对象,但是现在我找不到一个没有崩溃的方法!所以,如果有人能帮助我,我将非常感激.
当我尝试这个时,我收到错误:
class ViewController: UIViewController, UIScrollViewDelegate {
......
}
extension ViewController: UIScrollViewDelegate { // Error: Redundant conformance of 'ViewController' to protocol 'UI
....
}
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我没有收到错误:
class ViewController: UIViewController {
......
}
extension ViewController: UIScrollViewDelegate { // No error
...
}
Run Code Online (Sandbox Code Playgroud)
为什么我使用扩展时没有将 UIScrollViewDelegate 添加到 ViewController 中?
如果一个类是 UIViewController 类型意味着它符合 UIScrollViewDelegate ?
我是快速和领域的新手。
我想显示存储在领域中的数据。
我想将每个日期显示到 tableview 部分。
项目对象class Item: Object {
@objc dynamic var amount: Int = 0
@objc dynamic var date: Date?
var parentCategory = LinkingObjects(fromType: Category.self, property: "items")
}
Run Code Online (Sandbox Code Playgroud)
import UIKit
import RealmSwift
class HistoryViewController: UITableViewController {
let realm = try! Realm()
var items: Results<Item>?
override func viewDidLoad() {
super.viewDidLoad()
items = realm.objects(Item.self)
}
override func numberOfSections(in tableView: UITableView) -> Int {
return items?.count ?? 1
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { …Run Code Online (Sandbox Code Playgroud) 我在互联网上找到了不同的东西,但没有任何帮助我.我是新手,我会帮助你.我会收到消息:
不能使用类型为'String'的索引下标'[NSObject:Any]'类型的值
private func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : Any]){
let chosenImage = info[UIImagePickerControllerEditedImage] as UIImage
let neuesBild = BildUndNotiz(bild: chosenImage, text: "")
bildUndNotiz += [neuesBild]
self.Spoonlist.reloadData()
picker.dismissViewControllerAnimated(true, completion:
{self.zeigeViewControllerFürBildUndNotiz(neuesBild)})
}
Run Code Online (Sandbox Code Playgroud)
非常感谢你
before you mark this question as a duplicate, I checked this question
and it didn't work for me.
how to fix this error:
error: SWIFT_VERSION '5.0' is unsupported, supported versions are: 3.0, 4.0, 4.2. (in target 'DropDown')
Run Code Online (Sandbox Code Playgroud) 在阅读Apple的Swift编程语言书时,我遇到了Pointwise等于,Pointwise小于和Pointwise大于运算符。参考:https : //developer.apple.com/documentation/swift/swift_standard_library/operator_declarations
.== Pointwise equal
.!= Pointwise not equal
Run Code Online (Sandbox Code Playgroud)
我找不到有关何时使用它们的任何解释和示例。这些操作员的功能是什么?
我对如何处理编译器不使用hashValue而不是实施的弃用警告一无所知hash(into:)。
“ Hashable.hashValue”已作为协议要求弃用;通过实现'hash(into :)'来使类型'MenuItem'与'Hashable'一致
Swift的回答:'Hashable.hashValue'已被弃用为协议要求;有这个例子:
func hash(into hasher: inout Hasher) {
switch self {
case .mention: hasher.combine(-1)
case .hashtag: hasher.combine(-2)
case .url: hasher.combine(-3)
case .custom(let regex): hasher.combine(regex) // assuming regex is a string, that already conforms to hashable
}
}
Run Code Online (Sandbox Code Playgroud)
而且我有这个结构,可以自定义PagingItem羊皮纸(https://github.com/rechsteiner/Parchment)。
import Foundation
/// The PagingItem for Menus.
struct MenuItem: PagingItem, Hashable, Comparable {
let index: Int
let title: String
let menus: Menus
var hashValue: Int {
return index.hashValue …Run Code Online (Sandbox Code Playgroud) 苹果定义的 有什么特别的原因CGFloat.zero吗?我们应该什么时候使用它?和它有什么不同0?