Empty vars when calling method from singleton class
Its hard to understand what is going on. But you are subclassing a Jukebox class. Then making this subclass a delegate of the Jukebox itself. Then I also notice you're setting a Jukebox property that appears to be optional but not.
For example. Why in the play() function is jukebox. used twice but the last line is jukebox?. Is jukebox optional? Or implicitly unwrapped? And if thats the case, why are you using it unwrapped twice and then optionally the third time.
Have you tried not making this singleton a subclass of jukebox. Instead just make it conform to the JukeBoxDelegate protocol and see if that accomplishes the same goal?
How to stop recreating @state variable after recreating view in SwiftUI
Small example : The add in the subview update the dictionnaire for the desired user in parent view
import SwiftUI
struct UpdateUsersDict: View {
@State var myDict: [String: Double] = [:]
@State var amount: Double = 100
var body: some View {
VStack {
HStack {
OneUserView(myDict: $myDict, amount: amount, tag: "user 1")
OneUserView(myDict: $myDict, amount: amount, tag: "user 2")
OneUserView(myDict: $myDict, amount: amount, tag: "user 3")
}
HStack {
Text("\(myDict["user 1"] ?? -1)")
Text("\(myDict["user 2"] ?? -1)")
Text("\(myDict["user 3"] ?? -1)")
}
}
}
}
struct OneUserView: View {
@Binding var myDict: [String: Double]
@State var amount: Double
var tag: String
var body: some View {
HStack(alignment: .top) {
Button(tag, action: {
self.myDict[self.tag] = amount
})
}
}
}
struct UpdateUserDict_Previews: PreviewProvider {
static var previews: some View {
UpdateUsersDict()
}
}
pass qr image to another view controller
what are you doing:
let image: UIImage = UIImage() // <- its create image
let imageView: UIImageView = UIImageView() // its create some kind of container
imageView = image // ERROR!
you trying to set object with type UIImage to object with type UIImageView
correct:
let image: UIImage = UIImage()
let imageView: UIImageView = UIImageView()
imageView.image = image
Access var from rootViewController in CollectionViewCell in Swift
You must conditionally cast the rootViewController. Your current code only knows that it is a UIViewController, but in order for it to use your variable, it needs to know that it is an instance of your subclassed view controller, ViewController
.
Replacing your MainCollectionViewCell.init
with this should fix the problem:
if let cvc = self.window!.rootViewController as? ViewController {
var testStringFromMainView = cvc.test
}
Please note that due to the conditional unwrapping, which is much safer than forced unwrapping, this code will not be executed if the rootViewController
is not an instance of class ViewController
. In other words, you need to look into global variables if your app will have multiple view controllers.
Objective-C isEmpty helper suddenly stopping build
It sounds like the problem is that some class(es) in the framework/library declares a -count
method that returns something different than -[NSArray count]
(etc.).
Even when you're sending a message to an object of unknown (id
) type, the compiler needs to know some information about the method that will be called, including the return type. In short, this is because the message send path is different depending on the return type of the method that will be called. In cases like your code, the compiler will look for any method declared in the project with a name matching the message you're sending, and assume that's the method that will be called for the purposes of figuring out return type, etc. In this case, it's finding two different methods with the same name, but which have differing return types, and therefore doesn't know the exact semantics required for sending the count
message.
The quick and dirty solution is to change the cast in your isEmpty()
function to [(NSArray *)thing count]
. This should work fine as long as you never call isEmpty()
with instances of whatever class it is that has a different -count
method.
Related Topics
Invalid Signature - Code Object Is Not Signed at All
Change Table to Edit Mode and Delete Rows Inside a Normal Viewcontroller
Randomly Choosing an Item from a Swift Array Without Repeating
Bridge Google Drive API to Swift
Uiwebview VS Wkwebview to Load Local HTML
MySQL and Swift - Upload Image and File || Would It Be Better to Use Alamofire
Swift 3.0, Alamofire 4.0 Extra Argument 'Method' in Call
Corenfc Not Reading Uid in iOS
How to Count Rows in a Parse Class Programmatically in an iOS App Using Swift
Pass Variables to a New View Controller via a Subclass and Dozens of Map Pins
How to Use Charles Proxy on the Xcode 6 (iOS 8) Simulator
Drawrect Circle and Animate Size/Color
Uiscrollview in Storyboard Not Working with iOS 8 Size Classes and Autolayout
Wait for Async Task to Finish Completion Block Before Returning in App Delegate
Why Tesseract Ocr Library (Ios) Cannot Recognize Text at All
Xcode Instruments Allocations: Look at Live Bytes or Overall Bytes