Sqlite.swift: Swift-4 (iOS 11) Initializer for conditional binding must have Optional type, not 'String.UTF8View.Index'

Created on 25 Aug 2017  路  7Comments  路  Source: stephencelis/SQLite.swift

iOS 11 (swift-4) branch

  • error: Initializer for conditional binding must have Optional type, not 'String.UTF8View.Index'
  • file: FTS4.swift
  • extension: Connection
  • method: registerTokenizer
  • lineNo: 156,157
 if let from = range.lowerBound.samePosition(in: view),
               let to = range.upperBound.samePosition(in: view) {
                offset.pointee += Int32(string[string.startIndex..<range.lowerBound].utf8.count)
                length.pointee = Int32(view.distance(from: from, to: to))
                return token
            } else {
                return nil
            }

screen shot 2017-08-25 at 6 04 41 pm

for the time being fix:

let from = range.lowerBound.samePosition(in: view)
            let to = range.upperBound.samePosition(in: view)
            if from != nil && to != nil {
                offset.pointee += Int32(string[string.startIndex..<range.lowerBound].utf8.count)
                length.pointee = Int32(view.distance(from: from, to: to))
                return token
            } else {
                return nil
            }

screen shot 2017-08-25 at 6 10 16 pm

All 7 comments

i suppose this is with beta6?

Using Xcode beta 5 and iOS 11 beta 7

weird. are you sure the xcode beta is active? this got fixed just a few days ago.

Yeah i am sure because i am using swift 4 branch which will not compile on xcode 8.3.3

hm, something is odd w/ your setup, it compiles both on travis and on my local machine (using Xcode 9 beta5). if you check the method signature in the API docs you see that it returns an optional value (samePosition:in).

yeah code works fine on Xcode beta 6 , if possible close the issue

great!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bitflying picture bitflying  路  5Comments

Tchoupinax picture Tchoupinax  路  8Comments

webull-ios picture webull-ios  路  8Comments

fortitude1990 picture fortitude1990  路  4Comments

pgawlowski picture pgawlowski  路  6Comments