Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
r/swift iconr/swift icon

r/swift

members
online
Best
Open sort options
Change post view

Community highlights

  • FAQ and Advice for Beginners - Please read before posting

    votes • comments
  • What’s everyone working on this month? (November 2025)

    Swiftapple votes • comments
  • What’s everyone working on this month? (April 2025)

    Swiftapple votes • comments

  • New instance methods for 26.4+ betas! New instance methods for 26.4+ betas!
    FYI

    Even though we just got 26.2 Beta, looks like Apple is already publishing some new instance methods coming up with iOS 26.4+Beta, iPadOS 26.4+Beta, Mac Catalyst 26.4+Beta, macOS 26.4+Beta, tvOS 26.4+Beta, visionOS 26.4+Beta and watchOS 26.4+Beta.

    It’s a new overload of .task that adds:

    name: — a human-readable label that shows up in debugging/profiling so you can tell tasks apart.

    executorPreference: — an advanced hook to request a particular executor for the task hierarchy (for folks using custom executors).

    Still supports priority: and id: (the id causes the task to restart when the value changes).

    Debuggability: name makes async work much easier to trace in instruments/logs.

    Control (advanced): executorPreference is there if you need to steer where non-isolated async work runs.

    Familiar lifecycle: Same start/cancel behavior as the existing .task.

    Like other .task variants, it starts just before the view appears and is automatically cancelled when the view disappears.

    https://developer.apple.com/documentation/swiftui/view/task(id:name:executorpreference:priority:file:line:_:)


    u/RevenueCat avataru/RevenueCat
    Promoted
    Use AI to create subscriptions, manage products, and generate paywalls with the RevenueCat MCP.
    media poster

    revenuecat.com
    Learn More

    Announcing the Swift SDK for Android
    Swift on Linux Swift on Linux
    Question

    I have a command line app that I what to port to Linux from macOS. It has a few features that use AppKit (NSImage for example) that are not supported on Linux.

    Is there a way to custom compile to avoid those features. on Linux but still have them on macOS? As its only a small part of the application, I'd like not to have to have two separate code bases

    For example is there any in-source means to only import AppKit and use NSImage on build on macOS, perhaps with if #available(...)

    However, it seems I can't do this at the top-level

    import Foundationif #available(macOS 10.0, *) {    import AppKit}

    Then I was then hoping to use if in functions, but it not working how I wanted for example...

            if #available(macOS 10.0, *) {            // I wanted this to run only for macOS, but...            print("This gets printed on Linux and macOS")        } else {            print("This never prints")        }

    Seems #available(...) is always true on Linux, or I'm doing this wrong

    Or, maybe there is a way to leverage the SPM to build with different source files depending on the platform? I'm quite new to SPM and I think I'm struggling to find the right set of words to google for platform dependent building


    Created Nov 23, 2013
    Public

    Anyone can view, post, and comment to this community

    45K433

    r/swift Rules

    Your post should be related to The Swift Programming Language. We get it, Taylor Swift is great but unless she's starting a new career as a Swift developer, we don't need to know about it.

    We know you're passionate about Swift but, please be respectful and follow reddiquette. Any form of abuse, discrimination (whether racial, sexual, religious etc) or any vulgar comments/posts are not tolerated.

    Make the original source of the content your submission, and do not use URL shorteners. If a mirror is necessary, please provide one in comments. No hotlinking or rehosting someone else's work (unless they specifically allow it in their terms of use or request it).

    Post direct links to your source.

    Before posting your question, use the search bar to make sure your question has not been answered before. If you think your question is simple, please post it in the monthly pinned thread titled "Got an easy question? Ask it here!"

    Self promotion is tolerated for people that are contributing to the community by answering questions and engaging in constructive discussions. Fewer than 5% of your posts (including comments) should be self promotion. If you have fewer than 5 posts/comment on the sub, or your account is less than 2 month old, self promotion is not allowed.

    Note: If your post is about a job opening, youmust include the name of the company and a salary range, otherwise your post will be removed.




    Related Subreddits

  • r/iOSProgramming icon176,165 members
  • r/SwiftUI icon54,138 members
  • r/SwiftPM icon987 members
  • r/ios icon851,685 members
  • 60,105 members
  • r/MacOS icon482,727 members

  • Moderators

    View all moderators

    [8]
    ページ先頭

    ©2009-2025 Movatter.jp