#swifttip search results

๐Ÿ’ก #SwiftTip: Multiple SwiftUI Preview Providers Did you know that you can have any number of #SwiftUI preview providers in a single file? Xcode will group them, pretty print their names, and add a separator.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Multiple SwiftUI Preview Providers

Did you know that you can have any number of #SwiftUI preview providers in a single file? 

Xcode will group them, pretty print their names, and add a separator.

Use this code tip if you want trigger some functionality if you get back in your VC AND not the first time you present it ๐Ÿ˜Ž๐Ÿ’ป #swifttip #iosdev

swift_al_dente's tweet image. Use this code tip if you want trigger some functionality if you get back in your VC AND not the first time you present it ๐Ÿ˜Ž๐Ÿ’ป #swifttip #iosdev

๐Ÿ’ก #SwiftTip: KeyPath-Based Builder ๐Ÿ‘ทโ€โ™‚๏ธ Here is a cool trick with #Swift KeyPaths โ€” you can implement a universal Builder pattern once and reuse it everywhere. Great to make your APIs more expressive and readable.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: KeyPath-Based Builder ๐Ÿ‘ทโ€โ™‚๏ธ

Here is a cool trick with #Swift KeyPaths โ€” you can implement a universal Builder pattern once and reuse it everywhere.

Great to make your APIs more expressive and readable.

#SwiftTip You can gracefully avoid nested do/catch with a simple extension on the Result type. Really useful if you want to try different things before eventually fallback on a default value. gist.github.com/jegnux/500b097โ€ฆ


๐Ÿ’ก #SwiftTip: Calling `willSet` and `didSet` from initializer By default, `willSet` and `didSet` observers are not called when a property is first initialized. We can overcome this by using the `defer` statement inside the `init` method ๐Ÿ‘‡

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Calling `willSet` and `didSet` from initializer

By default, `willSet` and `didSet` observers are not called when a property is first initialized. We can overcome this by using the `defer` statement inside the `init` method ๐Ÿ‘‡

๐ŸŽฏ Swift tip #7: Comparing boolean conditions with switch instead of if-elseif-elseif-else. Additionally compiler makes sure that all the possible cases are handled. #swifttip #xcode #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Swift tip #7: Comparing boolean conditions with switch instead of if-elseif-elseif-else. Additionally compiler makes sure that all the possible cases are handled.
#swifttip  #xcode #iosdev

๐Ÿ’ก #SwiftTip: Avoiding Degenerate Optional Values Avoid designing your code with `Optional` collections and booleans. Otherwise, you will run into a degenerate case, where it is unclear what does "nothing" mean. Is it an empty array or `nil` array; is it `false` or `nil`?

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Avoiding Degenerate Optional Values

Avoid designing your code with `Optional` collections and booleans. Otherwise, you will run into a degenerate case, where it is unclear what does "nothing" mean. Is it an empty array or `nil` array; is it `false` or `nil`?

#SwiftTip I know that there is a bunch of uses for SwiftUI previews, but I just found out that it can be used for convenient DateFormatter and NumberFormatter configuration


๐Ÿ’ก#SwiftTip: Result<T, Never> Set Result.Failure type to Never in case error is impossible or can be replaced with a value. E.g., pass an empty array if an array of elements has failed to load. The compiler is smart and does not require us to handle the failure case in switch.

V8tr's tweet image. ๐Ÿ’ก#SwiftTip:  Result&amp;lt;T, Never&amp;gt;

Set Result.Failure type to Never in case error is impossible or can be replaced with a value. E.g., pass an empty array if an array of elements has failed to load.

The compiler is smart and does not require us to handle the failure case in switch.

๐Ÿ’ก #SwiftTip: 'Y' vs 'y' formatter ๐Ÿ“… โ€ข 'y' specifies the calendar year. โ€ข 'Y' specifies the ISO8601 year-week calendar. โ€ข Always use 'y' when presenting dates to users. ๐Ÿ‘ ISO8601 counts full weeks. In 2021 Jan 1st falls on Friday, thus the mismatch is Dec 29 - 31.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: &apos;Y&apos; vs &apos;y&apos; formatter ๐Ÿ“…

