Skip to main content
added 6 characters in body
Source Link
phnmnn
  • 13.3k
  • 11
  • 50
  • 69

SWIFT 2.0

simple:

let myString = "full text container" let substring = myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

SWIFT 3.0

let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 4.0

Substring operations return an instance of the Substring type, instead of String.

// Convert the result to a String for long-term storage. let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful // Convert the result to a String for long-term storage. let newString = String(substring) 

SWIFT 2.0

simple:

let myString = "full text container" let substring = myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

SWIFT 3.0

let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 4.0

Substring operations return an instance of the Substring type, instead of String.

// Convert the result to a String for long-term storage. let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful let newString = String(substring) 

SWIFT 2.0

simple:

let myString = "full text container" let substring = myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

SWIFT 3.0

let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 4.0

Substring operations return an instance of the Substring type, instead of String.

let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful // Convert the result to a String for long-term storage. let newString = String(substring) 
added 239 characters in body
Source Link
phnmnn
  • 13.3k
  • 11
  • 50
  • 69

SWIFT 2.0

simple:

let myString = "full text container" let substring = myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

SWIFT 3.0

let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 4.0

Substring operations return an instance of the Substring type, instead of String.

// Convert the result to a String for long-term storage. let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful let newString = String(substring) 

SWIFT 2.0

simple:

let myString = "full text container" myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

SWIFT 3.0

myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 2.0

simple:

let myString = "full text container" let substring = myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

SWIFT 3.0

let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 4.0

Substring operations return an instance of the Substring type, instead of String.

// Convert the result to a String for long-term storage. let substring = myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful let newString = String(substring) 
deleted 49 characters in body
Source Link
phnmnn
  • 13.3k
  • 11
  • 50
  • 69

SWIFT 2.0/3.0 in Xcode 8 beta 5

simple:

let myString = "full text container" myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

swiftSWIFT 3.0 in Xcode 8 beta 6 or later

myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 2.0/3.0 in Xcode 8 beta 5

simple:

let myString = "full text container" myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

swift 3.0 in Xcode 8 beta 6 or later

myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 

SWIFT 2.0

simple:

let myString = "full text container" myString[myString.startIndex..<myString.startIndex.advancedBy(3)] // prints: ful 

SWIFT 3.0

myString[myString.startIndex..<myString.index(myString.startIndex, offsetBy: 3)] // prints: ful 
added 18 characters in body
Source Link
phnmnn
  • 13.3k
  • 11
  • 50
  • 69
Loading
added 6 characters in body
Source Link
phnmnn
  • 13.3k
  • 11
  • 50
  • 69
Loading
Source Link
phnmnn
  • 13.3k
  • 11
  • 50
  • 69
Loading