Zum Hauptinhalt springen
LIVE
CVSS 7.0CVE-2026-138158 | libgphoto2 through 2.5.34 contains a stack buffer overflow in sierra_get_string_register() that lets a malicious sierra-protocol camera or USB device overwrite stack memory. When files are listed, the device can answer the file-name register with an oversized packet, writing up to 32 KB past small stack buffers to cause crashes or possible code execution.CVSS 7.7CVE-2026-138159 | edbrowse through 3.8.19 contains an integer overflow in stringAndBytes() that allows malicious servers to write past a heap buffer by sending response bodies larger than 2 GB. When a user browses to an attacker-controlled HTTP, FTP, or gopher server, the oversized body skips reallocation and corrupts the heap, causing crashes or potentially code execution.CVSS 8.5CVE-2026-138160 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ReadBackupTextLen() that allows attackers to overwrite stack memory via crafted backup files. Attackers can supply overlong quoted text values decoded into a 10,000-byte stack array during convertbackup, restore, or GSM_ReadBackupFile calls, causing crashes or potential code execution.CVSS 8.5CVE-2026-138161 | Gammu before 1.45.2 contains a buffer overflow vulnerability in LoadBackup() that allows attackers to corrupt memory by supplying an overlong MD5 value in a crafted backup file. Attackers can overwrite adjacent phonebook and calendar entry pointers via strcpy() into MD5Original when files are loaded with convertbackup or restore, causing crashes or potential code execution.CVSS 7.3CVE-2026-138162 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ALCATEL_EncodeString() that allows attackers to overwrite stack memory via oversized encoded phonebook text. Attackers can supply a crafted backup restored with gammu restore or addnew to an attached Alcatel phone, using GSM extension characters to crash Gammu or potentially execute code.CVSS 8.5CVE-2026-138163 | Gammu before 1.45.2 contains a heap-based buffer overflow in ReadWAPSettingsEntry() that allows attackers to corrupt heap memory via crafted backup files with excess WAP or MMS settings entries. Attackers can supply a backup with more than four TitleNN keys in a [WAPSettings] or [MMSSettings] section, loaded via convertbackup, restore, or GSM_ReadBackupFile, causing crashes or potential code execution.CVSS 4.8CVE-2026-138164 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in SaveBackupText() in backtext.c that allows attackers to corrupt stack memory by supplying long text fields. Attackers can craft a backup with long calendar or note fields that, when converted with gammu convertbackup, writes hex digits past the 10,000-byte stack buffer.CVSS 9.3CVE-2026-138154 | POSTAL 2 before build 26810491 contains a sandbox escape vulnerability that allows malicious Steam Workshop mods to execute code by calling ConsoleCommand with a start file URI. Attackers can ship a batch file in a mod at the predictable workshop install path and launch it via ShellExecuteW, executing commands as the player on Windows.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

Swift Structs — Static Properties and Methods 🏛️

Sometimes you want data or functionality to belong to a struct itself, not to any individual instance. That's what static properties and methods are for—let's b…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 5 Min. Lesezeit
Quelle: dev.to
Rubrik: Sichere Programmierung

Sometimes you want data or functionality to belong to a struct itself, not to any individual instance. That's what static properties and methods are for—let's break them down with some examples!



Every property and method we've added to our structs so far has belonged to instances — each Ninja you create has its own name, each Guild has its own gold. But sometimes you need data or functionality that belongs to the struct itself, shared across everything. That's where static comes in. 🍥









The Problem Static Solves



Imagine we're building an anime series tracker app and we want to keep a count of how many series have been registered — not on any one series, but across all of them:




struct AnimeSeries {
static var totalRegistered = 0

static func register(title: "String) {"
print("\(title) has been added to the tracker!")
totalRegistered += 1
}
}






Notice the static keyword on both the property and the method. This means they belong to AnimeSeries the type itself — not to any specific instance.



Here's how you use them:




