iOS开发Swift-15-沙盒sandbox,JSON编码和Codable协议,本地数据存储,SQLite增删改查,视图按照数据排序-待办事项App进阶版...

IOS 苹果IAP(内购)之创建沙盒账号 阅读详情

1.在待办事项App中,寻找沙盒路径.

 TodosTableVC-Delegate:

import UIKit

//UITableViewDelegate
extension TodosTableVC{
    //当用户点击cell的时候调用
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true) //取消选择cell以让底色迅速消失
        
//        找到storyboard上的vc
//        let vc = storyboard?.instantiateViewController(withIdentifier: kTodoTableVCID) as! TodoTableVC
//        用代码进行push跳转
//        navigationController?.pushViewController(vc, animated: true)
    }
    
    //自定义左滑删除按钮的文本
//    override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
//        return "点击以删除"
//    }
    
    //编辑状态下cell左边的按钮-设置为none;因仍旧需要左滑删除功能,故在非编辑状态下仍需返回.delete
    override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        isEditing ? .none : .delete
    }
    //取消编辑状态下cell的缩进
    override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { false }
}


//TodoTableVCDelegate
//反向传值
extension TodosTableVC: TodoTableVCDelegate{
    //增删改查-增
    func didAdd(name: String) {
        //添加数据
        todos.append(Todo(name: name, checked: false))
        UserDefaults.standard.set(todos,forKey: "todos")
        //根据最新数据更新视图
        tableView.insertRows(at: [IndexPath(row: todos.count - 1, section: 0)], with: .automatic)
    }
    
    //增删改查-改
    func didEdit(name: String) {
        //改数据
        todos[row].name = name
        
        //根据最新数据更新视图
        
        //1.通过indexPath找cell,继而找到里面的todoLabel,然后改text
//        let indexPath = IndexPath(row: row, section: 0)
//        let cell = tableView.cellForRow(at: indexPath) as! TodoCell
//        cell.todoLabel.text = todos[row].name
        
        //2.刷新整个tableView(不用过度担心耗资源问题)
        tableView.reloadData()
        
    }
}

 TodosTableVC:

import UIKit

//present和dismiss
//push和pop(压栈/入栈和出栈)

class TodosTableVC: UITableViewController {
    
    var todos = [
        Todo(name: "学习Lebus的《iOS基础版》课程", checked: false),
        Todo(name: "学习Lebus的《iOS进阶版》课程", checked: true),
        Todo(name: "学习Lebus的《iOS仿小红书实战项目》课程", checked: false),
        Todo(name: "学习Lebus的《iOS推送》课程", checked: false),
        Todo(name: "学习Lebus的《iOS-SwiftUI》课程", checked: false)
    ]


    var row = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        //print(todos)
        //isEditing = true //可手动修改isEditing

        //Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        //左边的排序按钮-用于对待办事项重新排序
        editButtonItem.title = nil
        editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        navigationItem.leftBarButtonItem = editButtonItem
        
        //右边的加号按钮-用于添加待办事项
        navigationItem.rightBarButtonItem?.image = pointIcon("plus.circle.fill")
        
        //沙盒sandbox
        print(NSHomeDirectory())
    }
    
    //点下editButtonItem后调用
    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        
        if isEditing{
            editButtonItem.image = nil
            editButtonItem.title = "完成"
        }else{
            editButtonItem.title = nil
            editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        }
    }


    // MARK: - Navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let vc = segue.destination as! TodoTableVC
        vc.delegate = self
        
        if segue.identifier == kEditTodoID{
            let cell = sender as! TodoCell //sender就是用户点击的那个cell
            
            //1.cell-->indexPath
            row = tableView.indexPath(for: cell)!.row
            //2.indexPath-->cell(下述)
            //tableView.cellForRow(at: indexPath) as! TodoCell
            
            vc.name = todos[row].name //正向传值
        }
    }
    

}

启动运行:

 找到在模拟器上的沙盒路径:/Users/linyi/Library/Developer/CoreSimulator/Devices/10416348-B6C4-4F06-B07F-06F4FA9346FB/data/Containers/Data/Application/6580A342-D8E6-4A38-9F27-10E1FC890354

找到沙盒文件夹:

 通过观察文件夹可知,能够放入沙盒的数据类型是有限制的,所以需要使用JSON编码和Codable协议将数据类型转换为Data类型.

2.JSON编码和Codable协议

Todo:

import Foundation

//class Todo{
//    var name = ""
//    var checked = false
//}

//结构体-值类型
struct Todo: Codable {  //遵循编码协议和解码协议
    var name: String
    var checked: Bool
//    init(name: String, checked: Bool){
//        self.name = name
//        self.checked = checked
//    }
}

Constants:

import UIKit

let kTodoTableVCID = "TodoTableVCID"

let kTodoCellID = "TodoCellID"
let kAddTodoID = "AddTodoID"
let kEditTodoID = "EditTodoID"

let kTodosKey = "TodosKey"

func pointIcon(_ iconName: String, _ pointSize: CGFloat = 22) -> UIImage?{
    let config = UIImage.SymbolConfiguration(pointSize: pointSize)
    return UIImage(systemName: iconName, withConfiguration: config)
}

TodosTableVC-Delegate:

import UIKit

//UITableViewDelegate
extension TodosTableVC{
    //当用户点击cell的时候调用
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true) //取消选择cell以让底色迅速消失
        
//        找到storyboard上的vc
//        let vc = storyboard?.instantiateViewController(withIdentifier: kTodoTableVCID) as! TodoTableVC
//        用代码进行push跳转
//        navigationController?.pushViewController(vc, animated: true)
    }
    
    //自定义左滑删除按钮的文本
//    override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
//        return "点击以删除"
//    }
    
    //编辑状态下cell左边的按钮-设置为none;因仍旧需要左滑删除功能,故在非编辑状态下仍需返回.delete
    override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        isEditing ? .none : .delete
    }
    //取消编辑状态下cell的缩进
    override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { false }
}


