Another week, another #iOSDevTips tweet!

We often attach gifs or videos to our pull requests to show reviewers our features in action. With Xcode 12.5, we’re able to save a few steps and record directly from the simulator! 😍

https://twitter.com/txaiwieser/status/1387892348378652672?s=20

Txai Wieser 🌿 on Twitter

“New on Xcode 12.5: If you hold the option key the Simulator shows an option to record the device screen. You can save it as a video or GIF! https://t.co/rnc2LqZPvA”

Twitter

🤩 Our tip this week is from @[email protected]!

To sort all the files in an Xcode group by either name or by type, select the group and navigate to Edit → Sort → By Name or By Type. #iOSDevTips

Here's a tip from @[email protected] 📣

Starting in Xcode 11, you can mark assets as “development assets,” and they won't be added to your shipping app—which is great for test data in SwiftUI previews! #iOSDevTips

https://useyourloaf.com/blog/swiftui-preview-data/

SwiftUI Preview Data

Where do you put your SwiftUI preview data? See how Xcode development assets can help.

This week's tip is from @[email protected]!

You can specify a hex value when defining colors in asset catalogs by selecting an individual color variant and using the Attributes Inspector. Comes in pretty handy if your design system uses hex values! 🎨 #iOSDevTips

Andi Rohn 🏳️‍⚧️ on Twitter

“"Xcode 13 adds column breakpoints which work like a more granular version of line breakpoints. Here’s how you use them." Via https://t.co/r5aCL576F2”

Twitter

✨ A tip from @[email protected]:

I don’t know who needs to hear this, but if you’re using an M1 Mac and your dependencies don’t support multiple simulator architectures, check “Open using Rosetta” in the Info Panel on Xcode and Simulator, and relaunch! #iOSDevTips

💡 This week's tip comes from @[email protected]:

If you're unsatisfied with Xcode Simulator gifs, you can adjust the quality and animation smoothness in the Simulator Preferences menu below—no more choppy gifs! #iOSDevTips

🤝Here’s a tip from @[email protected]: don’t forget to credit your teammates when you’re pair programming using @[email protected]’s co-authors feature. #iOSDevTips

Here’s how to use it: https://docs.github.com/en/github/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors

Creating a commit with multiple authors - GitHub Docs

You can attribute a commit to more than one author by adding one or more Co-authored-by trailers to the commit's message. Co-authored commits are visible on GitHub.

🌟Today’s tip is from our friend @[email protected]! Another super useful keyboard shortcut to remember:

#iOSDevTips https://twitter.com/jordanmorgan10/status/1428081541700325377

Jordan Morgan on Twitter

“💡Did you know? Xcode Edition 💡 You can zoom out and see all of your open tabs, the same way that you can in Safari, within Xcode. I use this to gain context on all that I've got going on and to quickly choose a file instead of tabbing my way there. The shortcut is "⌘ ⇧ \" https://t.co/DW8AauDlWQ”

Twitter

@[email protected] 🅰️ In iOS 15, you can limit the min and max sizes of Dynamic Type in any view using the new minimum and maximum contentSizeCategory properties.

This is great for making sure your layout doesn't break at huge sizes (but don't overdo it). #iOSDevTips

https://useyourloaf.com/blog/restricting-dynamic-type-sizes/

Restricting Dynamic Type Sizes

In iOS 15 you can set limits on the minimum and maximum sizes of dynamic type.

⌨️ One of our most-used Xcode keyboard shortcuts is ⌃⌘↑ — which lets you jump straight to an Objective-C header file for the current class, or generated interface for a Swift file. #iOSDevTips
🎨 Great tip from @[email protected] for transforming colors into human-readable names! #iOSDevTips https://twitter.com/jordanmorgan10/status/1450457677503635467?s=21
Jordan Morgan on Twitter

“🎨 Cool API Alert 🎨 AXNameFromColor. Snag a human readable string from any CGColor ✨ You can use this for accessibility traits to boost VoiceOver experiences, or even leverage its utility outside of accessibility specific scenarios where you simply need a color's name.”

