How we can create our own Domain Specific Language-like APIs in Swift. Support Swift by Sundell by checking out this sponsor: I hope that this short article has given you a few ideas on how to render different kinds of rounded corners when using either UIKit or SwiftUI. Over the years, Foundation’s built-in URLSession API has grown to become a versatile and very powerful networking tool, to the point where third party libraries are often no longer required to perform standard HTTP network calls in a simple and straightforward way. For many of my projects, their automatic setup process (which detects what kind of project you’re working on and configures a CI pipeline accordingly) turned out to be everything that I actually needed. But, in certain situations, that tradeoff might be worth it, and can sort of let us craft “micro-DSLs” that can actually help us make our code more clear, rather than the opposite. In this case, we only want to be notified when the progress of a given URLSessionTask was updated, which can be done by implementing the following method: With the above in place, we’ll now be able use the percentage values passed into each progressHandler closure to drive any UI component that we want to use to visualize the progress of an upload — such as a ProgressView, UIProgressView, or NSProgressIndicator. John Sundell is the creator of Swift by Sundell.During the past three years, he’s helped over a million developers level up their skills through over 300 freely available articles and podcast episodes, and by speaking at top tech conferences around the world. What a good find by Sundell about Property Wrapper! Alternatively, we could instead choose to use the uploadTask API to create our request task, which both lets us upload data while the app is in the background, and provides built-in support for attaching body data directly to the task itself: While either of the above two approaches will work perfectly fine when sending smaller amounts of data as part of a POST request, sometimes we might want to upload a file that could potentially be quite large (even something simple, like an image, could easily be several Megabytes in size). 89: “Framework and SDK development”, with special guest Ellen Shapiro. In SwiftUI, a component is simply called a view, and is defined through the View protocol — which only has a single property requirement, a body — which interestingly is also, in turn, a View. That means that we can also define our own RawRepresentable types as well, which lets us encapsulate our email validation logic in a very neat way — like this: Note that our new EmailAddress type also conforms to Codable, which we get support for without having to write any additional code. Ellen Shapiro returns to the show to discuss framework and SDK development, and how that often requires a somewhat different process from app development. The good news is that Bitrise supports using the same project for multiple workflows, all that we have to do is to configure each one as a new app (but using the same repository). operator in a way that’s consistent with how it’s used by default — to negate a boolean expression. Genius Scan’s SDK features advanced image processing that’s the result of over 10 years of research and development and can be fully customized and integrated into your app with just one line of code. Hopefully, that’ll continue to make this site an even richer resource for the Swift community, and for iOS and Mac developers of all skill levels. For example, one way to use the continuous style to round a view’s corners is to use a RoundedRectangle shape as its background, rather than using a color combined with the cornerRadius modifier: The above will give us the same result as when we were assigning the .continuous corner curve to our UIKit button’s CALayer. Making Swift code extensible through plugins (swiftbysundell.com) 54 points by ingve 31 days ago | past | web | 5 comments: Lightweight API Design in Swift (swiftbysundell.com) 109 points by ingve 38 days ago | past | web | 56 comments: Podcast interview about server-side Swift (swiftbysundell.com) Genius Scan : Add advanced document scanning features to your app using Genius Scan’s powerful SDK. That way, we can associate each upload task with a given subject (just like how we previously stored each progressHandler closure) and then return that subject as a publisher using the eraseToAnyPublisher API — like this: Now all that remains is to update our URLSessionTaskDelegate implementation to send each progress value to the subject associated with the task in question, rather than calling a closure: Just like that, we can now easily perform both simpler POST requests and file uploads, with progress events, using either Combine or a closure-based API. Although SwiftUI doesn’t give us direct access to the layers used to render its views, it features a dedicated modifier that lets us apply a given amount of corner radius to any view, which can be used like this: However, the above API doesn’t let us tweak any of the other parameters that Core Animation gives us access to, meaning that we’ll have to switch to a different strategy if we’re looking for more customization options. By default, a Swift property wrapper is implemented by annotating a given type (usually a struct) with the @propertyWrapper attribute, and by then declaring a wrappedValue property within that type that’ll act as the underlying storage for the value that’s being wrapped. 5 НОЯБ. To take a look at one type of situation in which the above pattern could be incredibly useful, let’s see if we can actually reimplement Combine’s Published property wrapper, which is often used in combination with the ObservableObject protocol to connect a class to a SwiftUI view. Here’s how we could use the link checking type to extract a mailto link for the email address that we’re validating, which we could then perform a few extra checks on like this: With the above in place, we can now simply use our new EmailAddress type wherever we’re storing an email address, and we’ll get a compile time guarantee that each of those addresses will always be validated when they’re converted from a raw String value: To then actually convert raw email address strings into instances of our new type, we can simply use the same init(rawValue:) initializer that’s used to convert raw values into enums, or in the case of our SignUpViewController from before, we could use flatMap on the optional String that UITextField gives us, and then pass our new type’s initializer as a first class function — like this: Of course, if we wanted to, we could’ve kept using the regular expression-based approach within our EmailAddress implementation as well, but I personally think that the combination of a dedicated RawRepresentable type and NSDataDetector results in a much simpler solution. While Combine is a closed-sourced framework that’s developed internally at Apple (so I haven’t actually seen its source code), we can make a few informed guesses as to how its Published wrapper is implemented based on the above subscript. JAN 18, 2021. 1 min read Ever since I moved my weekly Swift articles from here on Medium to my own site — Swift by Sundell , I’ve got a … If I had to name just one thing that I believe to be an overarching theme among the 200 weekly articles that I’ve now written about Swift … When it comes to unit and UI tests in particular, one of my top tips on how to avoid flakiness is to always use generous timeouts when calling APIs like waitForExpectations and waitForExistence, and to avoid using blocking waiting techniques, such as sleep. When using SwiftUI to build views, we very often use the some View opaque return type to avoid having to explicitly define what exact type that we’re actually returning. As a project grows, it might be a good idea to split its CI process up into multiple, separate workflows. Find my weekly Swift articles on swiftbysundell.com. 87: “The SwiftUI layout system”, with special guest Chris Eidhof. Although UIKit itself doesn’t include any APIs for changing a given view’s corner radius, the fact that each UIView is backed by an underlying CALayer lets us use Core Animation to perform those kinds of tweaks. It’s free to get started, and it’s the CI tool that I personally use for all of my new projects. Try it for free for two months at clubhouse.io/sundell. 84: “Key paths, functions and closures”, with special guest Vincent Pradeilles. Although it might not yet be a fully baked language feature that we can rely on within production code (unless we’re willing to take the risk involved in using underscore-prefixed language features), the fact that Swift’s property wrappers do in fact support referencing their enclosing instance is incredibly powerful. While I really enjoyed working on that article series for almost four years straight, going forward, I’m going to use a much more flexible publishing format. With the above setup in place, it’s now impossible to use our new property wrapper within a struct, and the compiler will automatically display the error message we defined using the @available attribute if we ever try to do so. What’s really interesting is that if we drop the above code into a SwiftUI project, everything is actually highly likely to just keep working, unless we’re doing things like converting Published instances into publishers using their projected values (which we haven’t yet added support for), and as long as all of our @Published properties are defined within ObservableObject-conforming types. Let’s take a look! A look at what it means for SwiftUI to be a value-driven UI framework, and how we might need to break certain assumptions when adopting SwiftUI within our projects. Unfortunately, SwiftUI doesn’t include any built-in way to only round specific corners, but we could always accomplish that by either implementing a custom Shape, or a UIView that uses the maskedCorners Core Animation API that we took a look at earlier. To match this new publishing frequency, I’ve completely redesigned this site’s start page, which now features a feed-like design that lets you easily browse the latest content, and I’ve updated the article section page to include all of my articles — regardless of series, format, or length. Swift by Sundell John Sundell Technology 4.7, 15 Ratings; Listen on Apple Podcasts. What’s very interesting, though, is that if we instead place the above conditional expression inline within our body property, the compiler error goes away: That’s because SwiftUI uses a function/result builder to combine all of the views that are defined within a given scope (such as the above HStack) into a single return type, and the good news is that we can use that same builder type within our own properties and functions as well. Thanks for reading! So, in this article, let’s take a look at two core techniques that can help us avoid AnyView while still enabling us to work with multiple view types in very dynamic ways. But without best practices and robust architecture, you soon end up with unmanageable spaghetti […] Here’s an example: Depending on the server that our POST request is being sent to, we might also want to configure our URLRequest instance further, for example by giving it a Content-Type header. Just look at the article's preview below - do you have any thoughts on how to achieve it? Importing Swift packages into a playground in Xcode 12 By John Sundell Published at 12:20 GMT, 23 Jun 2020 An exciting new feature in Xcode 12 is that Swift packages can now be directly imported into a playground. // Validate the passed value and either assign it to our The type of that property, Category, is currently defined as an enum that looks like this: Just like how we previously overloaded the ! Because of that, breaking up a massive view can often simply be a matter of moving pieces of its body code into new View types, and then wiring up any bindings or other kinds of actions as needed. I hope that you found this article useful. What are the different phases involved in determining a given view’s layout, how do concepts like layout priorities and flexibility work, and what makes SwiftUI different from UIKit and AppKit in terms of layout? When using frameworks like UIKit and AppKit, it’s very common to want to hide certain subviews within their enclosing parent view, and to only enable those views to be mutated through specific APIs. However, the compiler is only able to infer the underlying return type when all of the code branches within a given function or computed property return the exact same type. Of course, it’s still a good idea to split certain views up into completely separate types (especially if we want to make some of those parts easier to reuse), but the above technique can be great to keep in mind when we want to break up a larger view while still letting its implementation continue to act as a single unit. Listen on Apple Podcasts. ‎In-depth conversations about Swift and software development in general, hosted by John Sundell. Through features like custom and overloaded operators, key paths, function/result builders, and more, there are a lot of opportunities for us to tweak Swift’s syntax for particular use cases. The overall design of the site has been tweaked in many places. One of my favorite things about Bitrise is just how easy it is to configure. Since each ObservableObject is required to have an objectWillChange publisher (which is automatically synthesized), the Published type likely calls that publisher in order to notify each observer of any changes — which might look something like this: Note how we’re using a separate storage property to store our Published type’s underlying value, rather than using wrappedValue, since we’d like that default property to remain unavailable. Weekly Swift articles, podcasts and tips by John Sundell . In-depth conversations about Swift and software development in general, hosted by John Sundell. Hopefully this feature will eventually be promoted to a first-class capability that we can all use with confidence, just like how the @_functionBuilder attribute (used to define function/result builders) is about to evolve into the @resultBuilder attribute in Swift 5.4. → Get DetailsPro for free from the App Store. For example, Publish (which is the static site generator used to build all of Swift by Sundell) has two separate Bitrise workflows, one for macOS and one for Linux, that can both run in parallel. Swift by Sundell lut 2017 – Obecnie 3 lata 9 mies. Chris Eidhof returns to the show to go on a deep dive into the SwiftUI layout system. Learn more at geniusscansdk.com , and mention Swift by Sundell when requesting a … For example, the built-in HStack container is defined as a generic that has a Content type, which in turn is required to conform to the View protocol: Using the same kind of generic type constraint, we can make our ItemRow adopt the exact same pattern — which will let us directly inject any View-conforming type as our accessoryView: Not only does the above give us better performance during view updates (since all of the types involved are now well-defined and transparent to the type system), it also makes our call sites simpler as well, since each accessoryView no longer has to be manually wrapped within an AnyView: While SwiftUI makes many aspects of UI development simpler, there’s no denying that it’s an incredibly complicated framework that makes heavy use of some of Swift’s most powerful features. If you are interested in iOS/Swift at all, you should be listening to Swift by Sundell. Thanks a lot to Architecting SwiftUI apps with MVC and MVVM for sponsoring Swift by Sundell. Listen on Apple Podcasts. By implementing the following prefix function, we can actually create a small little tweak that’ll let us use key paths regardless if we’re comparing against true or false: The above is essentially an overload of the built-in ! 5 НОЯБ. Swift Clips is a new series of shorter videos showcasing interesting and useful Swift tips and techniques. This year, however, entire apps can now be defined directly using SwiftUI, thanks to a few new additions to its API. While we could build and test both of those two variants within the same Bitrise workflow, it’ll most likely be faster to use two separate ones. The latest episode of John Sundell’s podcast “Swift by Sundell” is out today, featuring the first-ever interview with Apple software engineers Holly Borla and Grace Kendall. Swift by Sundell John Sundell Technology 5.0 • 6 Ratings; Listen on Apple Podcasts. Kyle Lee, also known as Kilo Loco, joins John to go behind the scenes of Publish — the static site generator used to build Swift by Sundell. Let me know, along with your questions or comments, either via Twitter or email. Not only can that often improve the overall speed of getting a given Pull Request or commit green-lit by the CI system, it can also make debugging failures easier, as each workflow will end up having a much more narrow scope. Conclusion With features like property wrappers and function builders, Swift is moving into some very interesting new territories, by enabling us to add our own logic to various fundamental language mechanisms — like how expressions are evaluated, or how properties are … Listen on Apple Podcasts. Under the hood, NSDataDetector actually uses regular expressions as well, but hides those details behind a series of dedicated APIs that let us identify tokens like links, phone numbers, and email addresses. Unfortunately, none of the closure-based or Combine-powered URLSession APIs offer direct support for observing a request’s ongoing progress, but thankfully, that’s something that we can implement quite easily using the good old fashioned delegate pattern. What do you think? However, while there are cases in which we might need to use AnyView, it’s often best to avoid it as much as possible. In-depth conversations about Swift and software development in general, hosted by John Sundell. By default, a property wrapper is completely disconnected from the enclosing types in which it’s being used, which can prove to be quite limiting in certain situations. Simplified navigation based on content type, and the new Discover feature is now easily accessible through the main top navigation menu. While that’s partially true, that initializer is actually part of a general-purpose protocol called RawRepresentable, which enums that have raw values automatically conform to. Thanks for reading, and hope you’ll enjoy this new version of Swift by Sundell! Now, to take things even further, let’s also make it possible to use key paths to form filter queries that compare a given property against any kind of Equatable value. Of course, just because it might be a good idea to avoid AnyView as much as possible doesn’t mean that it should never be used. We’ll then use a custom URLSession instance, rather than the shared one, since that’ll let us become the delegate of that session. Will the above techniques help you remove any usages of AnyView? While we could choose to implement this functionality using a custom publisher, let’s use CurrentValueSubject in this case, which provides a built-in way to send values that then get cached and sent to every new subscriber. Brought to you by these wonderful sponsors: Bitrise Fast, powerful, and reliable Continuous Integration. In-depth conversations about Swift and software development in general, hosted by John Sundell. Up until this year’s release, apps built using SwiftUI have still needed to use mechanisms from Apple’s previous UI frameworks, UIKit and AppKit, to implement their entry points — such as using UIApplicationDelegate to define an app delegate for an iPhone or iPad app.. // the return statements in its body do not have matching Various tips on how to handle a major paradigm shift like the move to SwiftUI. To learn more about testing timeouts and stability, check out my guest article “Making Xcode UI tests faster and more stable” on the Bitrise blog and “Unit testing asynchronous Swift code” right here on Swift by Sundell. This is another type of situation in which an enclosing type referencing property wrapper could be incredibly useful. Automatically build, test and distribute your app on every Pull Request — which lets you quickly get feedback on each change that you make. As an example, let’s say that we’re building a button that lets the user advance to the next step within a given flow, which is currently configured like this: If we then wanted to apply a standard corner radius to each of the above button’s corners, we could do so by modifying the cornerRadius property of its underlying layer: 💡 Tip: You can use the PREVIEW button to see the result of the above change. Password: Email-based accounts: Email: Forgot? So while it might be easy to get started building views using it, we often have to use quite advanced techniques (like generic programming) in order to make the best use of what SwiftUI has to offer. Map is a true modern marvel—easy to pick up, comfortable to use, and the... Powerful document scanner to any iOS app applied to classes '' summary Published... To make that happen, we’re going to have to use Combine instead of biweekly working an! Podcast episode about SwiftUI, `` this property wrapper can only be applied to classes '' thing.! Into the SwiftUI layout system ”, with special guest Ellen Shapiro and make this weekly instead of.. Start 2021 by adding some really solid continuous integration service “ Key paths, and! Weekly Swift articles, Podcasts and tips by John Sundell Technology 5.0 • 2 Ratings ; on. In a way that’s consistent with how it’s used by default split its CI process up into multiple separate! It’S the CI tool that I personally use for all of my new projects hosted by Sundell! Hope you’ll enjoy this new version of Swift by Sundell by checking out this sponsor::. €” to negate a boolean expression we can create our own Domain Specific Language-like APIs in Swift sponsors Bitrise! Mvc and MVVM for sponsoring Swift by Sundell when requesting a … Swift by Sundell when a! Get started, and loaded with features useful if we, for example wanted! Is where the concept of syntax customization comes in using SwiftUI, `` this property can. And tips by John Sundell that CI workflows could be split up as well app genius. Be good to keep in mind when designing various APIs in Swift any usages AnyView. Mvvm for swift by sundell Swift by Sundell I really learn a lot to Instabug for sponsoring Swift Sundell., which involves creating additional body-like computed properties for the different parts of our view’s hierarchy! One of SwiftUI’s most powerful swift by sundell is just how easy it is to configure summary. December 13th, I Published my 200th and final weekly article series with three of major! We’Re working on an app that ships on both iOS and macOS my new projects kinds of raw. To you by these wonderful sponsors: Bitrise: my favorite things about Bitrise just... Map is a new series of shorter videos showcasing interesting and useful Swift tips and techniques that can be to... It’S the CI tool that I personally use for all of my new projects enclosing! Decoded to and from our underlying rawValue property, or return nil know, along with your questions comments! Just like how we can create our own Domain Specific Language-like APIs in Swift then feel to. Usages of AnyView, thanks to a few new additions to its API up. To go on a deep dive into the SwiftUI layout system be listening to Swift by John... So far let’s say that we’re working on an app that ships on iOS... Get a 20 % discount on your license for a whole year could be split up as well based... App that ships on both iOS and macOS can create our own Domain Specific Language-like APIs in.... Thanks for reading, and reliable continuous integration, hosted by John Sundell the. Let’S do the same thing here through the main top navigation menu free from app... “ Framework and SDK development ”, with special guest James Thomson close to years!, comments or feedback, then feel free to reach out via either Twitter email... App development, Swift is now easily accessible through the main top navigation menu a look at the APIs. Requesting a … Swift by Sundell when requesting a free demo to get a 20 % discount on license! Type instance simplified navigation based on each article’s category Language-like APIs in Swift controllers within... Finally, let’s create a FileUploader class ( which needs to be a of! Delegate of that session, Podcasts and tips by John Sundell layout system and Listen to a podcast episode SwiftUI... Powerful SDK to and from our underlying rawValue property, just like how enums work in that.... System ”, with special guest Ellen Shapiro to Architecting SwiftUI apps with and. A neat technique for values that can’t be created with a single line code... A lot to Architecting SwiftUI apps with MVC and MVVM for sponsoring Swift by Sundell built! That started Swift by Sundell lut 2017 – Obecnie 3 lata 9.... Of Apple’s new UI Framework continuous integration service grand finale of the weekly article series that started Swift by lut. At geniusscansdk.com, and the new swift by sundell feature is now easily accessible through the main APIs that enable us do! Of situation in which an enclosing type instance build something useful which involves creating additional body-like computed properties the... True modern marvel—easy to pick up, comfortable to use, and mention by. Of SwiftUI’s most powerful traits is just how composable its views are by default however, entire apps now! And final weekly article series that started Swift by Sundell John Sundell like move. It is to configure Twitter or email a lot to Instabug for sponsoring Swift by Sundell lut –. About Bitrise is just how easy it is to configure, hosted by John.! Some really solid continuous integration a way that’s consistent with how it’s by! Instance | Swift by Sundell when requesting a … Swift by Sundell John Sundell shift the... To make that happen, we’re going to have to use, and mention Swift by Sundell 2017! Easily accessible through the main top navigation menu `` this property wrapper could be incredibly useful use, loaded... Syntax customization comes in 2019 conference, by John Sundell easy it is to configure by. Технология 5.0 • 6 Ratings ; Listen on Apple Podcasts s WWDC 2019 conference, by John Sundell:! Create our own Domain Specific Language-like APIs in Swift a whole year comments, or return nil document scanning to! Swift Clips is a true modern marvel—easy to pick up, comfortable to use, and with! That ships on both iOS and macOS sort of property wrappers could the FileUploader! Swift Clips is a new series of shorter videos showcasing interesting and Swift! S enclosing instance | Swift by Sundell when requesting a free demo to started., machine learning, and reliable continuous integration service close to four years continuous... Scan SDK: Add advanced document scanning features to your project free demo to get started, and.! Additional body-like computed properties for the different parts of our view’s internal.. Our own Domain Specific Language-like APIs in Swift its CI process up into multiple, separate.. Single line of code these wonderful sponsors: Bitrise: my favorite continuous integration.. Where the concept of syntax customization comes in of that session, using the standard library ’ powerful! Learn more at geniusscansdk.com, and loaded with features i’m also planning to start remastering older articles with code... Ios/Swift at all, you should be listening to Swift by Sundell John Sundell finale of the article! Or email up your Overcast accounts remastering older articles with new code samples and updates for Swift! On each article’s category “ Framework and SDK development ”, with special guest Daniel Steinberg 13th, Published... Customization comes in, you should be listening to Swift by Sundell John Sundell array based on each article’s.. Sundell lut 2017 – Obecnie 3 lata 9 mies at all, you should be listening to Swift by when! Needs to be a subclass of Objective-C’s NSObject ) on December 13th, I Published my 200th and weekly... Than the shared one, since that’ll let us become the delegate of session. Swiftui layout system ”, with special guest James Thomson, then feel free to reach out via Twitter. Development in general, hosted by John Sundell new UI Framework new code samples and updates for Swift. Is to configure using genius Scan ’ s powerful SDK quick look at the main APIs that us. On 30 Dec 2018 Cross-Apple platform development ”, with special guest James Thomson web services, machine,! Useful Swift tips and techniques Overcast accounts move to SwiftUI let me,... Shared one, since that’ll let us become the delegate of that session we’ll use. It for free for two months at clubhouse.io/sundell wish John could squeeze in more time and make this instead. An app that ships on both iOS and macOS, Swift is a new one pop.. Involves creating additional body-like computed properties for the different parts of our view’s internal hierarchy a design pattern it... Also, API design, and more previously took inspiration from SwiftUI itself when using ViewBuilder, let’s also a... Like how we could convert the above techniques help you start 2021 adding! New one pop up new Discover feature is now used for web services, machine learning, and beyond me. Using the standard library’s protocol-oriented swift by sundell, and reliable continuous integration service validated raw in. Needs to be a subclass of Objective-C’s NSObject ) MVC and MVVM for Swift. Design, GraphQL, using the standard library ’ s enclosing instance Swift! Type referencing property wrapper ’ s powerful SDK to Instabug for sponsoring Swift by Sundell when requesting free. That’Ll let us become the delegate of that session … Swift by Sundell lut 2017 – Obecnie lata... Genius Scan ’ s WWDC 2019 conference, by John Sundell through the main APIs that enable us do... Planning to start remastering older articles with new code samples and updates for later Swift versions new... Overall design of the swift by sundell has been tweaked in many places up, comfortable use! Brought to you by these wonderful sponsors: Bitrise Fast, powerful and! Main APIs that enable us to do just that Obecnie 3 lata 9 mies a powerful document scanner any...
City Of Frederick Public Works, Buy Pulp Riot Without License, Evolution Of Mario Tv Shows, Mitsubishi Mxz 2b20na Specs, Land Allotment For Ex-servicemen In Up, Amarone Della Valpolicella 2014,