//TodoTableVCDelegate
//反向传值
extension TodosTableVC: TodoTableVCDelegate{
    //增删改查-增
    func didAdd(name: String) {
        //添加数据
        todos.append(Todo(name: name, checked: false))
        //编码
        do {
            let data = try JSONEncoder().encode(todos)  //todos类型转换为data
            UserDefaults.standard.set(data,forKey: kTodosKey)   //data存入沙盒
        }catch {
            print("编码错误:", error)
        }
        
        //根据最新数据更新视图
        tableView.insertRows(at: [IndexPath(row: todos.count - 1, section: 0)], with: .automatic)
    }
    
    //增删改查-改
    func didEdit(name: String) {
        //改数据
        todos[row].name = name
        
        //根据最新数据更新视图
        
        //1.通过indexPath找cell,继而找到里面的todoLabel,然后改text
//        let indexPath = IndexPath(row: row, section: 0)
//        let cell = tableView.cellForRow(at: indexPath) as! TodoCell
//        cell.todoLabel.text = todos[row].name
        
        //2.刷新整个tableView(不用过度担心耗资源问题)
        tableView.reloadData()
        
    }
}

启动测试:

 发现数据已被存储到了本机.

3.在增删改的时候都使用本地存储.

TodosTableVC-DataSource:

import UIKit

//UITableViewDataSource
extension TodosTableVC{

    //配置section的数量(不实现的话就相当于返回1)
    override func numberOfSections(in tableView: UITableView) -> Int { 1 }
    //配置row的数量
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { todos.count }
    //配置每个row里面显示什么内容
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: kTodoCellID, for: indexPath) as! TodoCell
        
        //增删改查-查
        let checkBoxBtn = cell.checkBoxBtn!
        let todoLabel = cell.todoLabel!
        let initSelected = todos[indexPath.row].checked
//        系统自带布局(虽然storyboard里面没有相应的UI控件,但仍旧可以这样使用)
//        var contentConfiguration = cell.defaultContentConfiguration()
//        contentConfiguration.text = "昵称"
//        contentConfiguration.secondaryText = "个性签名"
//        contentConfiguration.image = UIImage(systemName: "star")
//        cell.contentConfiguration = contentConfiguration
        
        //配置初始数据
        checkBoxBtn.isSelected = initSelected
        todoLabel.text = todos[indexPath.row].name
        todoLabel.textColor = initSelected ? .tertiaryLabel : .label //三元运算符.等同于下面
//        if todos[indexPath.row].checked{
//            cell.todoLabel.textColor = .tertiaryLabel
//        }else{
//            cell.todoLabel.textColor = .label
//        }
        
        
        //增删改查-改
        //设置每个checkBoxBtn的tag值为当前的row,用于传值
        checkBoxBtn.tag = indexPath.row
        //添加点击事件,用户点击checkBoxBtn后会触发self下面的toggleCheck函数,并且系统会自动把本身(toggleCheck)作为参数传过去
        checkBoxBtn.addTarget(self, action: #selector(toggleCheck), for: .touchUpInside)
        
        return cell
    }

    
    //增删改查-删
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        //左滑删除
        if editingStyle == .delete {
            //删数据
            todos.remove(at: indexPath.row)
            saveData()  //本地化存储
            //根据最新数据更新视图
            tableView.reloadData()
        } else if editingStyle == .insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }
    }
    

    //增删改查-改(移动/重新排序)
    override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
//        Swift里数组元素的移动(重新排序)
//        var arr = [1,2,3,4]
//        arr.remove(at: 0) //arr --> [2,3,4]
//        arr.insert(1, at: 3) //arr --> [2,3,4,1]
//        print(arr)
        
        //改数据
        let todoToRemove = todos[fromIndexPath.row] //一定要在删除数组某个元素前取出,不然后面取会取不到
        todos.remove(at: fromIndexPath.row)
        todos.insert(todoToRemove, at: to.row)
        //print(todos)
        saveData()   //本地化存储
        
        //系统自动更新视图(纯粹更新,不会调用DataSource)
        //但我们仍需刷新DataSource函数,因为要刷新indexPath,从而让用户点击CheckBox时数据能够准确
        tableView.reloadData()
    }
}

extension TodosTableVC{
    func saveData(){
        //编码
        do {
            let data = try JSONEncoder().encode(todos)  //todos类型转换为data
            UserDefaults.standard.set(data,forKey: kTodosKey)   //data存入沙盒
        }catch {
            print("编码错误:", error)
        }
    }
}

//监听函数
extension TodosTableVC{
    //用户点击checkBoxBtn触发
    @objc func toggleCheck(checkBoxBtn: UIButton){
        let row = checkBoxBtn.tag
        //修改数据
        todos[row].checked.toggle()
        //print("点击了第\(row + 1)行,todos变成了:",todos)
        saveData()    //本地化存储
        //根据最新数据更新视图
        let checked = todos[row].checked
        checkBoxBtn.isSelected = checked
        let cell = tableView.cellForRow(at: IndexPath(row: row, section: 0)) as! TodoCell
        cell.todoLabel.textColor = checked ? .tertiaryLabel : .label
    }
}

 TodosTableVC-Delegate:

import UIKit

//UITableViewDelegate
extension TodosTableVC{
    //当用户点击cell的时候调用
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true) //取消选择cell以让底色迅速消失
        
//        找到storyboard上的vc
//        let vc = storyboard?.instantiateViewController(withIdentifier: kTodoTableVCID) as! TodoTableVC
//        用代码进行push跳转
//        navigationController?.pushViewController(vc, animated: true)
    }
    
    //自定义左滑删除按钮的文本
//    override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
//        return "点击以删除"
//    }
    
    //编辑状态下cell左边的按钮-设置为none;因仍旧需要左滑删除功能,故在非编辑状态下仍需返回.delete
    override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        isEditing ? .none : .delete
    }
    //取消编辑状态下cell的缩进
    override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { false }
}