Twitter
@[email protected] 🅰️🔍 This tip is especially useful if you work on apps that support Dynamic Type! #iOSDevTips
https://twitter.com/marcoarment/status/1457346686972571650?s=21
Marco Arment on Twitter

“THANK YOU to whoever added preferred-text-size changes as keyboard shortcuts in the iOS Simulator! (I don’t know how long they’ve been there)”

Twitter

@[email protected] Ever have your unit tests fail and end up with a console full of logs you don't understand? We've been loving this new feature from Kaleidoscope that helps you get to the bottom of it! 🕵️‍♂️🔍 #iOSDevTips

https://twitter.com/kaleidoscopeapp/status/1478411978527940613?s=20&t=Rne_1y84L3SBk6Lt84gGGQ

Kaleidoscope on Twitter

“Want to avoid the drudgery of interpreting complex XCTest failures? Kaleidoscope makes the diffs easy to spot! Here’s how: https://t.co/5kF29gH4G5”

Twitter

@[email protected] Last year, we found a performance issue in UICollectionViewDiffableDataSource. After reporting the bug & speaking to Apple at WWDC, @[email protected] was excited that it's now fixed in the iOS 15.4 beta!

If you have this issue, try Xcode beta 🎉 #iOSDevTips

https://twitter.com/mb/status/1445431586430799877

Matthew Bischoff on Twitter

“ friends that work on UIKIt, I’d really appreciate you taking a look at a pretty big performance regression in UICollectionViewDiffableDataSource that @Cordavi recently found. applefeedback://FB9649428 https://t.co/Na6Fgd0CQO”

Twitter

👀 Ever wanted to know where and how Apple uses web views in their Mac apps? Use the Web Inspector from Safari → Develop → App Name. #iOSDevTips

https://twitter.com/jimniels/status/1498337278875348994?s=20&t=79LHntuSfogtuJxNJXJAzg

Jim Nielsen on Twitter

“📝 Blogged some about how you can use Safari’s Web Inspector to look under the hood of certain views in macOS. No real utility here—just fun. Thx to @samhenrigold for the tip. https://t.co/TbeeWODla9”

Twitter

🔎 Have you ever needed to check if one Swift string contains another regardless of case? Use the options parameter on the .range() method & specify .caseInsensitive — thanks to our friend @[email protected] for the tip! #iOSDevTips

https://www.hackingwithswift.com/example-code/strings/how-to-run-a-case-insensitive-search-for-one-string-inside-another

How to run a case-insensitive search for one string inside another - free Swift 5.4 example code and tips

Learn Swift coding for iOS with these free tutorials

Hacking with Swift

📲 Ever needed to find the device ID of a running iOS Simulator? Try this handy Terminal command from @[email protected]:

xcrun simctl list | egrep '(Booted)'

#iOSDevTips

👀 For those times you don’t want to be distracted by Twitter, did you know that you can fullscreen Xcode and the Simulator side-by-side with split screen?

#iOSDevTips via @[email protected]

⏰ It’s super easy to forget about the Date.formatted() method that was introduced in iOS 15—so thank you to our friend @[email protected] for this #iOSDevTips reminder https://twitter.com/MuseumShuffle/status/1524738580068941826
Chris Wu on Twitter

“Wow! Rising star @tundsdev showed me there's a much easier way to display the specific date I wanted that will adapt to locales. I've been using .formatted(date:, time:) a lot but had no idea that this other variation existed.”

Twitter

If you’re ever writing UI tests and you want to see a textual representation of the UI tree, run print(XCUIApplication().debugDescription) 🤖

Thanks for the tip @[email protected]! #iOSDevTips

🔎 This is a great #iOSDevTips from @[email protected] ! We’re already using this new feature in iOS 16 to find and fix hangs in our apps.

https://twitter.com/qzervaas/status/1547123259484672000

Quentin Zervaas on Twitter

“The new “Hang Detection” developer option in iOS 16 is amazing. (Settings app > Developer > Hang Detection) Found 2 easily-fixed hangs immediately in Streaks. Device auto-records stack-trace when a hang occurs.”

Twitter

Our engineers have been waiting for this feature since SwiftUI was introduced! Thanks @[email protected] for the #iOSDevTips 🙏

