Getting dyld_fatal_error after updating to Xcode 6 beta 4 using swift
Most extremely weird problems like this can be solved with a Clean & Build (or perhaps relaunch Xcode). You might also consider deleting the relevant folders from ~/Library/Developer/Xcode/DerivedData.
SwiftUI Xcode 11 beta 5 / 6: Type of expression is ambiguous without more context
After your update in your answer, I see some changes needed:
- Use
ObservableObject
(no need to useCombine.ObservableObject
) - Missing function
scanPassport
, I added a bogus one. willChange
no longer exists, it is nowobjectWillChange
. And it is autosynthesize for you.
import SwiftUI
class ClPassport : ObservableObject , Identifiable {
@Published var mrz : String = "" //{ didSet { update() } }
var isValid : Bool {
return true
}
func update() {
objectWillChange.send()
}
func getMRZKey() -> String {
return ""
}
}
struct ContentView : View {
@ObservedObject var passportDetails = ClPassport()
var body: some View {
ZStack{
VStack(alignment: .leading){
HStack{
Spacer()
Button(action: {
self.scanPassport( mrzKey: self.passportDetails.getMRZKey() )
}) {
Text("Read Chip")
.font(.largeTitle)
.foregroundColor(passportDetails.isValid ? .primary : Color.secondary.opacity(0.25))
.padding()
}.padding()
.background(Color.white.opacity(passportDetails.isValid ? 1 : 0.5))
.cornerRadius(15)
.padding()
.disabled( !passportDetails.isValid )
Spacer()
}
TextField("MRZ", text: $passportDetails.mrz)
}
}
}
func scanPassport( mrzKey: String ) {
//do stuff with mrzKey
}
}
macOS: Correct way of exposing Swift properties to Cocoa Bindings
@objc
is necessary to expose the property to the Objective-C runtime.
To make the property key-value observing compliant you have to add the dynamic
keyword
@objc dynamic var selectionIndexes = IndexSet()
and delete the ...ChangeValue(for
lines
SwiftUI @Binding update doesn't refresh view
You have not misunderstood anything. A View using a @Binding will update when the underlying @State change, but the @State must be defined within the view hierarchy. (Else you could bind to a publisher)
Below, I have changed the name of your ContentView to OriginalContentView and then I have defined the @State in the new ContentView that contains your original content view.
import SwiftUI
struct OriginalContentView: View {
@Binding var isSelected: Bool
var body: some View {
Button(action: {
self.isSelected.toggle()
}) {
Text(isSelected ? "Selected" : "Not Selected")
}
}
}
struct ContentView: View {
@State private var selected = false
var body: some View {
OriginalContentView(isSelected: $selected)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
How to use Cocoa bindings against Swift structs
You can't use Cocoa bindings with Swift structs.
The Cocoa bindings system is implemented on top of Key-Value Observing, and Key-Value Observing is implemented by creating a subclass to intercept the set<Property>:
messages sent to the observed object. Swift structs cannot have subclasses and don't necessarily use messages or function calls to set struct fields, so there is no way in general to intercept the setting of a Swift struct field.
The message complains about a lack of KVC compliance because Key-Value Coding defines the set<Property>:
(and <property>
getter) convention for message names.
XCTest Xcode 7 beta 3 swift 2 initiate View Controller from storyboard issue
Instead of making all my custom classes public to the test target. I use this new test declaration in swift 2
@testable import <my module name>
It works well now.
Related Topics
Where Is the .Camera Anchorentity Located
Swift Bindings Won't Work Xcode 6 Beta 5
Cast to a Metatype Type in Swift
How to Convert Int to Byte Array of 4 Bytes in Swift
Why Do I Need to Declare an Optional Value as Nil Explicitly in Struct - Swift
In Swift, What Does This Specific Syntax Mean
Swift Extension for Selected Class Instance
Error When Using Generic as Property Type in Swift
Hex String to Character in Pure Swift
How to Programmatically Change the Alpha of a Uivisualeffectview in a Navigationbar
How to Use JSON Arrays with Alamofire Parameters
Alamofire, Objectmapper, Realm: Nested Objects
Reusing Security Scoped Bookmark
Can't Use Concrete Subclass to Implement a Property in Protocol in Swift