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

推荐订阅源

S
Security @ Cisco Blogs
H
Hacker News: Front Page
P
Privacy International News Feed
N
News and Events Feed by Topic
T
Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
K
Kaspersky official blog
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
L
Lohrmann on Cybersecurity
Jina AI
Jina AI
P
Proofpoint News Feed
AI
AI
雷峰网
雷峰网
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 叶小钗
Webroot Blog
Webroot Blog
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
罗磊的独立博客
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
S
Security Affairs
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
月光博客
月光博客
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Securelist
W
WeLiveSecurity
T
Troy Hunt's Blog
A
Arctic Wolf
博客园 - 司徒正美

博客园 - 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, 禁止转载 🈲️,侵权必究⚠️!