optional

AngularJS: Routing with URL having optional parameters

允我心安 提交于 2019-12-10 16:09:30
问题 I have a URL in my app.js containing routes. lets say the url is: /api/:opt1/:opt2/:opt3/users I want that my url will work in any case, i should able to ignore the optional parameters (opt1, opt2 or opt3, may be all or few). How can I achieve this. Is there any way that I can call $location.path('/users') , and I can specify also what are the values of the optional parameters? 回答1: Optional route parameters are marked with ? , like this: `/users/:id?` Then this route matches both /users and

Optional chaining used in left side of assignment in Swift

∥☆過路亽.° 提交于 2019-12-10 15:15:03
问题 What does it mean when optional chaining is used in the left side of the assignment statement? Will the app crash if the optional variable is nil? e.g. // cell is a UITableViewCell cell.textLabel?.text = "Test" 回答1: Sort of like a short-circuiting && operator that stops when it reaches the first false value, optional chaining will stop when it hits the first nil value. So in an extreme case like container?.cell?.textLabel?.text = "foo" , any of container, cell, or textLabel could be nil. If

dynamically determine type of Option when it has value 'None'

筅森魡賤 提交于 2019-12-10 15:09:07
问题 There is some difficulty in getting Option type dynamically. Suppose I have a function: let printType x = if (box x) = null then printfn "the type is 'null'" else printfn "the type is %A" (x.GetType()) And we have the output here: printType 3 // the type is System.Int32 printType (Some(3)) // the type is Microsoft.FSharp.Core.FSharpOption`1[System.Int32] printType None // the type is null printType null // the type is null How to differentiate between None and null when getting an expression

if-let statement doesn't unwrap optional

两盒软妹~` 提交于 2019-12-10 13:33:44
问题 I've run across something in my code that seems curious and was wondering if there is a straightforward explanation for this behavior. Given the following statement: if let tabBarController = topViewController as? UITabBarController { for subcontroller in tabBarController.viewControllers! { println(subcontroller.view) if let subcontrollerView = subcontroller.view { println(subcontrollerView) println(subcontrollerView!) if subcontrollerView!.window != nil && subcontroller.isViewLoaded() {

How to retrieve value from optional parser in Parsec?

[亡魂溺海] 提交于 2019-12-10 13:14:23
问题 Sorry if it's a novice question - I want to parse something defined by Exp ::= Mandatory_Part Optional_Part0 Optional_Part1 I thought I could do this: proc::Parser String proc = do { ;str<-parserMandatoryPart ;str0<-optional(parserOptionalPart0) --(1) ;str1<-optional(parserOptionalPart1) --(2) ;return str++str0++str1 } I want to get str0/str1 if optional parts are present, otherwise, str0/str1 would be "". But (1) and (2) won't work since optional() doesn't allow extracting result from its

In Swift should I set my optional instance variables to nil when done?

强颜欢笑 提交于 2019-12-10 12:55:04
问题 I'm using lots of audio, video, and images in one of my apps and seem to be having minor memory issues and was wondering what the best way to free up memory is. I use lots of optional variables like this: var myImageView: UIImageView? I was wondering if it is considered best practice to set these to nil as soon as you know you won't need it anymore to free up memory like this: myImageView = nil It seems like setting it to nil would remove the last strong reference and cause it to be released,

how to use optional and filter along to retrieve an object from chained/cascaded objects generated by wsdl2java

心不动则不痛 提交于 2019-12-10 12:07:17
问题 I understand flatMap is recommended when dealing with hierarchical objects in Java, particularly while extracting values from objects created out of XML files. Whithout relying on Optional and since getCommercieleNaam() will bring me a list, I coded: NaamOndernemingLijstCommercieelType naamOndernemingLijstCommercieel = onderneming.getNamen() .getCommercieleNamen(); NaamOndernemingType naamOndernemingType = naamOndernemingLijstCommercieel.getCommercieleNaam().stream() .filter(x -> x

How can I fix “Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value” in Swift [duplicate]

ぐ巨炮叔叔 提交于 2019-12-10 12:00:44
问题 This question already has answers here : What does “Fatal error: Unexpectedly found nil while unwrapping an Optional value” mean? (11 answers) Closed last year . I am trying to add music to a game I created. But I am getting the error: "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value. I found another post on Stack Overflow (What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?), but I do not understand how this applies to my

Is it good idea to use Optional.of() method to make method chaining?

随声附和 提交于 2019-12-10 10:54:57
问题 Is it good idea to use Optional.of() method to make method chaining ? i had a conversation with group of collegues about Optional.of() method. currently one of the project they are using Optional.of() method to achieve the method chaining functional programming style . Here i am giving the sample example : TxResponse initTxDataResponse = gateway.initiateTx(initTxDataRequest); Optional.of(initTxDataResponse) .map(initTxDataResponse::getReturnCode) .filter(code -> ResponseCode.SUCCESS.getCode()

fatal error: unexpectedly found nil while unwrapping an Optional value - Stanford Calculator

二次信任 提交于 2019-12-10 10:13:58
问题 I'm watching the Stanford Swift lecturers on ItunesU and have some trouble in understanding. The lecturer is typecasting a String to a Double at one point. He did it as follows: return NSNumberFormatter().numberFromString(display.text!)!.doubleValue display.text is a UILabel Anyhow, when I'm doing it like this my app crashes and I get the following error: fatal error: unexpectedly found nil while unwrapping an Optional value When I typecast the String like this: (display.text! as NSString)