//TodoTableVCDelegate
//反向传值
extension TodosTableVC: TodoTableVCDelegate{
    //增删改查-增
    func didAdd(name: String) {
        //添加数据
        todos.append(Todo(name: name, checked: false))
        saveData()   //本地化存储
        
        //根据最新数据更新视图
        tableView.insertRows(at: [IndexPath(row: todos.count - 1, section: 0)], with: .automatic)
    }
    
    //增删改查-改
    func didEdit(name: String) {
        //改数据
        todos[row].name = name
        saveData()   //本地化存储
        
        //根据最新数据更新视图
        
        //1.通过indexPath找cell,继而找到里面的todoLabel,然后改text
//        let indexPath = IndexPath(row: row, section: 0)
//        let cell = tableView.cellForRow(at: indexPath) as! TodoCell
//        cell.todoLabel.text = todos[row].name
        
        //2.刷新整个tableView(不用过度担心耗资源问题)
        tableView.reloadData()
        
    }
}

4.在查询数据的时候使用解码从本地数据中查询待办事项.

TodosTableVC:

import UIKit

//present和dismiss
//push和pop(压栈/入栈和出栈)

class TodosTableVC: UITableViewController {
    
    var todos: [Todo] = [
//        Todo(name: "学习Lebus的《iOS基础版》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS进阶版》课程", checked: true),
//        Todo(name: "学习Lebus的《iOS仿小红书实战项目》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS推送》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS-SwiftUI》课程", checked: false)
    ]


    var row = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        //print(todos)
        //isEditing = true //可手动修改isEditing

        //Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        //左边的排序按钮-用于对待办事项重新排序
        editButtonItem.title = nil
        editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        navigationItem.leftBarButtonItem = editButtonItem
        
        //右边的加号按钮-用于添加待办事项
        navigationItem.rightBarButtonItem?.image = pointIcon("plus.circle.fill")
        
        //沙盒sandbox
        print(NSHomeDirectory())
        
        //根据key在沙盒中取data数据
        if let data = UserDefaults.standard.data(forKey: kTodosKey){
            //解码
            if let todos = try? JSONDecoder().decode([Todo].self, from: data){
                //想把数据从data类型解码成数组里边元素是Todo的类型
                self.todos = todos
            }else{
                print("解码失败")
            }
        }
        
    }
    
    //点下editButtonItem后调用
    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        
        if isEditing{
            editButtonItem.image = nil
            editButtonItem.title = "完成"
        }else{
            editButtonItem.title = nil
            editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        }
    }


    // MARK: - Navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let vc = segue.destination as! TodoTableVC
        vc.delegate = self
        
        if segue.identifier == kEditTodoID{
            let cell = sender as! TodoCell //sender就是用户点击的那个cell
            
            //1.cell-->indexPath
            row = tableView.indexPath(for: cell)!.row
            //2.indexPath-->cell(下述)
            //tableView.cellForRow(at: indexPath) as! TodoCell
            
            vc.name = todos[row].name //正向传值
        }
    }
    

}

 启动测试:

 关闭应用,再次打开:

 5.每次都直接覆盖存储,数据多了可能会影响系统性能.所以使用Core Data来提高效率.

以前在新建项目的时候勾选了Core Data,所以系统为我们自动生成了DataModel.

配置Core Data:

 这时Todo这个类就暂时不需要了.将它注释掉.

Todo:

import Foundation

//class Todo{
//    var name = ""
//    var checked = false
//}

//结构体-值类型
//struct Todo: Codable {
//    var name: String
//    var checked: Bool
////    init(name: String, checked: Bool){
////        self.name = name
////        self.checked = checked
////    }
//}

6.Todos的数据库添加操作.

将数据库中的name和checked都取消可选类型,设置默认值.

 新建一个用于存放存储代码的swift文件.

修改新增部分代码.

TodosTableVC-Delegate:

import UIKit

//UITableViewDelegate
extension TodosTableVC{
    //当用户点击cell的时候调用
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true) //取消选择cell以让底色迅速消失
        
//        找到storyboard上的vc
//        let vc = storyboard?.instantiateViewController(withIdentifier: kTodoTableVCID) as! TodoTableVC
//        用代码进行push跳转
//        navigationController?.pushViewController(vc, animated: true)
    }
    
    //自定义左滑删除按钮的文本
//    override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
//        return "点击以删除"
//    }
    
    //编辑状态下cell左边的按钮-设置为none;因仍旧需要左滑删除功能,故在非编辑状态下仍需返回.delete
    override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        isEditing ? .none : .delete
    }
    //取消编辑状态下cell的缩进
    override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { false }
}


//TodoTableVCDelegate
//反向传值
extension TodosTableVC: TodoTableVCDelegate{
    //增删改查-增
    func didAdd(name: String) {
        //添加数据
//        todos.append(Todo(name: name, checked: false))
//        saveData()   //本地化存储
        //修改内存中的数据,再将修改后的数据存到本地.
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        let context = appDelegate.persistentContainer.viewContext
        let todo = Todo(context: context)
        todo.name = name
        todos.append(todo)
        appDelegate.saveContext()
        
        //根据最新数据更新视图
        tableView.insertRows(at: [IndexPath(row: todos.count - 1, section: 0)], with: .automatic)
    }
    
    //增删改查-改
    func didEdit(name: String) {
        //改数据
        todos[row].name = name
        //saveData()   //本地化存储
        
        //根据最新数据更新视图
        
        //1.通过indexPath找cell,继而找到里面的todoLabel,然后改text
//        let indexPath = IndexPath(row: row, section: 0)
//        let cell = tableView.cellForRow(at: indexPath) as! TodoCell
//        cell.todoLabel.text = todos[row].name
        
        //2.刷新整个tableView(不用过度担心耗资源问题)
        tableView.reloadData()
        
    }
}

通过地址/Users/linyi/Library/Developer/CoreSimulator/Devices/10416348-B6C4-4F06-B07F-06F4FA9346FB/data/Containers/Data/Application/0B19CC42-A036-492E-9F77-AF56F9EF4071/Library/ApplicationSupport的Todos.sqlite查看数据库:

 7.删除待办事项后更新本地数据库.