https://twitter.com/clarko/status/1552383186604216321?s=21&t=0p4GnP-oBWCqgbOK7o30tQ

Clarko on Twitter

“Whoa, pull-to-refresh has a new trick in iOS 16 beta 4 👀 Used to be, SwiftUI could only do it on Lists. You have a Grid? Tough cookies. Now seems to work on any ScrollView!”

Twitter

🪧 Our designer was super excited that UIMenu gained size options for elements in iOS 16!

Specify them with the preferredElementSize API:
https://developer.apple.com/documentation/uikit/uimenu/4013313-preferredelementsize?changes=latest_minor

#iOSDevTips

Apple Developer Documentation

If you’re not already using an 8pt grid in your designs, @[email protected] makes it super easy to get into the habit with a configurable nudge shortcut. Set it up in the Canvas Preferences, under “Nudging” 👇 #iOSDevTips

🪫 If the Xcode 14 beta is draining your laptop battery, our friend @[email protected] put together a blog post with a workaround! It's been a lifesaver. #iOSDevTips

https://blog.nihongo-app.com/stop-xcode-14-beta-from-pegging-cpu/

Stop Xcode 14 beta from draining your battery

There's a bug in Xcode 14 betas 4-6 that causes your CPU to go crazy and drain your battery. Here's a workaround.

Nihongo Blog

🏎️ This tip from @[email protected] is making our SwiftUI even faster to write in Xcode 14! #iOSDevTips

https://twitter.com/edwardsanchez/status/1570168643962699777

Ed Sanchez on Twitter

