Ann Knowledge Hub
  • 📚Home
  • Bash
  • 🔀git
  • 🤖AI / ML / Gen AI
    • Generative AI - A Primer
    • Course Notes - Google ML Intro
  • 🎯How To Guides
  • 🔖Good Reference Articles
  • 📳Mobile Development
    • iOS
      • Useful Information
      • Debugging Tricks
      • ViewController Concepts
      • Nullability Annotations
      • UI Testing XCTestUI
      • Xcode Concepts
    • Mobile Application Services
    • AB Testing
    • Firebase
    • Good Articles Blogs
    • iOS Troubleshooting
    • Cocoapods Troubleshooting
  • 💯Miscellaneous
    • Google Calendar API
  • 🌐Web Development
    • 📚Learning Resources
    • 🔎Troubleshooting Issues
Powered by GitBook

About Me

  • My blog
  • GitHub

© 2024 Ann Catherine Jose

On this page

Was this helpful?

Edit on GitHub
  1. Mobile Development
  2. iOS

Nullability Annotations

PreviousViewController ConceptsNextUI Testing XCTestUI

Last updated 6 years ago

Was this helpful?

Two groups of nullability annotations -_Nullable/_Nonnull and nullable/nonnull. The lowercase one is more elegant and works for almost all scenarios:

  • Method declarations - write the annotation right after the open parenthesis of the parameter

    • - (nullable NSString *) getItemWithIdentifier:(nonnull NSString*)identifier;

  • Property declarations - write the annotation in the attributes list

    • @property (copy, nonnull) NSString* name;

  • You can also define Nullability regions to mark specific regions in the file to consider any pointer type to be nonnull. So you need to explicitly mark only nullable properties/parameters

    • NS_ASSUME_NONNULL_BEGIN and NS_ASSUME_NONNULL_END

Source:

📳
https://developer.apple.com/swift/blog/?id=25