2

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

1

1 Answer 1

7

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.