I am using your new BlinkIDUI sdk for iOS and I can have the list of all the scanned fields from "recognitionResult.resultEntries" like Secondary ID = Jason", "Primary ID = Bourne", "Sex = F", "Date Of Birth = 3/23/83", "Nationality = UAE", "Document Code = P" from the delegate method "- (void)didScanEntireDocumentWithRecognitionResult:(MBRecognitionResult * _Nonnull)recognitionResult successFrame:(UIImage * _Nullable)successFrame". My query is How to get value for particular key like “"Document Code” ?
Additional Details are:
The Framework addition in Project: Manual.
Xcode version : 10.1.
Language: Objective-C (ARC OFF).
Device: iPhone8 / iOS(11.1.1)
That's because resultEntries is an array not a dictionary,
Use like this:
for (MBField *field in recognitionResult.resultEntries) {
if (field.key == MBFieldKeyDocumentCode) {
}
}
If you are using it in ObjectiveC project then also check if #objc tag is there in front of MBFieldKey public property in "MBField" class, if it is not there just put it as:
public class MBField: NSObject {
#objc public let key: MBFieldKey
#objc public let value: String
.....
}
Related
I have a moshi PolymorphicJsonAdapterFactory and it works great.
.withSubtype(ColdWeather::class.java, "Cold")
.withSubtype(HotWeather::class.java, "Hot")
.withDefaultValue(//how to grab the label)
The method withDefaultValue is a great catch all, but my BE team wants me to log the actual label that comes down in order to help catch a bug that's going on on their end. As far as I can tell... in the withDefaultValue I can't grab a reference to the label which in this case the backend is sending back "Medium".
I feel like there must be a way to grab this label (but I'm missing something simple?) so I can log it and possibly propagate it in the withDefaultValue method.
I stumbled on the issue a while ago. I found it impossible to achieve with just using .withDefaultValue method. So far I did not find better solution other than .withFallbackJsonAdapter (I am using moshi version 1.12), which lets you parse the json manually in case the label is unknown to your PolymorphicJsonAdapterFactory adapter. The documentation says:
/**
* Returns a new factory that with default to {#code fallbackJsonAdapter.fromJson(reader)} upon
* decoding of unrecognized labels.
*
* <p>The {#link JsonReader} instance will not be automatically consumed, so make sure to consume
* it within your implementation of {#link JsonAdapter#fromJson(JsonReader)}
*/
public PolymorphicJsonAdapterFactory<T> withFallbackJsonAdapter(
#Nullable JsonAdapter<Object> fallbackJsonAdapter) {
return ...
}
I assume your code is somewhat like this (simplified):
interface Weather {
val type: String
}
#JsonClass(generateAdapter = true)
class ColdWeather( #Json(name = "type") override val type: String) : Weather
#JsonClass(generateAdapter = true)
class HotWeather( #Json(name = "type") override val type: String) : Weather
val weatherAdapter = PolymorphicJsonAdapterFactory.of(Weather::class.java, "type")
.withSubtype(ColdWeather::class.java, "Cold")
.withSubtype(HotWeather::class.java, "Hot")
and you receive a json similar to this:
{
"weather" : {
"type" : "Cold"
}
}
To receive an unknown label, I would do something like this:
class UnknownWeather(override val type: String) : Weather
val weatherAdapter = PolymorphicJsonAdapterFactory.of(Weather::class.java, "type")
.withSubtype(ColdWeather::class.java, "Cold")
.withSubtype(HotWeather::class.java, "Hot")
.withFallbackJsonAdapter((object : JsonAdapter<Any>() {
override fun fromJson(reader: JsonReader): UnknownWeather {
var type = ... // parse it from the reader
return UnknownWeather(type)
}
override fun toJson(writer: JsonWriter, value: Any?) {
// nothing to do
}
}))
Of course that means that you will have to dig a bit into JsonReader, but it has a fairly understandable interface, you basically iterate through the properties of the json object and extract what you need, in our case just the "type" property.
FYI, seems like more people had problem with this: https://github.com/square/moshi/issues/784
If my model looks like:
type alias Application = { id : Int , term : Int , amount : Int }
type alias Model = { application : Application }
and I am trying to update the term value, I have onInput UpdateTerm on an input inside my update case statement how do I update this value?
so far I have UpdateTerm term ->; but unsure how I can update only the term value inside application?
Record field update is described in the guide and also in the reference documentation. Updating a field in a record nested inside another record is simply a matter of doing one after the other. Assuming you have a binding named model:
let
application =
model.application
updatedApplication =
{ application | term = term }
in
{ model | application = updatedApplication }
for a better readability you can make function like this:
update msg model =
case msg of
changeNestedProperty property ->
({ model | record= setNestedProperty property model.record } , Cmd.none)
setNestedProperty : String -> Record-> Record
setNestedProperty property record =
{ record | nestedProperty = property }
I am attempting to integrate this library with my RxSwift project, https://github.com/glenyi/FloatRatingView
I am unable to get the updated rating.
Here is how I have created the FloatRatingView in the Controller,
let starRater : FloatRatingView = {
let floatRatingView = FloatRatingView()
floatRatingView.emptyImage = UIImage(named: "EmptyStar")
return floatRatingView
}()
The Model contains the following,
let my_rating = Variable<Float?>(nil)
What I want to be able to do is to update the value in the my_rating variable when a user changes the rating by tapping on a star. Here is what I've written for this,
_ = starRater.rx.rating
.asObservable()
.bindTo(viewModel.my_rating.rx_value)
But here is the error I'm receiving.
Value of type 'Reactive FloatRatingView' has no member 'rating'
Here is how I will retrieve the value from my_rating variable,
let stars = self.my_rating.value
Kindly help me out. Thanks.
You need to add a bindable sink for the property, it would be something like this:
extension Reactive where Base: FloatRatingView {
/// Bindable sink for `rating` property
public var progress: UIBindingObserver<Base, Float> {
return UIBindingObserver(UIElement: self.base) { floatRatingView, rating in
floatRatingView.rating = rating
}
}
}
im new in Swift and X-Code. Im searching for a way import a own defined class (best case in an own document). I want store all needed settings (text-snippets and app-settings) in this file. For example:
class snippetsAndSettings {
// e.g translations
let t_welcome: String = "Welcome to my App"
let t_share: String = "Social Share Buttons"
let t_rate: String = "Rate"
// e.g settings
let s_weburl: String = "http://www.mypage.com/webservice.php"
let s_slider: Bool = false
let s_bgColor: String = "#ff9900"
let s_tColor: String = "#222222"
let t_shadow: String? // Bool or colorString!
}
I want to use this class on every app-page. But i can not import the for for example in ViewController.swift
My questions:
In which format do i have to save the file (snippetsAndSettings)? Cocoa Class
How can i import the file in my ViewController.Swift
Is this a common way to store own app-settings in Swift?
The method to store settings is via NSUserDefaults. You can setup your default values in your app delegate's application:didFinishLaunchingWithOptions: method. For example:
NSUserDefaults.standardUserDefaults().registerDefaults([
"volume": 100,
"showShadows": true
])
To get these back, you would do:
NSUserDefaults.standardUserDefaults().integerForKey("volume")
and
NSUserDefaults.standardUserDefaults().boolForKey("showShadows")
In Swift 5, it now looks like this:
UserDefaults.standard.register(defaults: [
"volume": 100,
"showShadows": true
])
And to get it back
let volume = UserDefaults.standard.integer(forKey: "volume")
let showShadows = UserDefaults.standard.bool(forKey: "showShadows")
For translations, you should look in to Internationalization and Localization
I am using Swift, Cocoa Bindings and Core Data in an OSX Xcode project to display an outline view which is bound to my entity "Series" and displays the attribute "name", which has a to-many relationship with itself.
I want my users to be able to enter only three levels: one root, a child and another child of that child.
Here is my subclass for Series:
#objc(Series)
class Series: NSManagedObject {
#NSManaged var isLeaf: NSNumber
#NSManaged var name: String
#NSManaged var parent: Series
#NSManaged var subGroups: NSSet
}
Effectively when the data is entered and saved, "isLeaf" should be changed to true for the third name entry. In this way, it would be impossible for the user to create a fourth entry.
I added this function to the Series subclass, so I could validate each new name entry:
func validateName(ioValue: AutoreleasingUnsafeMutablePointer<AnyObject?>,
error: NSErrorPointer) -> Bool {
if let test = ioValue.memory as? String {
if test != "" {
println("Name is \(test)")
// This is where we need to test for indentation level
}
} else {
}
return true
}
I'm pretty sure that what I need to do is test for the indentation level of the third entry and if it returns 2, then I need to change isLeaf from false to true.
Unfortunately, I do not know how to do this in practice. Does anyone have any suggestions, please?