โ€ข &apos;y&apos; specifies the calendar year.
โ€ข &apos;Y&apos; specifies the ISO8601 year-week calendar.
โ€ข Always use &apos;y&apos; when presenting dates to users. ๐Ÿ‘

ISO8601 counts full weeks. In 2021 Jan 1st falls on Friday, thus the mismatch is Dec 29 - 31.

๐Ÿ’ก #SwiftTip: Configuring UIAlertControllers Here is a neat way of configuring alert controllers โ€” you can declare a factory method for each style. It cuts boilerplate code, organizes your alerts in one place and makes them more readable.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Configuring UIAlertControllers

Here is a neat way of configuring alert controllers โ€” you can declare a factory method for each style.

It cuts boilerplate code, organizes your alerts in one place and makes them more readable.

๐Ÿ’ก #SwiftTip Debug Log Optionals without Warnings Remember this problem when you debug log or display an optional value on UI, it prints 'Optional(...)' and gives a warning? The solution is to provide a custom string interpolation for Optional<T>. See the attached screenshot.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip Debug Log Optionals without Warnings

Remember this problem when you debug log or display an optional value on UI, it prints &apos;Optional(...)&apos; and gives a warning?

The solution is to provide a custom string interpolation for Optional&amp;lt;T&amp;gt;. See the attached screenshot.

#SwiftTip Una de las curiosidades de usar operadores Bit a Bit que se puede usar para setear una variable a 0 de la forma mรกs eficiente por la CPU "Bueno eso en ASM si lo es, XD)

Codelaby's tweet image. #SwiftTip

Una de las curiosidades de usar operadores Bit a Bit que se puede usar para setear una variable a 0 de la forma mรกs eficiente por la CPU &quot;Bueno eso en ASM si lo es, XD)

๐ŸŽฏ #unavailable landed with Swift 5.6 and Xcode 13.3 #swifttip #xcode #iosdev

toomasvahter's tweet image. ๐ŸŽฏ #unavailable landed with Swift 5.6 and Xcode 13.3
#swifttip  #xcode #iosdev

๐ŸŽฏ Swift tip #8: Dictionary has a subscript with default value. Useful if accessing the dictionary should return a fallback value when the dictionary key is not present. #swifttip #xcode #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Swift tip #8: Dictionary has a subscript with default value. Useful if accessing the dictionary should return a fallback value when the dictionary key is not present.
#swifttip  #xcode #iosdev

๐Ÿ’ก #SwiftTip: KeyPath Builder ๐Ÿ‘ทโ€โ™‚๏ธ Here is a cool trick with Swift KeyPaths โ€” you can implement a universal Builder pattern once and reuse it everywhere. Great to make your APIs more expressive and readable.

swiftamman's tweet image. ๐Ÿ’ก #SwiftTip: KeyPath Builder ๐Ÿ‘ทโ€โ™‚๏ธ

Here is a cool trick with Swift KeyPaths โ€” you can implement a universal Builder pattern once and reuse it everywhere.
 
Great to make your APIs more expressive and readable.

๐ŸŽฏ Optional pattern matching in for loop only loops over non-nil values #swiftlang #swifttip #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Optional pattern matching in for loop only loops over non-nil values
#swiftlang #swifttip #iosdev

Sad that you're still stuck on Mohave and you can't use the fancy new Previews ๐Ÿ˜”? You can run your SwiftUI Views in an Xcode 11 playground by wrapping it in a UIHostingController. ๐Ÿš€ #swifttip #swiftuitip

razvanlitianu's tweet image. Sad that you&apos;re still stuck on Mohave and you can&apos;t use the fancy new Previews ๐Ÿ˜”? You can run your SwiftUI Views in an Xcode 11 playground by wrapping it in a UIHostingController.  ๐Ÿš€

#swifttip #swiftuitip

โฑ๏ธSwift 5.7 in Xcode 14 has a new ContinuousClock API which also provides a nice way to measure time of async functions. #swiftlang #swifttip #iosdev

