Johny D Good
Johny D Good

Reputation: 427

substring(from:)' is deprecated. Use string slicing subscript with a 'partial range from' operator

I have just coverted an app from swift3 to swift4.2 on Xcode 10.1

I am in the process of fixing some of the many errors that have appeared. Apparently substring(from:)' is deprecated. Use string slicing subscript with a 'partial range from' operator

t_prefix_phone = contact_phone.substring(to:contact_phone.index(contact_phone.startIndex, offsetBy: 3))

t_phone = contact_phone.substring(from:contact_phone.index(contact_phone.endIndex, offsetBy: -7))

Could you please help me translate the code above to 4.2 in such a way that the results are still strings.

Thanks

Upvotes: 2

Views: 2370

Answers (1)

Johny D Good
Johny D Good

Reputation: 427

swift 4 has prefix and suffix just for this:

    let contact_phone = "0123456789"
    let t_prefix_phone = String(contact_phone.prefix(3))
    let t_phone = String(contact_phone.suffix(7))

Upvotes: 7

Related Questions