Questions tagged [conditional-binding]

13 questions
19
votes
5 answers

Bound value in a conditional binding must be of Optional Type

I have a protocol defined: protocol Usable { func use() } and a class that conforms to that protocol class Thing: Usable { func use () { println ("you use the thing") } } I would like to programmatically test whether or not the…
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
7
votes
1 answer

Contextual bindings with Ninject 2.0

In Ninject 1.0 I had following binding definitions: Bind().To().Only(When.Context.Variable("variable").EqualTo(true)); Bind().To(); Given such bindings I had calls: ITarget target =…
5
votes
2 answers

Understanding syntax of closure with no return type

I am getting into swift for the first time here and I have stumbled across a closure statement that doesn't make a whole lot sense to me based off of my current understanding of how closures are written. This is really a two-part question because I…
sanch
  • 696
  • 1
  • 7
  • 21
4
votes
6 answers

Conditional variable binding in Common Lisp

I want to execute a function with 2 local variables, but the values of these of these variables should depend on some condition. For example, let's say I have 2 variables x and y, and I want to swap them inside let if y > x. The swap should be…
Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
3
votes
1 answer

Pattern match and conditionally bind in a single Switch statement

Is there a way to write this if/else if/else ladder as a switch statement? let x: Any = "123" if let s = x as? String { useString(s) } else if let i = x as? Int { useInt(i) } else if let b = x as? Bool { useBool(b) } else { …
Alexander
  • 59,041
  • 12
  • 98
  • 151
3
votes
2 answers

Parameter based bindings in ninject 2.0

I want to use conditional binding in ninject, based on passed parameters. I have something like below: public class Subject { } public interface ITarget { } public class Target1 : ITarget { } public class Target2 : ITarget { } And now I need to…
2
votes
1 answer

Conditional dependency injection binding only when property not null

It is a desktop application which is obliged to impersonate the current user when accessing the underlying data source. How can I tell Ninject not to bind the dependency until the property of a parent object is not null? Application forces user…
1
vote
2 answers

Conditionally binding to an existing property

I'm looking for a way to improve this pattern of code: struct Struct { let i: Int init?(i: Int?) { guard let unwrappedI = i else { return nil } self.i = unwrappedI } } It'd be nice to remove the unwrappedI temporary…
Alexander
  • 59,041
  • 12
  • 98
  • 151
1
vote
2 answers

How do you conditionally bind data?

How do I conditionally bind data to a combo box? I have a combo box that by default should display an ID. However, if the user checks a check box then the display should display both the ID and a NAME. For example, "OO1: Sam". I have the default ID…
GAR8
  • 293
  • 1
  • 5
  • 14
0
votes
3 answers

Vue Conditional Class Binding

I am trying to dynamically render class based off actionTypeCreate. This is a method that simply returns a boolean value based off the prop actionType that is passed. I am triggering this method on the mounted hook and confirmed it is returning…
Jeff Domain
  • 81
  • 1
  • 8
0
votes
1 answer

Initializer for conditional binding must have Optional type, not 'String' on HTTPCookieStorage

Not sure why I'm getting this error, but I get it when I updated to Swift 2. The error is on if let token = cookie.value { Initializer for conditional binding must have Optional type, not 'String' func saveAuthToken() { if let cookies =…
mosaic6
  • 923
  • 3
  • 11
  • 18
-1
votes
1 answer

Swift dictionary with assigned nil value can be conditionally bind in if let statement

Can you explain this Swift code If I assign nil value for "a" key and then use if let statement this nil value will be unwrapped as nil and can be printed import Foundation var dictionary = ["a": nil, "b": "Costam", "c":…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
-2
votes
1 answer

Optional Binding (String: AnyObject) to [String]

I have a JSON object/dictionary I retrieved from AFNetworking and I want to conditionally unwrap the key into an array of strings. var person: [String : AnyObject] = ... if let interests = person["interests"] as [String]{ // Do something } I…
blee908
  • 12,165
  • 10
  • 34
  • 41