toomasvahter's tweet image. โฑ๏ธSwift 5.7 in Xcode 14 has a new ContinuousClock API which also provides a nice way to measure time of async functions.
#swiftlang #swifttip #iosdev

#SwiftTip: Use the reduce() method to combine all elements of an array into a single value. ```swift let numbers = [1, 2, 3, 4, 5] let sum = numbers.reduce(0, +) // 15 ``` #Swift


#Swift Tip ๐Ÿ’ก #SwiftTip ๐Ÿ’ก Initialize an array with a specified size using the `init(repeating:count:)` initializer. Example: ```swift let array = Array(repeating: "Swift", count: 3) // ["Swift", "Swift", "Swift"] ```


#Swift tip: Use the `reduce` method to iterate over an array and apply a transformation to each element. Here's an example: let numbers = [1, 2, 3, 4, 5] let sum = numbers.reduce(0, +) // Result: 15 #SwiftTip #ArrayManipulation #FunctionalProgramming


**Swift** #swiftTip: Use `reduce` to iterate over a collection and accumulate a single value. ```swift let numbers = [1, 2, 3, 4, 5] let sum = numbers.reduce(0, +) print(sum) // 15 ``` #Swift #programming #dev


Swift tip โšก๏ธ: For a quick debug print, use `print(thing, terminator: "")` to print to the same line instead of a new line. You can follow it up with `print()` to return to a new line. #swift #swiftlang #swifttip


#SwiftTip: Use the ?? operator to unwrap an optional value safely. If the value is nil, the default value will be used. Example: ```swift let name: String? = nil let displayName = name ?? "Unknown" // displayName will be "Unknown" ```


Foundation's partition(by:) is useful if we want to divide a collection into two parts and operate on both sub-collections. Example could be partitioning index paths and calling UITableView reloadRows for one part and reconfigureRows for the other part. #swifttip #iosdev

toomasvahter's tweet image. Foundation&apos;s partition(by:) is useful if we want to divide a collection into two parts and operate on both sub-collections. Example could be partitioning index paths and calling UITableView reloadRows for one part and reconfigureRows for the other part.
#swifttip #iosdev

When dealing with shared instances, sometimes it makes sense to introduce static subscript for skipping typing .shared everywhere. #swifttip #iosdev

toomasvahter's tweet image. When dealing with shared instances, sometimes it makes sense to introduce static subscript for skipping typing .shared everywhere.
#swifttip #iosdev

Using enums over structs for namespacing static constants. Nicer since we can't create an instance of AppConstants nor AppConstants.URLs. More Swift tips: bit.ly/swifttips #swiftlang #swifttip

toomasvahter's tweet image. Using enums over structs for namespacing static constants. Nicer since we can&apos;t create an instance of AppConstants nor AppConstants.URLs.
More Swift tips: bit.ly/swifttips
#swiftlang #swifttip

Destructuring a tuple is a short way to extract values from tuples in Swift #swifttip #swiftlang #iosdev

toomasvahter's tweet image. Destructuring a tuple is a short way to extract values from tuples in Swift
#swifttip #swiftlang #iosdev

In addition to functions and properties, we can add init methods to protocols in Swift. In that case the comforming non-final class needs use the โ€œrequiredโ€ modifier. This ensures that the init is explicitly implemented by the class or its subclasses. #swifttip #swiftlang #iosdev

toomasvahter's tweet image. In addition to functions and properties, we can add init methods to protocols in Swift. In that case the comforming non-final class needs use the โ€œrequiredโ€ modifier. This ensures that the init is explicitly implemented by the class or its subclasses.
#swifttip #swiftlang #iosdev

Keep your code efficient and clean with #SwiftTip๐Ÿš€ #iOSDev


Reduce boilerplate and harness the power of protocol-oriented programming in #Swift! protocol Identifiable { var id: Int { get set } } Now each of your models can conform and be 'identifiable'! #SwiftTip ๐Ÿค“