TodosTableVC-DataSource:

import UIKit

//UITableViewDataSource
extension TodosTableVC{

    //配置section的数量(不实现的话就相当于返回1)
    override func numberOfSections(in tableView: UITableView) -> Int { 1 }
    //配置row的数量
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { todos.count }
    //配置每个row里面显示什么内容
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: kTodoCellID, for: indexPath) as! TodoCell
        
        //增删改查-查
        let checkBoxBtn = cell.checkBoxBtn!
        let todoLabel = cell.todoLabel!
        let initSelected = todos[indexPath.row].checked
//        系统自带布局(虽然storyboard里面没有相应的UI控件,但仍旧可以这样使用)
//        var contentConfiguration = cell.defaultContentConfiguration()
//        contentConfiguration.text = "昵称"
//        contentConfiguration.secondaryText = "个性签名"
//        contentConfiguration.image = UIImage(systemName: "star")
//        cell.contentConfiguration = contentConfiguration
        
        //配置初始数据
        checkBoxBtn.isSelected = initSelected
        todoLabel.text = todos[indexPath.row].name
        todoLabel.textColor = initSelected ? .tertiaryLabel : .label //三元运算符.等同于下面
//        if todos[indexPath.row].checked{
//            cell.todoLabel.textColor = .tertiaryLabel
//        }else{
//            cell.todoLabel.textColor = .label
//        }
        
        
        //增删改查-改
        //设置每个checkBoxBtn的tag值为当前的row,用于传值
        checkBoxBtn.tag = indexPath.row
        //添加点击事件,用户点击checkBoxBtn后会触发self下面的toggleCheck函数,并且系统会自动把本身(toggleCheck)作为参数传过去
        checkBoxBtn.addTarget(self, action: #selector(toggleCheck), for: .touchUpInside)
        
        return cell
    }

    
    //增删改查-删
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        //左滑删除
        if editingStyle == .delete {
            //删除本地中的数据
            context.delete(todos[indexPath.row])
            //删内存中的数据
            todos.remove(at: indexPath.row)
            appDelegate.saveContext()
            //saveData()  //本地化存储
            //根据最新数据更新视图
            tableView.reloadData()
        } else if editingStyle == .insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }
    }
    

    //增删改查-改(移动/重新排序)
    override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
//        Swift里数组元素的移动(重新排序)
//        var arr = [1,2,3,4]
//        arr.remove(at: 0) //arr --> [2,3,4]
//        arr.insert(1, at: 3) //arr --> [2,3,4,1]
//        print(arr)
        
        //改数据
        let todoToRemove = todos[fromIndexPath.row] //一定要在删除数组某个元素前取出,不然后面取会取不到
        todos.remove(at: fromIndexPath.row)
        todos.insert(todoToRemove, at: to.row)
        //print(todos)
        //saveData()   //本地化存储
        
        //系统自动更新视图(纯粹更新,不会调用DataSource)
        //但我们仍需刷新DataSource函数,因为要刷新indexPath,从而让用户点击CheckBox时数据能够准确
        tableView.reloadData()
    }
}



//监听函数
extension TodosTableVC{
    //用户点击checkBoxBtn触发
    @objc func toggleCheck(checkBoxBtn: UIButton){
        let row = checkBoxBtn.tag
        //修改数据
        todos[row].checked.toggle()
        //print("点击了第\(row + 1)行,todos变成了:",todos)
        //saveData()    //本地化存储
        //根据最新数据更新视图
        let checked = todos[row].checked
        checkBoxBtn.isSelected = checked
        let cell = tableView.cellForRow(at: IndexPath(row: row, section: 0)) as! TodoCell
        cell.todoLabel.textColor = checked ? .tertiaryLabel : .label
    }
}

 8.编辑待办事项后更新本地数据库.

TodosTableVC-Delegate:

import UIKit

//UITableViewDelegate
extension TodosTableVC{
    //当用户点击cell的时候调用
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true) //取消选择cell以让底色迅速消失
        
//        找到storyboard上的vc
//        let vc = storyboard?.instantiateViewController(withIdentifier: kTodoTableVCID) as! TodoTableVC
//        用代码进行push跳转
//        navigationController?.pushViewController(vc, animated: true)
    }
    
    //自定义左滑删除按钮的文本
//    override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
//        return "点击以删除"
//    }
    
    //编辑状态下cell左边的按钮-设置为none;因仍旧需要左滑删除功能,故在非编辑状态下仍需返回.delete
    override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        isEditing ? .none : .delete
    }
    //取消编辑状态下cell的缩进
    override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { false }
}


//TodoTableVCDelegate
//反向传值
extension TodosTableVC: TodoTableVCDelegate{
    //增删改查-增
    func didAdd(name: String) {
        //添加数据
//        todos.append(Todo(name: name, checked: false))
//        saveData()   //本地化存储
        //修改内存中的数据,再将修改后的数据存到本地.
       
        let todo = Todo(context: context)
        todo.name = name
        todos.append(todo)
        appDelegate.saveContext()
        
        //根据最新数据更新视图
        tableView.insertRows(at: [IndexPath(row: todos.count - 1, section: 0)], with: .automatic)
    }
    
    //增删改查-改
    func didEdit(name: String) {
        //改数据
        todos[row].name = name
        appDelegate.saveContext()
        //saveData()   //本地化存储
        
        //根据最新数据更新视图
        
        //1.通过indexPath找cell,继而找到里面的todoLabel,然后改text
//        let indexPath = IndexPath(row: row, section: 0)
//        let cell = tableView.cellForRow(at: indexPath) as! TodoCell
//        cell.todoLabel.text = todos[row].name
        
        //2.刷新整个tableView(不用过度担心耗资源问题)
        tableView.reloadData()
        
    }
}

 TodosTableVC-DataSource:

import UIKit

//UITableViewDataSource
extension TodosTableVC{

