Last active
January 26, 2023 07:57
-
-
Save lucascaton/f5490fb8d69ca63c352d to your computer and use it in GitHub Desktop.
Swift and Ruby comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"] | |
sorted_cities = cities.sort | |
if sorted_cities.include?("London") | |
puts "London is city number #{sorted_cities.index('London')} in the list" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"] | |
let sortedCities = sort(cities) { $0 < $1 } | |
if let indexOfLondon = find(sortedCities, "London") { | |
println("London is city number \(indexOfLondon + 1) in the list") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def configure_labels(labels: []) | |
label_text_color = UIColor.green_color | |
labels.each do |label| | |
# label inferred to be UILabel | |
label.text_color = label_text_color | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func configureLabels(labels: UILabel[]) { | |
let labelTextColor = UIColor.greenColor() | |
for label in labels { | |
// label inferred to be UILabel | |
label.textColor = labelTextColor | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html