Suppose I define variable in one class, ViewController
, and want to access that variable from another class, say BLEHandler
. How do I go about doing that? I've had trouble with NSUserDefaults
, so a method besides that would be greatly appreciated.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
One way is to create a variable in app delegate. Its global to your view controllers.
Don't worry
There are may ways you can pass value between viewControllers For example
Different way is used in different case.
If you use prepareFoSegue- is used when you want to pass when perform segue
If you use notificationcenter - blind notification,one vc send message,may more than one to receive. In send message vc
In receive message vc Register first
Than you get the value from the selector
Do not forget to remove
If you use delegate - the receiver and sender has a connection first. There are may post about this,I will not post example.
If you use singleton - you have to be clear about the life circle of singleton. I do not suggest to pass value in this way.