    //配置section的数量(不实现的话就相当于返回1)
    override func numberOfSections(in tableView: UITableView) -> Int { 1 }
    //配置row的数量
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { todos.count }
    //配置每个row里面显示什么内容
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: kTodoCellID, for: indexPath) as! TodoCell
        
        //增删改查-查
        let checkBoxBtn = cell.checkBoxBtn!
        let todoLabel = cell.todoLabel!
        let initSelected = todos[indexPath.row].checked
//        系统自带布局(虽然storyboard里面没有相应的UI控件,但仍旧可以这样使用)
//        var contentConfiguration = cell.defaultContentConfiguration()
//        contentConfiguration.text = "昵称"
//        contentConfiguration.secondaryText = "个性签名"
//        contentConfiguration.image = UIImage(systemName: "star")
//        cell.contentConfiguration = contentConfiguration
        
        //配置初始数据
        checkBoxBtn.isSelected = initSelected
        todoLabel.text = todos[indexPath.row].name
        todoLabel.textColor = initSelected ? .tertiaryLabel : .label //三元运算符.等同于下面
//        if todos[indexPath.row].checked{
//            cell.todoLabel.textColor = .tertiaryLabel
//        }else{
//            cell.todoLabel.textColor = .label
//        }
        
        
        //增删改查-改
        //设置每个checkBoxBtn的tag值为当前的row,用于传值
        checkBoxBtn.tag = indexPath.row
        //添加点击事件,用户点击checkBoxBtn后会触发self下面的toggleCheck函数,并且系统会自动把本身(toggleCheck)作为参数传过去
        checkBoxBtn.addTarget(self, action: #selector(toggleCheck), for: .touchUpInside)
        
        return cell
    }

    
    //增删改查-删
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        //左滑删除
        if editingStyle == .delete {
            //删除本地中的数据
            context.delete(todos[indexPath.row])
            //删内存中的数据
            todos.remove(at: indexPath.row)
            appDelegate.saveContext()
            //saveData()  //本地化存储
            //根据最新数据更新视图
            tableView.reloadData()
        } else if editingStyle == .insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }
    }
    

    //增删改查-改(移动/重新排序)
    override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
//        Swift里数组元素的移动(重新排序)
//        var arr = [1,2,3,4]
//        arr.remove(at: 0) //arr --> [2,3,4]
//        arr.insert(1, at: 3) //arr --> [2,3,4,1]
//        print(arr)
        
        //改数据
        let todoToRemove = todos[fromIndexPath.row] //一定要在删除数组某个元素前取出,不然后面取会取不到
        todos.remove(at: fromIndexPath.row)
        todos.insert(todoToRemove, at: to.row)
        //print(todos)
        //saveData()   //本地化存储
        
        //系统自动更新视图(纯粹更新,不会调用DataSource)
        //但我们仍需刷新DataSource函数,因为要刷新indexPath,从而让用户点击CheckBox时数据能够准确
        tableView.reloadData()
    }
}



//监听函数
extension TodosTableVC{
    //用户点击checkBoxBtn触发
    @objc func toggleCheck(checkBoxBtn: UIButton){
        let row = checkBoxBtn.tag
        //修改数据
        todos[row].checked.toggle()
        //print("点击了第\(row + 1)行,todos变成了:",todos)
        //saveData()    //本地化存储
        appDelegate.saveContext()
        //根据最新数据更新视图
        let checked = todos[row].checked
        checkBoxBtn.isSelected = checked
        let cell = tableView.cellForRow(at: IndexPath(row: row, section: 0)) as! TodoCell
        cell.todoLabel.textColor = checked ? .tertiaryLabel : .label
    }
}

 9.从本地取出数据.

TodosTableVC:

import UIKit

//present和dismiss
//push和pop(压栈/入栈和出栈)

class TodosTableVC: UITableViewController {
    
    var todos: [Todo] = [
//        Todo(name: "学习Lebus的《iOS基础版》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS进阶版》课程", checked: true),
//        Todo(name: "学习Lebus的《iOS仿小红书实战项目》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS推送》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS-SwiftUI》课程", checked: false)
    ]


    var row = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        //print(todos)
        //isEditing = true //可手动修改isEditing

        //Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        //左边的排序按钮-用于对待办事项重新排序
        editButtonItem.title = nil
        editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        navigationItem.leftBarButtonItem = editButtonItem
        
        //右边的加号按钮-用于添加待办事项
        navigationItem.rightBarButtonItem?.image = pointIcon("plus.circle.fill")
        
        //沙盒sandbox
        print(NSHomeDirectory())
        
//        //根据key在沙盒中取data数据
//        if let data = UserDefaults.standard.data(forKey: kTodosKey){
//            //解码
//            if let todos = try? JSONDecoder().decode([Todo].self, from: data){
//                //想把数据从data类型解码成数组里边元素是Todo的类型
//                self.todos = todos
//            }else{
//                print("解码失败")
//            }
//        }
        if let todos = try? context.fetch(Todo.fetchRequest()){
            self.todos = todos
        }else{
            print("从SQLite里面取数值失败了")
        }
    }
    
    //点下editButtonItem后调用
    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        
        if isEditing{
            editButtonItem.image = nil
            editButtonItem.title = "完成"
        }else{
            editButtonItem.title = nil
            editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        }
    }


    // MARK: - Navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let vc = segue.destination as! TodoTableVC
        vc.delegate = self
        
        if segue.identifier == kEditTodoID{
            let cell = sender as! TodoCell //sender就是用户点击的那个cell
            
            //1.cell-->indexPath
            row = tableView.indexPath(for: cell)!.row
            //2.indexPath-->cell(下述)
            //tableView.cellForRow(at: indexPath) as! TodoCell
            
            vc.name = todos[row].name //正向传值
        }
    }
    

}

 启动测试:

 10.移动待办事项:主键+Int16+添加属性时的自动迁移.

在Entity中追加一个属性-排序ID.

 TodosTableVC-DataSource:

import UIKit

//UITableViewDataSource
extension TodosTableVC{

