{"id":206,"date":"2026-09-30T11:58:39","date_gmt":"2026-09-30T11:58:39","guid":{"rendered":"https:\/\/mohammadreza.me\/blog\/?p=206"},"modified":"2026-09-30T14:00:19","modified_gmt":"2026-09-30T14:00:19","slug":"class-vs-struct-in-swift-whats-the-real-difference","status":"publish","type":"post","link":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/","title":{"rendered":"Class vs. Struct in Swift: What are the Real Differences?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">(I wrote this with Swift in mind. The core ideas carry over to other languages like C#, though the details differ.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019m usually asked about the difference between classes and structs in interviews, especially more recently. So I decided to study it a bit more and write a simple article about it, so I can use it as a reference to refresh my memory later. (if it sounds like another blah blah article, you can skip it and jump to <a href=\"#interview-answer\" data-type=\"internal\" data-id=\"#interview-answer\">How should I answer this question in an interview<\/a> directly)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#introduction\" data-type=\"internal\" data-id=\"#introduction\">Introduction<\/a><\/li>\n\n\n\n<li><a href=\"#meet-the-two\" data-type=\"internal\" data-id=\"#meet-the-two\">Meet the Two: What Is a Struct and What Is a Class?<\/a>\n<ul class=\"wp-block-list\">\n<li><a href=\"#what-is-struct\" data-type=\"internal\" data-id=\"#what-is-struct\">What is a struct?<\/a><\/li>\n\n\n\n<li><a href=\"#what-is-class\">How about a class?<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><a href=\"#differences\" data-type=\"internal\" data-id=\"#differences\">What are the Differences?<\/a><\/li>\n\n\n\n<li><a href=\"#about-memory\" data-type=\"internal\" data-id=\"#about-memory\">Where They Live in Memory<\/a><\/li>\n\n\n\n<li><a href=\"#how-to-choose\" data-type=\"internal\" data-id=\"#how-to-choose\">When and How to Choose<\/a><\/li>\n\n\n\n<li><a href=\"#interview-answer\" data-type=\"internal\" data-id=\"#interview-answer\">How should I answer this question in an interview<\/a><\/li>\n\n\n\n<li><a href=\"#conclusion\">Conclusion<\/a><\/li>\n<\/ul>\n\n\n\n<hr id=\"introduction\" class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;ve written Swift for more than a week, you&#8217;ve faced this small decision over and over: should this be a <code>class<\/code> or a <code>struct<\/code>? At first it feels like a coin flip. Both let you bundle properties and methods together, both can conform to protocols, and both can have initializers. On the surface they look almost identical.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But the choice affects how your data is copied, how it&#8217;s stored, how bugs show up, and even how your code performs. Swift&#8217;s own standard library leans heavily on structs (<code>Int<\/code>, <code>String<\/code>, <code>Array<\/code>, and <code>Dictionary<\/code> are all structs), while much of UIKit is built on classes. That split isn&#8217;t an accident. Once you understand why, the decision gets much easier.<\/p>\n\n\n\n<hr id=\"meet-the-two\" class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Meet the Two: What Is a Struct and What Is a Class?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before comparing them, let&#8217;s look at each one on its own.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h4 id=\"what-is-struct\" class=\"wp-block-heading\">What is a struct?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A struct is a way to group related values into a single, custom type. Think of it as a small container of data with some behavior attached. You define what it holds (properties) and what it can do (methods), and Swift handles the rest.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct User {\n    var name: String\n    var age: Int\n\n    func greeting() -> String {\n        \"Hi, I'm \\(name)!\"\n    }\n}\n\nvar user = User(name: \"Reza\", age: 30)\nprint(user.greeting()) \/\/ Hi, I'm Reza!<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that you didn&#8217;t write an initializer. Swift generates one for you automatically. The most important thing to remember about a struct is that it&#8217;s a <strong>value type<\/strong>. Every time you pass it around or assign it to a new variable, you get your own copy. It behaves a lot like a plain number or a string: if you copy <code>5<\/code>, you don&#8217;t expect changing one copy to change the other.<\/p>\n\n\n\n<h4 id=\"what-is-class\" class=\"wp-block-heading\">How about a class?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A class is also a blueprint for a custom type with properties and methods, but it works more like a real &#8220;thing&#8221; that exists once and can be pointed to from many places.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class Player {\n    var name: String\n    var score: Int\n\n    init(name: String, score: Int) {\n        self.name = name\n        self.score = score\n    }\n\n    func addPoints(_ points: Int) {\n        score += points\n    }\n}\n\nlet player = Player(name: \"Sara\", score: 0)\nplayer.addPoints(10)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here you have to write your own <code>init<\/code>, and you can modify <code>score<\/code> even though <code>player<\/code> is declared with <code>let<\/code>. That&#8217;s because a class is a <strong>reference type<\/strong>. The variable doesn&#8217;t hold the object itself, only a reference to it. Anyone else holding that same reference is looking at the very same object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Classes also bring extra abilities that structs don&#8217;t have: they can inherit from other classes, they can be checked for identity, and they can clean up after themselves with a <code>deinit<\/code>.<\/p>\n\n\n\n<hr id=\"differences\" class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h3 class=\"wp-block-heading\">Hmm OK so What are the Differences?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The biggest difference is that <strong>structs are value types and classes are reference types<\/strong>. Everything else follows from that.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you assign a struct to a new variable, you get an independent copy:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct Point {\n    var x: Int\n    var y: Int\n}\n\nvar a = Point(x: 1, y: 2)\nvar b = a\nb.x = 99\n\nprint(a.x) \/\/ 1\nprint(b.x) \/\/ 99<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Changing <code>b<\/code> doesn&#8217;t touch <code>a<\/code>. Each has its own data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With a class, both variables point to the same instance:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class Counter {\n    var value = 0\n}\n\nlet c1 = Counter()\nlet c2 = c1\nc2.value = 5\n\nprint(c1.value) \/\/ 5<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here <code>c1<\/code> and <code>c2<\/code> are two names for one object. Change it through either and both see the change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A few other differences are worth knowing:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Inheritance.<\/strong> Classes can inherit from other classes. Structs can&#8217;t. If you want to share behavior across structs, you use protocols and extensions instead.<\/li>\n\n\n\n<li><strong>Initializers.<\/strong> Structs get a free memberwise initializer. Classes don&#8217;t, so you write your own <code>init<\/code>.<\/li>\n\n\n\n<li><strong>Mutability.<\/strong> A struct declared with <code>let<\/code> is fully immutable, including its properties. A class declared with <code>let<\/code> only means the reference can&#8217;t change, and you can still modify the properties inside it.<\/li>\n\n\n\n<li><strong>Identity.<\/strong> Classes have identity. You can ask whether two variables point to the <em>same<\/em> object using <code>===<\/code>. Structs only have equality (are the values the same?), never identity.<\/li>\n\n\n\n<li><strong>Deinitializers.<\/strong> Only classes have <code>deinit<\/code>, which runs when the last reference disappears. That&#8217;s useful for cleaning up resources like file handles or observers.<\/li>\n\n\n\n<li><strong>Reference counting.<\/strong> Classes are managed by ARC, so retain cycles and <code>weak<\/code>\/<code>unowned<\/code> references are something you have to think about. Structs don&#8217;t have that problem.<\/li>\n\n\n\n<li><strong>Objective-C interop.<\/strong> If you need to subclass <code>NSObject<\/code> or work with Objective-C APIs, you need a class.<\/li>\n<\/ul>\n\n\n\n<hr id=\"about-memory\" class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h3 class=\"wp-block-heading\">Where They Live in Memory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll often hear the short version: <em>structs live on the stack, classes live on the heap.<\/em> It&#8217;s a good starting point, but it&#8217;s only partly true.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>stack<\/strong> is fast and simple. Memory is allocated and freed automatically as functions are entered and exited, with almost no overhead. The <strong>heap<\/strong> is more flexible, since data can outlive the function that created it, but allocating and freeing memory there is slower and has to be tracked. That&#8217;s what ARC is doing for you behind the scenes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Class instances always live on the heap. The variable you hold is just a reference (a pointer) to it, and copying that variable copies the pointer, not the object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Structs are <em>often<\/em> stored on the stack, or directly inline inside whatever contains them. But there are plenty of exceptions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If a struct is a property of a class, it lives inside that class&#8217;s heap allocation.<\/li>\n\n\n\n<li>If a closure captures a struct, it may get moved to the heap.<\/li>\n\n\n\n<li>A struct with a large collection inside, like an <code>Array<\/code>, keeps the actual elements in a heap buffer. The struct itself only holds a small header pointing to it. Swift uses copy-on-write here, so copying the array is cheap until one copy is modified.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So the more accurate way to think about it is this: the value-versus-reference distinction is about <em>semantics<\/em>, meaning how your code behaves. Stack versus heap is an <em>optimization detail<\/em> the compiler is allowed to choose. Design around the semantics and let the compiler worry about placement.<\/p>\n\n\n\n<hr id=\"how-to-choose\" class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">When and How to Choose<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apple&#8217;s own guidance is to <strong>start with a struct<\/strong> and switch to a class only when you have a reason. I agree with that. Here&#8217;s how I usually decide.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Reach for a struct when:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The type is mostly <em>data<\/em>: a user profile, a coordinate, a network response model, a configuration.<\/li>\n\n\n\n<li>Equality should be based on values. Two <code>Point(x: 1, y: 2)<\/code> instances are the same thing regardless of where they came from.<\/li>\n\n\n\n<li>You want safety. Since every copy is independent, nobody can change your data from somewhere else in the app.<\/li>\n\n\n\n<li>You don&#8217;t need inheritance.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Reach for a class when:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need <strong>shared, mutable state<\/strong>, where multiple parts of the app must see the same instance and its changes. A database connection, a cache, or an audio player are good examples.<\/li>\n\n\n\n<li><strong>Identity matters.<\/strong> This object represents one specific thing, not just a bundle of values.<\/li>\n\n\n\n<li>You need <strong>inheritance<\/strong> or Objective-C interoperability, which is common with UIKit (<code>UIViewController<\/code>, <code>UIView<\/code>) and other framework base classes.<\/li>\n\n\n\n<li>You need <code>deinit<\/code> to clean up when the object goes away.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A quick gut-check I like is to ask: <em>&#8220;If I copied this, would it still make sense?&#8221;<\/em> A copy of a coordinate makes perfect sense. A copy of a network manager or a live camera session usually doesn&#8217;t, because there should only be one of them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also keep in mind that this isn&#8217;t an either\/or choice for a whole app. Many well-designed codebases use structs for models and state, and classes for the few objects that own resources or coordinate work. In SwiftUI, for example, your views and most of your data are structs, while shared observable state is often a class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One last practical warning: don&#8217;t pick a class &#8220;for performance&#8221; without measuring. Copying small structs is cheap, and heap allocation plus reference counting can actually cost more. Choose based on meaning first, then optimize if a profiler tells you to.<\/p>\n\n\n\n<hr id=\"interview-answer\" class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">How should I answer it in a interview?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I would say something like:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">The biggest difference is that a struct is a value type and a class is a reference type. When you copy a struct, you get a new independent copy. When you copy a class, both variables point to the same object in memory. Also, classes support inheritance and have deinitializers, but structs don&#8217;t. In my daily work, I use struct by default. I only choose class when I need shared state, identity, or inheritance.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible follow-up question:<\/strong> &#8220;What is copy-on-write, and does it apply to structs?&#8221;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Answer:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy-on-write means Swift doesn&#8217;t copy the data right away when you assign a collection to another variable. Both variables share the same storage until one of them changes something. Only then does Swift make a real copy. So we get value semantics, but we don&#8217;t pay the cost of copying every time. It&#8217;s built into Array, Dictionary, and String. For our own structs it doesn&#8217;t happen automatically. We need to implement it ourselves, for example with <code>isKnownUniquelyReferenced<\/code>.<\/p>\n<\/blockquote>\n\n\n\n<hr id=\"conclusion\" class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Classes and structs look like twins, but they behave very differently because of one idea: structs are copied, and classes are shared. That single difference shapes how safe your code is, how easy it is to reason about, and how your data moves through memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Default to structs. They&#8217;re simpler, safer, and fit naturally with how Swift is designed. When you genuinely need shared state, identity, inheritance, or cleanup logic, switch to a class and do it on purpose. If you&#8217;re ever unsure, go back to that small question: does it make sense to copy this thing? Your answer will usually tell you what you need to know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(I wrote this with Swift in mind. The core ideas carry over to other languages like C#, though the details differ.) I\u2019m usually asked about the difference between classes and structs in interviews, especially more recently. So I decided to study it a bit more and write a simple article about it, so I can &hellip; <a href=\"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Class vs. Struct in Swift: What are the Real Differences?<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[34,17],"class_list":["post-206","post","type-post","status-publish","format-standard","hentry","category-swift","tag-foundation","tag-swift"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Class vs. Struct in Swift: What are the Real Differences? - Swift with Reza<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Class vs. Struct in Swift: What are the Real Differences? - Swift with Reza\" \/>\n<meta property=\"og:description\" content=\"(I wrote this with Swift in mind. The core ideas carry over to other languages like C#, though the details differ.) I\u2019m usually asked about the difference between classes and structs in interviews, especially more recently. So I decided to study it a bit more and write a simple article about it, so I can &hellip; Continue reading Class vs. Struct in Swift: What are the Real Differences? &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/\" \/>\n<meta property=\"og:site_name\" content=\"Swift with Reza\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-30T11:58:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-30T14:00:19+00:00\" \/>\n<meta name=\"author\" content=\"Reza\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Reza\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/\"},\"author\":{\"name\":\"Reza\",\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/#\\\/schema\\\/person\\\/9ab155944216224664701a81bc56cf8c\"},\"headline\":\"Class vs. Struct in Swift: What are the Real Differences?\",\"datePublished\":\"2026-09-30T11:58:39+00:00\",\"dateModified\":\"2026-09-30T14:00:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/\"},\"wordCount\":1647,\"commentCount\":0,\"keywords\":[\"Foundation\",\"Swift\"],\"articleSection\":[\"Swift\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/\",\"url\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/\",\"name\":\"Class vs. Struct in Swift: What are the Real Differences? - Swift with Reza\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/#website\"},\"datePublished\":\"2026-09-30T11:58:39+00:00\",\"dateModified\":\"2026-09-30T14:00:19+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/#\\\/schema\\\/person\\\/9ab155944216224664701a81bc56cf8c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/2026\\\/09\\\/30\\\/class-vs-struct-in-swift-whats-the-real-difference\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Class vs. Struct in Swift: What are the Real Differences?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/\",\"name\":\"Swift with Reza\",\"description\":\"Yet another Swift blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/#\\\/schema\\\/person\\\/9ab155944216224664701a81bc56cf8c\",\"name\":\"Reza\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1a4d35be7e8c853112a49822b1ccc907e5855a115f93d587800a7d71f2255f01?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1a4d35be7e8c853112a49822b1ccc907e5855a115f93d587800a7d71f2255f01?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1a4d35be7e8c853112a49822b1ccc907e5855a115f93d587800a7d71f2255f01?s=96&d=mm&r=g\",\"caption\":\"Reza\"},\"sameAs\":[\"http:\\\/\\\/mohammadreza.me\\\/blog\"],\"url\":\"https:\\\/\\\/mohammadreza.me\\\/blog\\\/author\\\/mohammadreza\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Class vs. Struct in Swift: What are the Real Differences? - Swift with Reza","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/","og_locale":"en_US","og_type":"article","og_title":"Class vs. Struct in Swift: What are the Real Differences? - Swift with Reza","og_description":"(I wrote this with Swift in mind. The core ideas carry over to other languages like C#, though the details differ.) I\u2019m usually asked about the difference between classes and structs in interviews, especially more recently. So I decided to study it a bit more and write a simple article about it, so I can &hellip; Continue reading Class vs. Struct in Swift: What are the Real Differences? &rarr;","og_url":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/","og_site_name":"Swift with Reza","article_published_time":"2026-09-30T11:58:39+00:00","article_modified_time":"2026-09-30T14:00:19+00:00","author":"Reza","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Reza","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/#article","isPartOf":{"@id":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/"},"author":{"name":"Reza","@id":"https:\/\/mohammadreza.me\/blog\/#\/schema\/person\/9ab155944216224664701a81bc56cf8c"},"headline":"Class vs. Struct in Swift: What are the Real Differences?","datePublished":"2026-09-30T11:58:39+00:00","dateModified":"2026-09-30T14:00:19+00:00","mainEntityOfPage":{"@id":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/"},"wordCount":1647,"commentCount":0,"keywords":["Foundation","Swift"],"articleSection":["Swift"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/","url":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/","name":"Class vs. Struct in Swift: What are the Real Differences? - Swift with Reza","isPartOf":{"@id":"https:\/\/mohammadreza.me\/blog\/#website"},"datePublished":"2026-09-30T11:58:39+00:00","dateModified":"2026-09-30T14:00:19+00:00","author":{"@id":"https:\/\/mohammadreza.me\/blog\/#\/schema\/person\/9ab155944216224664701a81bc56cf8c"},"breadcrumb":{"@id":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mohammadreza.me\/blog\/2026\/09\/30\/class-vs-struct-in-swift-whats-the-real-difference\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mohammadreza.me\/blog\/"},{"@type":"ListItem","position":2,"name":"Class vs. Struct in Swift: What are the Real Differences?"}]},{"@type":"WebSite","@id":"https:\/\/mohammadreza.me\/blog\/#website","url":"https:\/\/mohammadreza.me\/blog\/","name":"Swift with Reza","description":"Yet another Swift blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mohammadreza.me\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mohammadreza.me\/blog\/#\/schema\/person\/9ab155944216224664701a81bc56cf8c","name":"Reza","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1a4d35be7e8c853112a49822b1ccc907e5855a115f93d587800a7d71f2255f01?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1a4d35be7e8c853112a49822b1ccc907e5855a115f93d587800a7d71f2255f01?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1a4d35be7e8c853112a49822b1ccc907e5855a115f93d587800a7d71f2255f01?s=96&d=mm&r=g","caption":"Reza"},"sameAs":["http:\/\/mohammadreza.me\/blog"],"url":"https:\/\/mohammadreza.me\/blog\/author\/mohammadreza\/"}]}},"wps_subtitle":"","_links":{"self":[{"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/posts\/206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/comments?post=206"}],"version-history":[{"count":22,"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/posts\/206\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/posts\/206\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/media?parent=206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/categories?post=206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohammadreza.me\/blog\/wp-json\/wp\/v2\/tags?post=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}