小编Dáv*_*tor的帖子

iOS WatchOS-WatchKit App和WatchKit App extension之间有什么区别?

我正在尝试创建一个iOS WatchOS5并发症,并看到了许多教程和Apple文档。他们谈论:

  • WatchKit应用
  • WatchKit App扩展

iOS WatchKit App和WatchKit App Extension有什么区别?

如果我想在手机应用程序和手表应用程序之间共享数据,是否需要同时使用手表连接框架?

apple-watch watchkit apple-watch-complication watchconnectivity watchos-5

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

二进制运算符'!=='不能应用于两个'MyProtocol'

我创建了一个协议:

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不仅仅是课堂,那么解决方案是什么呢?

swift swift-protocols

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

Swift:ARKit保存ARPlaneAnchor用于下一场比赛

ARKit 很新,我很快就开始......所以我遇到了一些麻烦...

我想ARPlaneAnchor在会话期间保存检测到的并在重新启动应用程序时重新加载它们.我的手机总是在同一个地方,我想一次扫描房间.记住我每次启动应用程序时在房间里找到的Anchor.

我试过几个解决方案:

解决方案1: 使用以下方法保存ARPlaneAnchor:NSKeyedArchiver.archiveRootObject(plane, toFile: filePath)

我收到了这个错误:

因未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [ARPlaneAnchor encodeWithCoder:]:发送到实例的无法识别的选择器

我想也许我无法在本地保存这种数据

解决方案2:存储数据ARPlaneAnchor然后在我启动应用程序时对它们进行实例化.数据主要是浮动的.我可以创造ARAnchor轻松,我能投他们的ARPlaneAnchor,但我不能修改"中心"和"扩展"的参数ARPlaneAnchor,因为他们只有一个getter,而不是制定者.所以我无法创造出好的锚点.

我愿意接受解决方案.我想我需要存储ARAnchor对象,但是现在我找不到一个没有崩溃的方法!所以,如果有人能帮助我,我将非常感激.

ios swift arkit aranchor

3
推荐指数
1
解决办法
2252
查看次数

错误:“ViewController”与扩展协议的冗余一致性

当我尝试这个时,我收到错误:

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 ?

ios swift

3
推荐指数
1
解决办法
5805
查看次数

RealmSwift 显示每个日期到 tableview 部分

我是快速和领域的新手。

我想显示存储在领域中的数据。

我想将每个日期显示到 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)

realm uitableview ios swift

3
推荐指数
1
解决办法
1155
查看次数

不能使用类型为'String'的索引下标'[NSObject:Any]'类型的值

我在互联网上找到了不同的东西,但没有任何帮助我.我是新手,我会帮助你.我会收到消息:

不能使用类型为'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)

非常感谢你

ios swift

3
推荐指数
1
解决办法
3477
查看次数

Unsupported swift version (SWIFT 5)

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)

xcode swift

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

Swift中Pointwise Equal,Pointwise小于和Pointwise大的功能是什么?

在阅读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)

我找不到有关何时使用它们的任何解释和示例。这些操作员的功能是什么?

swift

3
推荐指数
1
解决办法
156
查看次数

如何在Swift中从hashValue实现hash(into :)?

我对如何处理编译器不使用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)

hashable swift

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

为什么 CGFloat.zero 存在?

苹果定义的 有什么特别的原因CGFloat.zero吗?我们应该什么时候使用它?和它有什么不同0

core-graphics swift

3
推荐指数
1
解决办法
179
查看次数