    //配置section的数量(不实现的话就相当于返回1)
    override func numberOfSections(in tableView: UITableView) -> Int { 1 }
    //配置row的数量
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { todos.count }
    //配置每个row里面显示什么内容
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: kTodoCellID, for: indexPath) as! TodoCell
        
        todos[indexPath.row].orderID = Int16(indexPath.row)
     appDelegate.saveContext() //增删改查-查 let checkBoxBtn = cell.checkBoxBtn! let todoLabel = cell.todoLabel! let initSelected = todos[indexPath.row].checked // 系统自带布局(虽然storyboard里面没有相应的UI控件,但仍旧可以这样使用) // var contentConfiguration = cell.defaultContentConfiguration() // contentConfiguration.text = "昵称" // contentConfiguration.secondaryText = "个性签名" // contentConfiguration.image = UIImage(systemName: "star") // cell.contentConfiguration = contentConfiguration //配置初始数据 checkBoxBtn.isSelected = initSelected todoLabel.text = todos[indexPath.row].name todoLabel.textColor = initSelected ? .tertiaryLabel : .label //三元运算符.等同于下面 // if todos[indexPath.row].checked{ // cell.todoLabel.textColor = .tertiaryLabel // }else{ // cell.todoLabel.textColor = .label // } //增删改查-改 //设置每个checkBoxBtn的tag值为当前的row,用于传值 checkBoxBtn.tag = indexPath.row //添加点击事件,用户点击checkBoxBtn后会触发self下面的toggleCheck函数,并且系统会自动把本身(toggleCheck)作为参数传过去 checkBoxBtn.addTarget(self, action: #selector(toggleCheck), for: .touchUpInside) return cell } //增删改查-删 override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { //左滑删除 if editingStyle == .delete { //删除本地中的数据 context.delete(todos[indexPath.row]) //删内存中的数据 todos.remove(at: indexPath.row) appDelegate.saveContext() //saveData() //本地化存储 //根据最新数据更新视图 tableView.reloadData() } else if editingStyle == .insert { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } //增删改查-改(移动/重新排序) override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { // Swift里数组元素的移动(重新排序) // var arr = [1,2,3,4] // arr.remove(at: 0) //arr --> [2,3,4] // arr.insert(1, at: 3) //arr --> [2,3,4,1] // print(arr) //改数据 let todoToRemove = todos[fromIndexPath.row] //一定要在删除数组某个元素前取出,不然后面取会取不到 todos.remove(at: fromIndexPath.row) todos.insert(todoToRemove, at: to.row) //print(todos) //saveData() //本地化存储 //系统自动更新视图(纯粹更新,不会调用DataSource) //但我们仍需刷新DataSource函数,因为要刷新indexPath,从而让用户点击CheckBox时数据能够准确 tableView.reloadData() } } //监听函数 extension TodosTableVC{ //用户点击checkBoxBtn触发 @objc func toggleCheck(checkBoxBtn: UIButton){ let row = checkBoxBtn.tag //修改数据 todos[row].checked.toggle() //print("点击了第\(row + 1)行,todos变成了:",todos) //saveData() //本地化存储 appDelegate.saveContext() //根据最新数据更新视图 let checked = todos[row].checked checkBoxBtn.isSelected = checked let cell = tableView.cellForRow(at: IndexPath(row: row, section: 0)) as! TodoCell cell.todoLabel.textColor = checked ? .tertiaryLabel : .label } }

 测试:

 11.首次进入App首页时按照orderID从小到大的顺序进行排序.

TodosTableVC:

import UIKit

//present和dismiss
//push和pop(压栈/入栈和出栈)

class TodosTableVC: UITableViewController {
    
    var todos: [Todo] = [
//        Todo(name: "学习Lebus的《iOS基础版》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS进阶版》课程", checked: true),
//        Todo(name: "学习Lebus的《iOS仿小红书实战项目》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS推送》课程", checked: false),
//        Todo(name: "学习Lebus的《iOS-SwiftUI》课程", checked: false)
    ]


    var row = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        //print(todos)
        //isEditing = true //可手动修改isEditing

        //Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        //左边的排序按钮-用于对待办事项重新排序
        editButtonItem.title = nil
        editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        navigationItem.leftBarButtonItem = editButtonItem
        
        //右边的加号按钮-用于添加待办事项
        navigationItem.rightBarButtonItem?.image = pointIcon("plus.circle.fill")
        
        //沙盒sandbox
        print(NSHomeDirectory())
        
//        //根据key在沙盒中取data数据
//        if let data = UserDefaults.standard.data(forKey: kTodosKey){
//            //解码
//            if let todos = try? JSONDecoder().decode([Todo].self, from: data){
//                //想把数据从data类型解码成数组里边元素是Todo的类型
//                self.todos = todos
//            }else{
//                print("解码失败")
//            }
//        }
        //指定排序规则
        let request = Todo.fetchRequest()
        //根据orderID的顺序进行升序排列.
        request.sortDescriptors = [NSSortDescriptor(key: "orderID", ascending: true)]
        
        if let todos = try? context.fetch(request){
            self.todos = todos
        }else{
            print("从SQLite里面取数值失败了")
        }
    }
    
    //点下editButtonItem后调用
    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        
        if isEditing{
            editButtonItem.image = nil
            editButtonItem.title = "完成"
        }else{
            editButtonItem.title = nil
            editButtonItem.image = pointIcon("arrow.up.arrow.down.circle.fill")
        }
    }


    // MARK: - Navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let vc = segue.destination as! TodoTableVC
        vc.delegate = self
        
        if segue.identifier == kEditTodoID{
            let cell = sender as! TodoCell //sender就是用户点击的那个cell
            
            //1.cell-->indexPath
            row = tableView.indexPath(for: cell)!.row
            //2.indexPath-->cell(下述)
            //tableView.cellForRow(at: indexPath) as! TodoCell
            
            vc.name = todos[row].name //正向传值
        }
    }
    

}

 启动测试:

IOS沙盒相关 ios沙盒 阅读详情

相关推荐

iOS开发 - Swift Codable协议实战:快速、简单、高效地完成JSON和Model转换!