Swift 5.9 added sleep(for:) to the Clock protocol rather than having to define an instant. github.com/apple/swift-evโ€ฆ #swifttip #swiftlang #iosdev

toomasvahter's tweet image. Swift 5.9 added sleep(for:) to the Clock protocol rather than having to define an instant.
github.com/apple/swift-evโ€ฆ
#swifttip #swiftlang #iosdev

Combat #carpetstains like a pro with this #swifttip! ๐Ÿงผ When spills happen, act fast. Gently blot the area using a clean cloth or paper towel. Begin from the outer edges and work your way toward the center to avoid #spreading the stain. Quick action, lasting cleanliness! โœจ๐Ÿ›‹๏ธ

CareTnt's tweet image. Combat #carpetstains like a pro with this #swifttip! ๐Ÿงผ When spills happen, act fast. Gently blot the area using a clean cloth or paper towel. Begin from the outer edges and work your way toward the center to avoid #spreading the stain. Quick action, lasting cleanliness! โœจ๐Ÿ›‹๏ธ

If a function in Swift has multiple defer statements then these run in a reverse order. Something to keep in mind if the order is happens to be important. #swifttip #swiftlang #iosdev

toomasvahter's tweet image. If a function in Swift has multiple defer statements then these run in a reverse order. Something to keep in mind if the order is happens to be important.
#swifttip #swiftlang #iosdev

In Swift 5.8 we can opt-in to a new #file behavior where it equals to the module_name/file_name instead of the full path. Useful when implementing custom logging functions. #swifttip #iosdev #swiftlang

toomasvahter's tweet image. In Swift 5.8 we can opt-in to a new #file behavior where it equals to the module_name/file_name instead of the full path. Useful when implementing custom logging functions.
#swifttip #iosdev #swiftlang

Swift 5.8 in Xcode 14.3 implements @backDeployed attribute for adding functionality to older API versions! ๐Ÿ‘ #swifttip #iosdev gist.github.com/laevandus/af00โ€ฆ

toomasvahter's tweet image. Swift 5.8 in Xcode 14.3 implements @backDeployed attribute for adding functionality to older API versions! ๐Ÿ‘
#swifttip #iosdev
gist.github.com/laevandus/af00โ€ฆ

When using switch for enums with associated values and we do not want to use associated values then we can only write out the case name .error (instead of `.error(_)`) gist.github.com/laevandus/dd1dโ€ฆ #swifttip #iosdev

toomasvahter's tweet image. When using switch for enums with associated values and we do not want to use associated values then we can only write out the case name .error (instead of `.error(_)`)
gist.github.com/laevandus/dd1dโ€ฆ
#swifttip #iosdev

Adding custom init in an extension keeps the auto-generated init for structs in Swift gist.github.com/laevandus/d541โ€ฆ #swifttip #iosdev

toomasvahter's tweet image. Adding custom init in an extension keeps the auto-generated init for structs in Swift
gist.github.com/laevandus/d541โ€ฆ
#swifttip #iosdev

๐Ÿ’ก #SwiftTip: Multiple SwiftUI Preview Providers Did you know that you can have any number of #SwiftUI preview providers in a single file? Xcode will group them, pretty print their names, and add a separator.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Multiple SwiftUI Preview Providers

Did you know that you can have any number of #SwiftUI preview providers in a single file? 

Xcode will group them, pretty print their names, and add a separator.

๐Ÿ’ก #SwiftTip: KeyPath-Based Builder ๐Ÿ‘ทโ€โ™‚๏ธ Here is a cool trick with #Swift KeyPaths โ€” you can implement a universal Builder pattern once and reuse it everywhere. Great to make your APIs more expressive and readable.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: KeyPath-Based Builder ๐Ÿ‘ทโ€โ™‚๏ธ

Here is a cool trick with #Swift KeyPaths โ€” you can implement a universal Builder pattern once and reuse it everywhere.

Great to make your APIs more expressive and readable.