AnimeSeries.register(title: "\"Naruto\")"
AnimeSeries.register(title: "\"One Piece\")"
AnimeSeries.register(title: "\"Attack on Titan\")"

print(AnimeSeries.totalRegistered) // 3






No instance needed — you call directly on AnimeSeries. That's the key difference: regular properties need an instance (var series = AnimeSeries()), static properties belong to the struct itself.









Why No mutating Keyword?



You might have noticed that register() modifies totalRegistered but isn't marked as mutating. That's because mutating is only needed for regular instance methods, to handle cases where the struct instance was created as a constant.



Static properties and methods don't belong to any instance, so there's no instance to be constant or variable — mutating simply doesn't apply here.









self vs Self — Two Different Things



Now that we have static members, there are two similar-looking keywords that mean very different things:





  • self (lowercase) — refers to the current instance of the struct


  • Self (uppercase) — refers to the current type itself




struct Ninja {
var name: String

func introduce() {
print("I am \(self.name)") // self = this specific ninja
}

static func describe() {
print("We are all \(Self.self)s") // Self = the Ninja type
}
}






A helpful way to remember: Swift types always start with a capital letter (Int, String, Bool) — and Self follows that same convention because it is a type.









Two Main Uses for Static






Use 1 — Storing Shared App Data



Static properties are perfect for storing data that's the same everywhere in your app — configuration, constants, shared settings:




struct AppConfig {
static let appVersion = "1.0.0"
static let maxEpisodesPerDay = 10
static let animeAPIBaseURL = "https://api.animelist.com"
}






Now anywhere in your app you need the version number or API URL, you just write AppConfig.appVersion or AppConfig.animeAPIBaseURL. No need to create an instance — you just read it directly from the type.



This is cleaner and safer than defining these as loose global constants floating around your codebase.






Use 2 — Example Instances for SwiftUI Previews



This one is especially useful in SwiftUI. When you're building a screen that displays a Ninja or an AnimeCharacter, SwiftUI lets you preview it in Xcode — but you need some sample data to fill it with.



The cleanest way to provide that is with a static let example property:




struct AnimeCharacter {
let name: String
let show: String
let powerLevel: Int

static let example = AnimeCharacter(
name: "Goku",
show: "Dragon Ball Z",
powerLevel: 9001
)
}






Now whenever you need a sample character to pass into a SwiftUI preview, you just write AnimeCharacter.example. It's always available, always consistent, and you didn't need to create a new instance just to test your UI.









Mixing Static and Non-Static



You can have both static and regular members in the same struct — but there are rules about how they interact:



From static code, you can't access non-static members:




struct AnimeSeries {
var title: String
static var totalRegistered = 0

static func showTitle() {
print(title) // ❌ Can't access — which instance's title would this be?
}
}






This makes sense: if you're in static code, there's no specific instance to read from.



From non-static code, you can access static members using the type name:




struct AnimeSeries {
var title: String
static var totalRegistered = 0

func describe() {
print("\(title) — Series #\(AnimeSeries.totalRegistered)") // ✅
}
}












Combining Static with Private



You can also combine static with access control from the last article. For example, if you want a counter that's shared across all instances but can only be changed through a controlled method:




struct AnimeEpisodeTracker {
private static var episodesWatched = 0

static func watch() {
episodesWatched += 1
print("Episodes watched today: \(episodesWatched)")
}

static func totalWatched() -> Int {
episodesWatched
}
}

AnimeEpisodeTracker.watch() // "Episodes watched today: 1"
AnimeEpisodeTracker.watch() // "Episodes watched today: 2"
print(AnimeEpisodeTracker.totalWatched()) // 2
// AnimeEpisodeTracker.episodesWatched // ❌ private — not accessible






The episodesWatched counter is shared across the entire app, but it's private so it can only be changed through watch().









A Quick Note on When to Use Static



Static properties and methods aren't something you'll reach for constantly — most of the time, regular instance properties and methods are what you need. But they shine in a handful of situations:





  • App-wide constants — version numbers, API endpoints, configuration values


  • Shared counters or state — something that tracks across all instances


  • SwiftUI preview data — static let example for sample instances


  • Utility methods — helper functions that don't need any instance data









Wrap Up




































Concept What It Means
static Belongs to the struct type itself, not to any instance
Static property Shared across all instances — accessed via the type name
Static method Called on the type directly, no instance needed
self The current instance
Self The current type
Common uses Shared app data, SwiftUI preview examples, utility methods





This article was written by me; AI was used to improve grammar and readability.

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Community-Diskussion & Kommentare

🌐 Zum Hauptchat

Starte die Diskussion im Social-Chat Broadcast Stream oder reiche oben über „Information ergänzen“ einen Fachbeitrag ein.

Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War dieser Artikel hilfreich?
0
Jetzt Bewertung abgeben
Detail-Bewertung (optional)
Inhalt & Qualität
Quelle & Glaubwürdigkeit
Aktualität
Security Briefing Kostenlos · 1-Klick-Abmeldung

Intelligence Digest — kostenlos

Täglich die wichtigsten Security-News · jederzeit abbestellbar

Verwandte Story-Cluster & Quellen (Vektor-KI)

2 Cluster
2 Quellen
CVE-2026-125718 | Adobe Campaign Classic sql injection (EUVD-2026-134345)
VulDB Updates vor 45 Min.
1 weitere Quelle
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Swift Structs — Static Properties and Methods 🏛️

Thematisch verwandte Begriffe: Swift, Structs, Static, Properties · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Widgets & Themen
Widgets werden geladen…
Nächster Beitrag