Codable是Swift 4.0引入的一种协议,它是一个组合协议,由Decodable和Encodable两个协议组成。它的作用是将模型对象转换为 JSON 或者是其它的数据格式,也可以反过来将 JSON 数据转换为模型对象。Encodable和Decodable分别定义了和两个协议函数,分别用来实现数据模型的归档和外部数据的解析和实例化。最常用的场景就是刚提到的 JSON 数据与模型的相互转换,但是 Codable 的能力并不止于此。

qq_41146932的博客 1697

IOS学习之IOS沙盒(sandbox)机制和文件操作(一)

1、IOS沙盒机制 IOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等。 1.1、每个应用程序都有自己的存储空间 1.2、应用程序不能翻过自己的围墙去访问别的存储空间的内容 1.3、应用程序请求的数据都要通过权限检测,假如不符合条件的话,不会被放行。

Kikim的地盘 2289

精通iOS沙盒封装技术:Sandbox完全解析

沙盒技术最初来源于操作系统的隔离机制,随着互联网的发展,特别是针对Web浏览器中的脚本执行,沙盒技术逐渐成为一种重要的安全防护手段。它最早被引入到网络浏览器中,以隔离不可信的代码,防止其对系统造成损害。随着技术的演进,沙盒模型已经被广泛应用在操作系统、移动应用、虚拟机以及其他需要严格安全隔离的场景中。

weixin_35815766的博客 1503

IOS内购自动续费订阅测试

IOS内购自动续费订阅测试

weixin_43587784的博客 7488

Swift iOS StoreKit 原生内购订阅代码封装,含Demo

Swift iOS StoreKit 原生内购订阅代码封装,语言是Swift,内含demo,可以二次封装给其他开发工具使用.

LabVIEW与MySQL的连接:软件下载与安装至UDL文件创建全过程

依据个人经验编辑的十分完备的使用教程

tiaowudexiaoyu的博客 5584

iOS沙盒(sandbox)

iOS沙盒(sandbox)一、什么是sandbox每个iOS应用都被限制在“沙盒”中,“沙盒”相当于一个加了仅主人可见权限的文件夹,苹果对沙盒主要有以下限制。1. 应用程序可以在自己的沙盒里运作,但是不能访问任何其他应用程序的沙。 2. 应用程序间不能共享数据,沙盒里的文件不能被复制到其他应用程序文件夹中,也不能把其他应用程序文件夹中的文件复制到沙盒里。 3. 苹果禁止任何读、写沙盒以外的文件,禁

Sky_jay的博客 1212

SC-FDMA

<br />SC-FDMA(Single-carrier Frequency-Division Multiple Access,單載波分頻多工),是LTE的上行鏈路的主流多址。<br />SC-FDMA是單波載(Single-carrier),與OFDMA相比之下具有的較低的PAPR(峰值/平均功率比,peak-to-average power ratio),比多載波的PAPR低1-3dB左右(PAPR是由于多載波在频域叠加引起)。更低的PAPR可以使行動終端(mobile terminal)在發送功效方面

jod的专栏 3306

iOS 沙盒机制

iOS沙盒:笼统的说就是APP的文件目录系统。 一:简介 1是iOS安全机制,每个iOS程序只能访问自己沙盒中的东西 2是对程序执行各种操作的权限限制 3访问其他APP沙盒,需要权限。 4非代码文件都在此保存,例如图片,图标,视频,plist文件,文本文件。 5APP之间不能相通,只能通过URL scheme来通信。 6相对独立,封闭。 二:访问路径:1)/Users/XX

巴拉巴拉小魔仙 5082

电力现货市场出清机制与节点电价计算实战解析

本文深入解析了电力现货市场的出清机制,特别是节点边际电价的计算原理与实战应用。通过一个基于Matlab和IEEE30节点系统的完整案例,详细演示了如何利用最优潮流模型求解市场出清价格,并提取节点电价,揭示了电网阻塞如何影响实时电价的形成。

weixin_29061425的博客 969

神经网络:初学者指南(专业版)

神经网络是一种受生物大脑启发的计算模型,由多层互连的人工神经元组成。本文从生物神经元结构出发,介绍了感知器模型、激活函数、网络架构(输入/隐藏/输出层)等基础概念,并详细阐述了前向传播、反向传播、损失函数和优化器等核心训练机制。同时涵盖了CNN、RNN等常见架构,以及过拟合、梯度消失等关键挑战,最后概述了神经网络在计算机视觉、NLP等领域的广泛应用。全文系统性地梳理了神经网络的基础理论和实践要点,为初学者提供了清晰的学习路径。

weixin_42107409的博客 1806

iOS最新的“沙盒APPLE账户”设置位置

网上好多教程都比较陈旧了,很多文章里面的描述还是说“沙盒Apple账户”在“App Store”的设置中了,这是不正确的!在最新的iOS 18.2中,具体向下版本是多少不清楚,“时间2024年12月12日更新。

user95的博客 5022

ICC2 实战秘籍:create_workspace 命令全解析

必选项:工作区名称,这可是创建工作区的 “身份证”,必不可少。技术数据选项匹配:优先考虑用 -technology 直接加载技术文件,这是获取最新、最准确技术数据的首选路径;要是已经有合适的技术库了,那 -use_technology_lib 引用现有技术库也能快速上手。精度设置优先规则:技术文件自动配置排在第一位,能自动适配就别手动操心;要是自动配置不理想,那就显式指定 scale_factor;实在没要求,就用默认配置,但得清楚它的精度限制。

weixin_50820814的博客 1132

深入iOS安全基石:万字详解App沙盒机制 (App Sandbox)

如果这些 App 可以随意访问设备上的所有文件、读取其他 App 的数据、或者修改系统设置,那将会带来灾难性的后果——恶意软件可以轻易窃取你的敏感信息,一个有 Bug 的 App 可能意外删除你的重要照片,或者破坏操作系统的稳定性。它可以在自己的院子里自由活动,但不能随意跑到别人的院子里,也不能随意动用院子外面的公共设施(除非得到管理员——也就是操作系统的明确许可,并且通常还需要主人的同意——也就是用户的授权)。现在,我们将目光投向应用的“家”——那个由操作系统精心构建的、受限但安全的环境。