๐ŸŽฏ Swift tip #4: Use dump() for printing out all the properties of a type. Especially useful when the type has a custom description which reveals only some information. #swifttip #swiftlang #xcode #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Swift tip #4: Use dump() for printing out all the properties of a type. Especially useful when the type has a custom description which reveals only some information.
#swifttip #swiftlang  #xcode #iosdev

Use this code tip if you want trigger some functionality if you get back in your VC AND not the first time you present it ๐Ÿ˜Ž๐Ÿ’ป #swifttip #iosdev

swift_al_dente's tweet image. Use this code tip if you want trigger some functionality if you get back in your VC AND not the first time you present it ๐Ÿ˜Ž๐Ÿ’ป #swifttip #iosdev

๐ŸŽฏ Swift tip #7: Comparing boolean conditions with switch instead of if-elseif-elseif-else. Additionally compiler makes sure that all the possible cases are handled. #swifttip #xcode #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Swift tip #7: Comparing boolean conditions with switch instead of if-elseif-elseif-else. Additionally compiler makes sure that all the possible cases are handled.
#swifttip  #xcode #iosdev

๐ŸŽฏ #unavailable landed with Swift 5.6 and Xcode 13.3 #swifttip #xcode #iosdev

toomasvahter's tweet image. ๐ŸŽฏ #unavailable landed with Swift 5.6 and Xcode 13.3
#swifttip  #xcode #iosdev

๐ŸŽฏ Swift/iOS/macOS tip #5: HTTPURLResponse has a function for returning localised strings for HTTP status codes. #swifttip #xcode #iosdev #macosengineer

toomasvahter's tweet image. ๐ŸŽฏ Swift/iOS/macOS tip #5: HTTPURLResponse has a function for returning localised strings for HTTP status codes. 
#swifttip  #xcode #iosdev #macosengineer

๐Ÿ’ก #SwiftTip: Calling `willSet` and `didSet` from initializer By default, `willSet` and `didSet` observers are not called when a property is first initialized. We can overcome this by using the `defer` statement inside the `init` method ๐Ÿ‘‡

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Calling `willSet` and `didSet` from initializer

By default, `willSet` and `didSet` observers are not called when a property is first initialized. We can overcome this by using the `defer` statement inside the `init` method ๐Ÿ‘‡

๐ŸŽฏ Swift tip #1: Avoid optional when converting data to utf8 string with init(decoding:as:) #swiftlang #swifttip #iosengineer #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Swift tip #1: Avoid optional when converting data to utf8 string with init(decoding:as:)
#swiftlang #swifttip #iosengineer #iosdev

๐Ÿ’ก#SwiftTip: Result<T, Never> Set Result.Failure type to Never in case error is impossible or can be replaced with a value. E.g., pass an empty array if an array of elements has failed to load. The compiler is smart and does not require us to handle the failure case in switch.

V8tr's tweet image. ๐Ÿ’ก#SwiftTip:  Result&amp;lt;T, Never&amp;gt;

Set Result.Failure type to Never in case error is impossible or can be replaced with a value. E.g., pass an empty array if an array of elements has failed to load.

The compiler is smart and does not require us to handle the failure case in switch.

๐Ÿ’ก #SwiftTip: Configuring UIAlertControllers Here is a neat way of configuring alert controllers โ€” you can declare a factory method for each style. It cuts boilerplate code, organizes your alerts in one place and makes them more readable.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Configuring UIAlertControllers

Here is a neat way of configuring alert controllers โ€” you can declare a factory method for each style.

It cuts boilerplate code, organizes your alerts in one place and makes them more readable.

๐Ÿ’ก #SwiftTip: 'Y' vs 'y' formatter ๐Ÿ“… โ€ข 'y' specifies the calendar year. โ€ข 'Y' specifies the ISO8601 year-week calendar. โ€ข Always use 'y' when presenting dates to users. ๐Ÿ‘ ISO8601 counts full weeks. In 2021 Jan 1st falls on Friday, thus the mismatch is Dec 29 - 31.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: &apos;Y&apos; vs &apos;y&apos; formatter ๐Ÿ“…

