惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
W
WeLiveSecurity
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
A
Arctic Wolf
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
G
GRAHAM CLULEY
O
OpenAI News
S
Schneier on Security
Google Online Security Blog
Google Online Security Blog
Vercel News
Vercel News
宝玉的分享
宝玉的分享
Attack and Defense Labs
Attack and Defense Labs
T
The Blog of Author Tim Ferriss
量子位
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
P
Privacy & Cybersecurity Law Blog
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 热门话题
博客园_首页
F
Full Disclosure
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Docker
U
Unit 42
A
About on SuperTechFans
博客园 - 司徒正美
Hacker News - Newest:
Hacker News - Newest: "LLM"
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog

博客园 - xgqfrms

xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs Remotion Video Maker All In One git worktree All In One Tesla 的车机使用什么技术来渲染汽车模型的? 宜家 VEVELSTAD 维维斯托床架 All In One macOS sysmond bug All In One Three.js All In One The COF of LCD Monitor All In One Dell 显示器 S2419HM 灰屏 &花屏 All In One AI Harness Engineering All In One 电脑外接显示器天梯榜 All In One How to change the speed display unit of GSP from mph to km/h using GoPro Labs All In One WHCA 白宫记者协会 All In One Pascal Editor All In One 主流犬种图解指南 All In One 泡沫喷雾 & 辣椒喷雾 All In One 如何给身份证照片添加水印 All In One GoPro MISSION 1 PRO price All In One 杭州历史天气数据 All In One Pandoc All In One GoPro MISSION 1 SERIES All In One GoPro telemetry 中的 GPS5 与 GPS9 是什么 All In One xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs OpenCode All In One OpenClaw 设置 cron 定时任务 All In One free MongoDB Cloud API All In One 如何在 Raspberry Pi 安装 OpenClaw All In One free cloud LLM models API All In One Claude Code Free Video Tutorials All In One 如何解决 OpenClaw 升级后导致 feishu plugin 无法使用的问题 All In One Claude Code skills & plugins All In One LLM Benchmark All In One How to fix use the FileZilla FTP upload file error All In One
xgqfrms, cnblogs, blogs
xgqfrms · 2026-07-08 · via 博客园 - xgqfrms

SwiftData All In One

https://developer.apple.com/documentation/swiftdata

@Model 注解 修饰器


import SwiftUI
import SwiftData

@Model
class RemoteImage {
  var sourceURL: URL
  var data: Data
  
  init(sourceURL: URL, data: Data = Data()) {
    self.sourceURL = sourceURL
    self.data = data
  }
}

expand marco

image


import SwiftUI
import SwiftData

@Model
class RemoteImage {
  @_PersistedProperty
  var sourceURL: URL
  @_PersistedProperty
  var data: Data
  
  init(sourceURL: URL, data: Data = Data()) {
    self.sourceURL = sourceURL
    self.data = data
  }
  @Transient
  private var _$backingData: any SwiftData.BackingData<RemoteImage> = RemoteImage.createBackingData()

  public var persistentBackingData: any SwiftData.BackingData<RemoteImage> {
    get {
      return _$backingData
    }
    set {
      _$backingData = newValue
    }
  }

  static var schemaMetadata: [SwiftData.Schema.PropertyMetadata] {
    return [
      SwiftData.Schema.PropertyMetadata(name: "sourceURL", keypath: \RemoteImage.sourceURL, defaultValue: nil, metadata: nil),
      SwiftData.Schema.PropertyMetadata(name: "data", keypath: \RemoteImage.data, defaultValue: nil, metadata: nil)
    ]
  }

  required init(backingData: any SwiftData.BackingData<RemoteImage>) {
    _sourceURL = _SwiftDataNoType()
    _data = _SwiftDataNoType()
    self.persistentBackingData = backingData
  }

  @Transient private let _$observationRegistrar = Observation.ObservationRegistrar()

  internal nonisolated func access<_M>(
    keyPath: KeyPath<RemoteImage, _M>
  ) {
    _$observationRegistrar.access(self, keyPath: keyPath)
  }

  internal nonisolated func withMutation<_M, _MR>(
    keyPath: KeyPath<RemoteImage, _M>,
    _ mutation: () throws -> _MR
  ) rethrows -> _MR {
    try _$observationRegistrar.withMutation(of: self, keyPath: keyPath, mutation)
  }

  struct _SwiftDataNoType {
  }
}
extension RemoteImage: SwiftData.PersistentModel {
}

extension RemoteImage: Observation.Observable {
}

https://developer.apple.com/documentation/swiftdata/model()

https://developer.apple.com/documentation/swiftdata/persistentmodel

Core Data

image

image

image

https://developer.apple.com/documentation/coredata

image

.xcdatamodeld

https://developer.apple.com/documentation/coredata/creating-a-core-data-model

SwiftData vs Core Data

SwiftData 新版
Core Data 旧版
混合版,保留 Core Data + 渐进式 SwiftData

image

https://developer.apple.com/documentation/CoreData/adopting-swiftdata-for-a-core-data-app

https://developer.apple.com/documentation/coredata/core-data-model

demos

@attached(member, conformances: Observable, PersistentModel, Sendable, names: named(_\(backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_\)observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) macro Model()

// provide conformance to the PersistentModel and Observable protocols.

@Model
class RemoteImage {
    var sourceURL: URL
    var data: Data

    init(sourceURL: URL, data: Data = Data()) {
        self.sourceURL = sourceURL
        self.data = data
    }
}

import SwiftData

// Annotate new or existing model classes with the @Model macro.
@Model
class Trip {
    var name: String
    var destination: String
    var startDate: Date
    var endDate: Date
    var accommodation: Accommodation?
}

https://developer.apple.com/documentation/swiftdata/preserving-your-apps-model-data-across-launches

Observable

https://developer.apple.com/documentation/Observation/Observable

Codable

https://developer.apple.com/documentation/Swift/Codable

Storyboard vs SwiftUI

Storyboard 可以选择 Swift / Objective-C

image

Storyboard 只能使用 Core Data

image
image

Objective-C 测试只能选择 XCTest

image

Swift 测试可以选择 XCTest / Swift Testing

image

SwiftUI 必须使用 Swift

image

SwiftUI 可以选择 SwiftData / Core Data

image

Swift 测试可以选择 XCTest / Swift Testing

image

refs

https://www.hackingwithswift.com/quick-start/swiftdata

https://www.hackingwithswift.com/quick-start/swiftdata/swiftdata-vs-core-data



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!