qq_38334677的博客 3833

SPI模式下的SD卡读写,为什么你的数据总出错?详解时序与状态机避坑指南

本文深入探讨SPI模式下SD卡读写数据出错的根本原因,提供时序优化与状态机设计的实战指南。针对时钟周期计数、状态机跳转和忙检测等核心问题,详解命令时序细节、状态机同步策略及高级避坑技巧,帮助开发者提升SD卡在SPI模式下的稳定性和性能。

weixin_30514745的博客 269

霜冰优化算法(RIME)详解:从自然现象到智能优化

霜冰优化算法(RIME)是一种新型元启发式优化算法,灵感源于自然界中霜冰的形成过程。该算法通过模拟软霜和硬霜的不同生长特性,实现了高效的全局探索和局部开发平衡。RIME算法包含三个核心机制:软霜搜索策略模拟随机覆盖特性实现全局探索;硬霜穿刺机制模拟定向生长特性进行局部开发;正向贪婪选择机制确保解的持续优化。与遗传算法、粒子群算法相比,RIME具有参数少、收敛快、自适应平衡等优势,特别适合处理高维复杂优化问题。算法已在工程优化、机器学习等领域获得广泛应用,发表一年内即成为高被引论文。

qq_42212808的博客 792

iOS逆向工程及检查工具

iOS的沙盒機制 在 iOS 開發中,每一個 App 的資料都會處於自己的一個沙盒之中,App 之間不能存取資料的, 除非是在 iOS8 之後使用了App Group的機制,讓同一個 Team 的 App 之間可以共享資料。 沙盒的結構 Documents 一般用來存放持久化的數據,比如對話紀錄。 而 iTunes 也會幫忙進行備份,所以在網路上可以看到一些關於如何備份 Line 聊天記錄的教學文章(比如上圖中的 db_fruits.sqlite3) Library 存放的是 Cac

2301_77472496的博客 1444

SAR图像去斑(Despeckling)研究的主流开源数据集

这些数据集专门用于训练监督学习去斑模型,提供了配对的含斑SAR图像和对应的无噪声参考图像(Ground Truth)。这些数据集主要用于目标检测/识别,但包含原始SAR图像,可用于。由于缺乏真实无噪声SAR图像,许多研究采用。

VectorShift的博客 141

ios沙箱模式开启_IOS沙盒基本机制(sandbox)

释放双眼,带上耳机,听听看~!iOS系统相对于Android(或Windows)系统来说比较安全的原因有很多,其中有一点就是苹果推出的沙盒机制,每个应用都有自己对应的沙盒,每个应用程序之间不能相互访问非本程序的沙盒,所以,iOS系统相对于其他的系统来说比较安全,再是从内存上来说相对于Windows来说也比较安全,Apple的应用程序在内存消耗过高时会收到内存警告,如果不及时处理的话应用程序会自动退...

weixin_39732506的博客 4353

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

ios文件管理,沙盒机制以及如何操作“文件”APP,把文件共享到文件app

iOS如何实现文件的存储模式是怎样的?如何实现文件的共享,以及如何实现两个app共同共享数据

j15087159186的博客 5022

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

iOS沙盒与Bundle详解及文件操作

iOS沙盒与Bundle详解及文件操作 一、iOS沙盒机制:         iOS应用程序只能在为该改程序创建的文件中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等。沙盒是系统为每一个应用程序生成的一个特定文件夹 ,文件夹的名字由十六进制数据组成,每一个应用程序的沙盒文件名都是不一样的,是由系统随机生成的。

zyk5219的博客 2955

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

swift 5.1 Json转换之Codable

对于开发的人员来说,接受后台的数据,并转换成自己的数据模型是常见的事情。但是作为苹果开发者,并没有一个很好的工具去直接转换,必须借助与第三方的开发的库。那么比较好用的有YYModel、MJExtension。当然还有其他的库。但是有个问题,对于第三方库,如果使用过多对于我们开发者来说并不是一件好事。简单分析一下:优点:功能强大,使用方便,提高开发效率,相对较安全出现bug几率较...

海阔天空的专栏 2472

Swift JSON解析实战:5个必须掌握的Codable高级用法

掌握Swift JSON解析难题?本文详解5个Codable高级用法,涵盖嵌套解析、自定义键映射、容错处理等实战技巧,提升开发效率。适用于网络请求与本地数据存储场景,代码简洁安全,值得收藏。

ProceShoal的博客 613

探索iOS沙盒:PAirSandbox,你的便捷文件管理工具

探索iOS沙盒:PAirSandbox,你的便捷文件管理工具 项目地址:https://gitcode.com/gh_mirrors/ai/AirSandbox 1、项目介绍 在iOS开发中,获取和分享设备上的沙盒文件往往是一项挑战,特别是对于调试阶段的日志文件处理。PAirSandbox正是为了解决这一问题而生的一个轻量级开源项目。它允许开发者轻松查看并共享iOS设备上的沙盒文件系统,无需复杂操...

gitblog_00093的博客 583

IOS开发必备-推荐一个 iOS 沙盒文件管理工具:免越狱、免 iTunes、原生

真机调试时想看看 App 里的数据库?这个工具比 Xcode 好用 10 倍

weixin_38261823的博客 187

IOS学习之IOS沙盒(sandbox)机制和文件操作

IOS学习之IOS沙盒(sandbox)机制和文件操作(一) 1、IOS沙盒机制 IOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等。 1.1、每个应用程序都有自己的存储空间 1.2、应用程序不能翻过自己的围墙去访问别的存储空间的内容 1.3、应用程序请求的数据

artwebs 1286
上一篇: iOS开发Swift-16-App的生命周期-AppDelegate和SceneDelegate
下一篇: iOS开发实战-仿小红书App开发-1-App创建与Git
临易i
博客等级 码龄6年 321粉丝 340原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值