Zum Hauptinhalt springen
LIVE
CVSS 6.9CVE-2026-137684 | A security flaw has been discovered in eosphoros-ai DB-GPT up to 0.8.3. This affects the function editor_sql_run of the file packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/editor/api_editor_v1.py of the component Editor SQL Run API. Performing a manipulation of the argument db_name results in authorization bypass. It is possible to initiate the attack remotely. The exploit has been released to the public and may be used for attacks. The pull request to fixCVSS 8.7CVE-2026-137992 | libexpat through 2.11.0 contains a denial of service vulnerability in defineAttribute() of lib/xmlparse.c that fails to detect duplicate non-ID #IMPLIED or #REQUIRED attribute declarations. Attackers can supply a crafted XML document with repeated ATTLIST declarations in an internal DTD subset to cause quadratic CPU consumption in storeAtts() during parsing.CVSS 8.5CVE-2026-137994 | Leo through 6.8.10 contains an insecure deserialization vulnerability that allows attackers to execute code by embedding pickled data in unknown XML attributes of .leo outlines. Attackers can place a pickle __reduce__ gadget in a or element attribute that resolveUa passes to pickle.loads, executing code with user privileges when the outline is opened.CVSS 7.0CVE-2026-137995 | FOG Project before 1.6.0.119 contains an information disclosure vulnerability that allows unauthenticated attackers to obtain host tokens from status/hostgetkey.php by supplying a host MAC address. Attackers can present the token to service/hostinfo.php to retrieve decrypted Active Directory join credentials and Windows product keys during deployment windows.CVSS 6.8CVE-2026-137996 | Zettlr before 4.11.0 fails to validate URI schemes in Markdown link targets, allowing attackers to launch arbitrary registered protocol handlers via Electron shell.openExternal without confirmation. Attackers can craft documents whose Ctrl/Cmd-clicked links use smb:// to leak NTLM credential hashes on Windows or invoke custom protocol handlers with attacker-controlled parameters.CVSS 8.5CVE-2026-137997 | HCIPy through 0.7.1 contains an insecure deserialization vulnerability that allows attackers to execute code by supplying crafted .pkl files to read_field, read_grid or read_mode_basis. Because hcipy/util/io.py selects pickle by file extension and calls pickle.load, a __reduce__ gadget in a pupil, apodizer, PSF or mode-basis file runs code with the user's privileges.CVSS 8.5CVE-2026-137998 | Detoxify 0.5.3 through 0.5.4 contains an insecure deserialization vulnerability in load_checkpoint that allows attackers to execute code by supplying a crafted checkpoint file. Attackers can embed a pickle __reduce__ gadget in a .ckpt file loaded via torch.load with weights_only=False to run code with the user's privileges.CVSS 8.5CVE-2026-137999 | JSONSchema2PoPo2 through 3.0.3 contains a code injection vulnerability that allows attackers to inject Python code by supplying JSON Schema default or format values that are written unescaped. Attackers can place a single quote in a string property default to break out of the literal in the generated __init__ signature, executing injected code when the generated module is imported.
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:

💬 Topluluk tartışması ve yorumlar

🌐 Ana sohbete katıl

Tartışmayı başlat: Social Chat yayın akışı veya yukarıdaki ekleme formuyla uzman katkısı gönder.

Community Rating & Social Proof
⭐ Okuyucu Puanı
–
Ø / 5.0
Hiçbir okuyucu henüz yorum yok
Bu makale yararlı mıydı?
0
Değerlendirmenizi gönderin
Detaylı değerlendirme (isteğe bağlı)
İçerik ve Kalite
Kaynak ve Güvenilirlik
Güncellik
Security Briefing Ücretsiz · Tek tıkla abonelikten çıkma

Zeka Digest - ücretsiz

Günlük en önemli güvenlik haberi · herhangi bir zamanda alınabilir

İlgili Story Cluster & Kaynaklar (vector AI)

2 Cluster
2 Kaynaklar
OpenAI counter-sues Apple over trade secret theft
AppleInsider News 3 saat önce
1 başka bir kaynak
Benzer katkılar
🔍 Verwandte News

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

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

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Yorumlar yüklenir..
Update to Update
Widgets & Topics
Loading widgets…
Nächster Beitrag