小编Noa*_*h-1的帖子

只能从它所属的Realm中删除一个对象

我每次尝试从我的tableview上的域中删除一个对象时,我都会收到此错误" 只能从它所属的域中删除一个对象".这是相关代码:

let realm = try! Realm()
var checklists = [ChecklistDataModel]()

override func viewWillAppear(_ animated: Bool) {


    checklists = []
    let getChecklists = realm.objects(ChecklistDataModel.self)

    for item in getChecklists{

        let newChecklist = ChecklistDataModel()
        newChecklist.name = item.name
        newChecklist.note = item.note

        checklists.append(newChecklist)
    }

    tableView.reloadData()

}

override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return checklists.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let …
Run Code Online (Sandbox Code Playgroud)

realm uitableview swift

7
推荐指数
1
解决办法
5321
查看次数

如何使用Swift 3访问字典值?

所以自从Swift 3发布以来,我访问字典的代码的一部分不再起作用了,这里是以前发布的swift的代码:

var locationDict: NSDictionary?//location dictionary
if let getLocation = item.value?["Location"]{locationDict = getLocation as? NSDictionary}

//get dictionary values
let getLatitude = locationDict?.valueForKey("latitude") as! Double
let getLongitude = locationDict?.valueForKey("longitude") as! Double
Run Code Online (Sandbox Code Playgroud)

现在有了新版本,我不知道如何重写"getLocation".我只用新语法重写了最后两行:

//get dictionary values
let getLatitude = locationDict?.value(forKey: "latitude") as! Double
let getLongitude = locationDict?.value(forKey: "longitude") as! 
Run Code Online (Sandbox Code Playgroud)

我正在使用Firebase,这是完整的功能:(它为地图添加了一个注释数组)

 func setAnnotations(){

    //get data
    ref.child("Stores").observe(.value, with: { (snapshot) in

        self.mapView.removeAnnotations(self.annArray)

        for item in snapshot.children {

            let annotation = CustomAnnotation()

            //set all data on the annotation
            annotation.subtitle = (snapshot.value as? NSDictionary)? ["Category"] as? …
Run Code Online (Sandbox Code Playgroud)

dictionary firebase swift firebase-realtime-database

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