optional

Force parsing optional groups

别来无恙 提交于 2019-12-23 16:54:53
问题 I'm trying to make a regex string that extracts data from report files. The tricky part is that I need this single regex string to match multiple report file content formats. I want the regex to always match even if some optional groups are not found. Take the following report files content ( Note : #2 is missing the "val2" part.): File #1: " -val1-test-val2-result-val3-done- " Expected Result: Val1 Group: test Val2 Group: result Val3 Group: done File #2: " -val1-test-val3-done- " Expected

What is the purpose of the init! failable initializer?

会有一股神秘感。 提交于 2019-12-23 15:00:48
问题 The Apple Swift Programming Language guide mentions the existence of the init! initializer, but does not provide any example for it. (Search for init! in this page) I understand the use of a normal failable initializer declared with init?, but I fail to get the need of this other version. What is it needed for? Can somebody provide an example? 回答1: This serves two purposes: When importing Cocoa APIs that Swift doesn't know about. If Swift does not know if an initializer can return nil or not,

optional chaining in Swift 3: why does one example work and not the other?

折月煮酒 提交于 2019-12-23 05:15:13
问题 Here is a detailed account of a problem following my previous post on Swift optionals. Thanks to leads given here, here and here, I am able to read fractions ( for harmonic ratios ) or decimals ( for cents ) from a string array to calculate the frequencies of notes in musical scales. Each element in the string array is first tested to see if it contains a / or a . One of two functions then identifies input errors using optional chaining so both fractional and decimal numbers conform to rules

optional chaining in Swift 3: why does one example work and not the other?

↘锁芯ラ 提交于 2019-12-23 05:15:09
问题 Here is a detailed account of a problem following my previous post on Swift optionals. Thanks to leads given here, here and here, I am able to read fractions ( for harmonic ratios ) or decimals ( for cents ) from a string array to calculate the frequencies of notes in musical scales. Each element in the string array is first tested to see if it contains a / or a . One of two functions then identifies input errors using optional chaining so both fractional and decimal numbers conform to rules

Is 'x?.y' in Swift the same as 'x?' followed by '.y'?

喜你入骨 提交于 2019-12-23 04:52:36
问题 I understand that in Swift, if I define var opt:String? = "Optional" I will get an error if I attempt opt.isEmpty since opt is of type String? which does does not have an isEmpty method. And I thought that I understood that opt?.isEmpty does not produce an error because opt? unwraps (any non- nil ) opt , resulting in a String , which does have an isEmpty method. But opt? on its own results in a String? and not a String . Is ?. a different operator from ? followed by . ? Try (opt?).isEmpty and

is it possible to use twice ifPresent each one checking different return or bifurcate map

梦想与她 提交于 2019-12-23 01:24:25
问题 Context: I have chained objects generated by wsdl2java. There is an already created method that call the soap web services, receives the xml and unmarshalling it in cascaded objects. Desire: I want to get two different objects which lies in different hierarchy nodes. From mapping perspective they are hold "far" from one another but from business perspective they are a "couple". This is currently working: Optional.ofNullable(onderneming.getOndernemingOfVestiging()).map

Handling Optional APIs in J2ME

断了今生、忘了曾经 提交于 2019-12-22 18:33:35
问题 What is the right way of working with optional APIs in Java Mobile? Does one need to make different versions of their app? Or is it enough to check APIs availability at runtime using System.getProperty() ? Let's say I'd like my app to support JSR-256 (the Sensor API). Would importing classes from javax.microedition.sensor and registering variables of these types break my app if the device doesn't support it? I am sure there must be a pretty standard way of handling that situation. Thanks! 回答1

Swift: handling an unexpected nil value, when variable is not optional [duplicate]

岁酱吖の 提交于 2019-12-22 12:22:11
问题 This question already has answers here : Check if property is set in Core Data? (2 answers) Closed 4 years ago . I have a UITableViewController loading its entries from Core Data via a NSFetchedResultsController . Like this: let historyItem = fetchedResults.objectAtIndexPath(indexPath) as HistoryItem historyItem has a title property defined like this: @NSManaged var title: String So in cellForRowAtIndexPath the code says cell?.textLabel?.text = historyItem.title and that should all be fine.

java lambda - how to traverse optional list/stream of optionals

£可爱£侵袭症+ 提交于 2019-12-22 10:34:18
问题 Having an Optional List of Optional's like: Optional<List<Optional<String>>> optionalList = Optional.of( Arrays.asList( Optional.empty(), Optional.of("ONE"), Optional.of("TWO"))); How to traverse optionalList to print out the string's ONE and TWO ? What about having an Optional Stream of Optionals? Optional<Stream<Optional<String>>> optionalStream = Optional.of( Stream.of( Optional.empty(), Optional.of("ONE"), Optional.of("TWO"))); Update: Thanks for answers, solution for optionalStream (non

python regex match optional square brackets

断了今生、忘了曾经 提交于 2019-12-22 08:13:05
问题 I have the following strings: 1 "R J BRUCE & OTHERS V B J & W L A EDWARDS And Ors CA CA19/02 27 February 2003", 2 "H v DIRECTOR OF PROCEEDINGS [2014] NZHC 1031 [16 May 2014]", 3 '''GREGORY LANCASTER AND JOHN HENRY HUNTER V CULLEN INVESTMENTS LIMITED AND ERIC JOHN WATSON CA CA51/03 26 May 2003''' I am trying to find a regular expression which matches all of them. I don't know how to match optional square brackets around the date at the end of the string eg [16 May 2014]. casename = re.compile