โ€ข &apos;y&apos; specifies the calendar year.
โ€ข &apos;Y&apos; specifies the ISO8601 year-week calendar.
โ€ข Always use &apos;y&apos; when presenting dates to users. ๐Ÿ‘

ISO8601 counts full weeks. In 2021 Jan 1st falls on Friday, thus the mismatch is Dec 29 - 31.

๐Ÿ’ก #SwiftTip: Avoiding Degenerate Optional Values Avoid designing your code with `Optional` collections and booleans. Otherwise, you will run into a degenerate case, where it is unclear what does "nothing" mean. Is it an empty array or `nil` array; is it `false` or `nil`?

V8tr's tweet image. ๐Ÿ’ก #SwiftTip: Avoiding Degenerate Optional Values

Avoid designing your code with `Optional` collections and booleans. Otherwise, you will run into a degenerate case, where it is unclear what does &quot;nothing&quot; mean. Is it an empty array or `nil` array; is it `false` or `nil`?

๐Ÿ”จ Xcode tip #23: Sort files and folders by name by right clicking on a folder and selecting "Sort By Name" #xcodetip #swifttip #iosdev

toomasvahter's tweet image. ๐Ÿ”จ Xcode tip #23: Sort files and folders by name by right clicking on a folder and selecting &quot;Sort By Name&quot;
#xcodetip #swifttip #iosdev

๐Ÿ’ก #SwiftTip Debug Log Optionals without Warnings Remember this problem when you debug log or display an optional value on UI, it prints 'Optional(...)' and gives a warning? The solution is to provide a custom string interpolation for Optional<T>. See the attached screenshot.

V8tr's tweet image. ๐Ÿ’ก #SwiftTip Debug Log Optionals without Warnings

Remember this problem when you debug log or display an optional value on UI, it prints &apos;Optional(...)&apos; and gives a warning?

The solution is to provide a custom string interpolation for Optional&amp;lt;T&amp;gt;. See the attached screenshot.

๐Ÿ“ฃ Swift Tip ๐Ÿ“ฃ Controla el acceso a tu cรณdigo. Usa siempre el modificador de acceso apropiado para encapsular tu cรณdigo. En Swift tienes 3 modificadores: private, internal y public. #SwiftTip #iOS #MiraMiCodigo

MiraMiCodigo's tweet image. ๐Ÿ“ฃ Swift Tip  ๐Ÿ“ฃ

Controla el acceso a tu cรณdigo.

Usa siempre el modificador de acceso apropiado para encapsular tu cรณdigo. En Swift tienes 3 modificadores:

private, internal y public.

#SwiftTip #iOS #MiraMiCodigo

๐ŸŽฏ Swift tip #8: Dictionary has a subscript with default value. Useful if accessing the dictionary should return a fallback value when the dictionary key is not present. #swifttip #xcode #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Swift tip #8: Dictionary has a subscript with default value. Useful if accessing the dictionary should return a fallback value when the dictionary key is not present.
#swifttip  #xcode #iosdev

โฑ๏ธSwift 5.7 in Xcode 14 has a new ContinuousClock API which also provides a nice way to measure time of async functions. #swiftlang #swifttip #iosdev

toomasvahter's tweet image. โฑ๏ธSwift 5.7 in Xcode 14 has a new ContinuousClock API which also provides a nice way to measure time of async functions.
#swiftlang #swifttip #iosdev

๐ŸŽฏ Optional pattern matching in for loop only loops over non-nil values #swiftlang #swifttip #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Optional pattern matching in for loop only loops over non-nil values
#swiftlang #swifttip #iosdev

๐ŸŽฏ Swift tip #2: Converting an integer to data and back. Useful when working with raw bytes. #swiftlang #swifttip #xcode #iosengineer #macosengineer #iosdev

toomasvahter's tweet image. ๐ŸŽฏ Swift tip #2: Converting an integer to data and back. Useful when working with raw bytes.
#swiftlang #swifttip #xcode #iosengineer #macosengineer #iosdev

Loading...

Something went wrong.


Something went wrong.


United States Trends