“In Xcode 14, if you select a block of text and type {, it embeds the block in a closure and puts the cursor in the beginning of the closure so you can define it. Works great for SwiftUI!.”

Twitter

Have you ever tried to bold an alert action in SwiftUI? Here's a tip from @[email protected] to get the styling of a default action—set this modifier on your button:

.keyboardShortcut(.defaultAction)

If you’re frequently submitting builds to App Store Connect, this one weird trick will save you time on every submission! ⏳😅 #iOSDevTips

https://twitter.com/kslazinski/status/1573980451550613504?s=46&t=B9T4IBRs3LLcgzUzDo1VYQ

Kris Slazinski on Twitter

“👋 Hey, iOS developers. In case someone doesn’t know about this… You can add “App Uses Non-Exempt Encryption” to your Info.plist. After this App Store Connect will stop asking you if your app is using cryptography, every time you upload new build to TestFlight 🙂 #iOSdev”

Twitter

🤯 While we don’t need to do this often, it’s super handy to have an idiomatic way to iterate over relationships. Thanks for the #iOSDevTips Kyle!

https://twitter.com/kyleve/status/1575353657825972224?s=46&t=M3yeNJZAPcbK0hLlDDLqkA

Kyle says Yes On J 🏳️‍🌈 on Twitter

“One of my favorite Swift lessons over the last few months has been finding out about `sequence(first:next:)`, so you can easily iterate over a relationship like a superview: ``` for view in sequence(first: self, next: \.superview) { … } ```”

Twitter

One of @[email protected]’ favorite Xcode 14 features is the Product → Clear All Issues menu item 🧹

It’s super handy when working on large codebases that sometimes generate spurious warnings or errors during the build process #iOSDevTips

✨ Wanna add some juicy animations to your iOS app but don’t have time to build them from scratch? @[email protected] built the Pow library just for you! (And it’s only $99) #iOSDevTips

https://movingparts.io/pow

Pow – Beautiful Transitions for your iOS App

Beautiful Transitions for your iOS App

Moving Parts

This set of resources that recently came out is very helpful—thanks for sharing, @[email protected] 🙏 #iOSDevTips

https://twitter.com/mikaela__caron/status/1587066859278434304?s=12&t=nqshGkzyTDq4x1JiPeQ05A

Mikaela Caron 🦄 on Twitter

“💡Have you ever had an app idea, but no clue what to do next? I just saw this in the Apple Developer App, how to plan an app on all of Apple’s platforms, iOS, iPadOS, macOS, etc. It covers what you can do, where to start, and how to take your app further https://t.co/vnAubNcdb1”

Twitter

We’re back with more #iOSDevTips 👋

If you’re localizing your app & not sure how to find every string you need to localize, edit your scheme and check “Show non-localized strings” in Run → Options. Then, look for all-caps strings.

via @kharrison
https://useyourloaf.com/blog/finding-non-localized-strings/

🚂 Our engineers on larger projects have been waiting for this GitHub feature for a long time. Can't wait to queue up some PRs! #iOSDevTips

https://github.blog/changelog/2023-02-08-pull-request-merge-queue-public-beta/

Pull request merge queue (public beta) | GitHub Changelog

Pull request merge queue (public beta)

The GitHub Blog

Another GitHub tip:

If you find yourself always behind on code review (we’ve been there 😅), set up a Focus Mode for work & add the GitHub pull request widget to your home screen—like
@matthewbischoff does! #iOSDevTips

One of the things we’re most excited about in Xcode 14.3 and iOS 16.4 (out today!) is the new scrollBounceBehavior modifier in SwiftUI 📜 #iOSDevTips https://developer.apple.com/documentation/swiftui/view/scrollbouncebehavior(_:axes:)?changes=latest_minor

via: https://twitter.com/SwiftyAlex/status/1626586781188775941

scrollBounceBehavior(_:axes:) | Apple Developer Documentation

Configures the bounce behavior of scrollable views along the specified axis.

Apple Developer Documentation

🤞 Hoping the new backDeployed() API means we’ll be seeing backward-compatible SwiftUI from Apple during #WWDC23 so we can keep shipping great stuff to folks on older versions of iOS! #iOSDevTips

via:
https://twitter.com/sarunw/status/1626474657485570048

Sarun W. on Twitter

“In Xcode 14.3, it seems like Swift got a way to create backport of a new API to older ones using backDeployed(before:) attribute. Does it mean we would see more back-deployed SwiftUI features?”

Twitter
If you’ve ever wanted to use a subtitle in a menu in SwiftUI but didn’t know how, @TwigH figured it out. Just include a second text view in your label parameter, and voila! ✨ #iOSDevTips

🗺️ Our engineers have stumbled upon this a few times by accident—we didn’t know what was going on until we saw this tweet!

Very cool feature (when done intentionally 😂) #iOSDevTips

via: https://twitter.com/Lee_Kah_Seng/status/1640249889329147905

Lee Kah Seng on Twitter

“💡 Unintentionally discovered: Pressing ⌘ when hovering over the minimap will display detailed labeling of the minimap in Xcode. #iosdev #xcode”

Twitter

🚦 With #WWDC23 right around the corner, here’s a helpful blog post from @Mecid about how to use APIs only on operating systems where they’re available! #iOSDevTips

https://swiftwithmajid.com/2023/05/17/api-availability-in-swift/

API availability in Swift

WWDC is coming pretty soon, and we are going to use a bunch of new APIs. But how to use new APIs available only for the latest version of iOS? This week we will learn about availability conditions in Swift.

Swift with Majid

🧠 The new Observable type greatly simplifies data flow and improves performance in SwiftUI, and our engineers are so excited to use it! #WWDC23

However, there’s a critical gotcha that Apple mentions briefly in their docs—if you use SwiftUI, you’ll NEED to know this. #iOSDevTips

https://developer.apple.com/documentation/swiftui/managing-model-data-in-your-app

Managing model data in your app | Apple Developer Documentation

Create connections between your app’s data model and views.

Apple Developer Documentation

We’ve now seen indications that this behavior may be inaccurately documented. We tested it out ourselves in a minimal sample project, and everything worked as expected without making a new view —  it seems like this documentation may simply be incorrect. Phew!

Here’s further discussion on the forums: https://forums.swift.org/t/observable-in-swiftui-confusion/65407

`@Observable` in SwiftUI confusion

Fitting code on slides sometimes requires some things to be elided. The initializer part is something I think is reasonable to contain within the final version (because it is pretty heinous not to have it and rely on the default value definite initialization). Hence why I am a very strong +1 on the init accessors pitch. To me it is clear we need a solution in that space. The docs should probably be updated. Since that will (with modifications to account for the initializers and identifiable pa...

Swift Forums

Another update on this: Apple has confirmed that the docs are going to get updated.

(Thanks @chriseidhof!)

@lickability @chriseidhof Thanks for calling this out originally, and for posting a follow-up!

FYI we updated this document a few days ago, correcting that section as well as a few other changes:

https://developer.apple.com/documentation/swiftui/managing-model-data-in-your-app

Also check out the migration article, which was also updated recently:

https://developer.apple.com/documentation/swiftui/migrating-from-the-observable-object-protocol-to-the-observable-macro

Let us know if there’s more feedback or questions we can answer!

Managing model data in your app | Apple Developer Documentation

Create connections between your app’s data model and views.

Apple Developer Documentation

In Swift 5.9, if statements are now expressions—which means you can write them inline when declaring constants or variables! 🙌

😇 We’ll use this all the time for targeting features of new versions of iOS. #iOSDevTips

https://mastodon.social/@simonbs/110616035020244784

🔂 One of our favorite tiny additions to SwiftUI this year is the new .buttonRepeatBehavior modifier, which lets you make buttons that keep performing an action as you hold them! #iOSDevTips

https://mastodon.design/@hidde/110510737675569361

Hidde van der Ploeg (@[email protected])

Attached: 1 video So nice that this is now possible with a single line of code in SwiftUI (hold to repeat the action) It even speeds up as you hold it 😍

mastodon.design

🤯👠 Our SwiftUI engineers are head over heels for this change. No more need for arbitrary Groups to work around the limit! #iOSDevTips

https://mastodon.social/@twostraws/110678626975697398

🔴 Ever since we learned this, we’ve been adding SF Symbols to all of our custom notification actions. So many apps are still missing them! #iOSDevTips

https://twitter.com/natpanferova/status/1688446606285344768

Natalia Panferova on X

I recently discovered that we can add icons to action buttons in push notifications on iOS. Great way to make notifications more intuitive and visually appealing: https://t.co/J5weGbSUT2

X (formerly Twitter)

In SwiftUI, Picker is fundamental when you have options to choose from:

🚥 2 to 3? Use a segmented control.

📋 4 to 6? Try a menu.

👇 More than that? Stick with the classic list using this tip from @jordanmorgan. #iOSDevTips

https://mastodon.social/@jordanmorgan/111103633181909951

@lickability I think this looks worse than it is.

Previously, `@ObservedObject var books: [Book]` would have been totally invalid – the `@ObservedObject` property doesn't act on arrays, it acts on single objects.

This scenario looks like the same thing, it's just a little more subtle since there's no explicit attribute on the observed object.

@cocoawithlove @lickability yeah, this looks like the same limitation as having nested `@ Published` properties? I’ve had to write a few observers that map nested `objectWillChange` to `self.objectWillChange.send()`

Still good to know though. I think I’ve had one or two cases where I had to manually call `objectWillChange` for some reason, wondering if something like that is still possible?

@lickability Thinking about how the Observation framework works, this makes total sense in retrospect (and is very sad) 😕
@lickability in my testing this does seem to work, I'm not sure if the docs are wrong there?
@chris We have now tested this out in a minimal sample project and also see that it works. Thanks for checking – we'll follow up the post!

@lickability This will work in the final version, and the docs are outdated.

See https://forums.swift.org/t/observable-in-swiftui-confusion/65407/4

`@Observable` in SwiftUI confusion

Fitting code on slides sometimes requires some things to be elided. The initializer part is something I think is reasonable to contain within the final version (because it is pretty heinous not to have it and rely on the default value definite initialization). Hence why I am a very strong +1 on the init accessors pitch. To me it is clear we need a solution in that space. The docs should probably be updated. Since that will (with modifications to account for the initializers and identifiable pa...

Swift Forums
@tkrajacic Thanks for the heads up, we'll follow up our post with this info!

@lickability @nicklockwood Yeah.. there’s that magic again. It’s documented somewhere so not totally opaque, but as well as just declaring what you want, you also need a deep understanding of how that declaration is used by the engine that transforms it into imperative code.

When things stop working that becomes a nightmare. Same story as with cocoa bindings, GC, CSS, etc.

I prefer being explicit even if it results in more boilerplate code.

Hiding this code behind a macro is even nicer.