swift - Adding optional tuple to the array -


i have function returning optional tuple

(range<string.index>?, range<string.index>?).  

then, need add tuple array of tuples declares as

var arrayoftuples = [(range<string.index>, range<string.index>)]() 

i adding tuple array this

arrayoftuples += [mytuple] 

it gives me note operator += cannot applied operands

 [(range<string.index>, range<string.index>)] 

and

 [(range<string.index>?, range<string.index>?)] 

when make declaration of array optional

var arrayoftuples = [(range<string.index>?, range<string.index>?)]() 

there no more complains. but, @ end, need use startindex , endindex tuples array, , when try

let myrange = arrayoftuples.first!.0.startindex..< arrayoftuples.first!.0.endindex 

i have complain value of type

range<string.index>?  

has no member startindex.

as can understand, if want startindex , endindex tuples, need use array without optionals,

var arrayoftuples = [(range<string.index>, range<string.index>)]() 

but need somehow add optional tuples not (nil, nil). when adding tuple

arrayoftuples += [mytuple!] 

it not accepting this. if use condition

 if mytuple != (nil, nil)  {     arrayoftuples += [mytuple]  } 

it not working. complain operator != cannot applied. how solve problem?

the functions returns optionals reason. need check if optionals not nil first, unwrap them , insert them array. after shouldn't have issues.

you can unwrap them this

if let t1 = touple.0, t2 = touple.1 {     let unwraped = (t1, t2) } 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -