Provide a super-easy way for Apple Developers to Read and Write NFC Tags on SwiftUI.
| Tested on | Latest | Compatible |
|---|---|---|
| iOS | 16 | > 14 |
Apple Watch is well-known not supported. iPad / Mac is compatible with CoreNFC but there is no hardware to support this feature. 😂
Compatible ✅
Xcode Cloud requires Apple Developer Program membership.
- Add to your project via Package Manager.
- Add
Near Field Communication Tag Reading(aka NFC) into the Project's Combilities.
- Add NFC Privacy into
Info.plist
- Import first.
import SwiftNFC- Add ObservedObject before
bodyor anysome View.
@ObservedObject var NFCR = NFCReader()@ObservedObject var NFCW = NFCWriter()func read() {
NFCR.read()
}
func write() {
NFCW.msg = NFCR.msg
NFCW.write()
}Both NFCReader and NFCWriter classes use @Published properties for automatic SwiftUI view updates:
startAlert- Alert message shown when scanning startsendAlert- Custom alert message after scanning (optional)msg- Decoded NFC message content (updates after scan)raw- Raw NFC data with type, identifier, and payload information
startAlert- Alert message shown when writing startsendAlert- Custom alert message after writing (optional)msg- Content to write to the NFC tagtype- Record type: "T" for text (default) or "U" for URI
These properties automatically trigger view updates when changed, enabling seamless SwiftUI integration with two-way bindings:
// Example: Bind to a TextField
TextField("Message", text: $NFCW.msg)
// Example: Display scan results
Text(NFCR.msg)Path: ./Demo (Xcode Project in SwiftUI)
MIT
Q1. How can I contribute to the project?
A1. Simply pull a request, and someone will review your code. If everything is okay, your changes will be merged and reflected in the next minor version.
Q2. Can I use it in Educational (includ. Student's Homework, Class's demo) or NGO or Commerical Project?
A2. YES. This project is under license of MIT. Feel free to use it :)




