Environment: Mac mini M1; and iPhone 6s Plus, etc.
Mac OS 11+, iOS 14+
I'm using SwiftUI/Combine Frameworks versus Storyboard.
Scenario: I have an iOS application that I want to expand into a MacOS sister application; and probably add more functionality too.
I assume that 'Catalyst' is an option on the iOS side to map it to the MacOS environment without hassle with the code.
I also assume that from this baseline, I could create a MacOS target and share common code between the two and add compiler directives to separate the MacOS & iOS specifics.
Am I correct?
Given an iOS target that is Catalyst enabled (eg the "Mac" checkbox checked), you can use any frameworks/functions marked as available in iOS and Catalyst.
You can also conditionally compile for the different systems using things like:
#if targetEnvironment(macCatalyst)
or various #available configurations (https://nshipster.com/available/).
If your question is whether you can use macOS-specific code (not marked as available in Catalyst), like AppKit, for example, the question becomes more complicated. One can import and use a bundle with AppKit code, but it's not what I would call a streamlined process. See: https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit
Related
I am writing a tvOS app. Up to now I was developing the code as an OS X framework with a prototyping OS X app.
Now I would like to add the production tvOS app into the mix, keeping the OS X prototype. Which means I need the framework to be built both for OS X and tvOS. This should not be a problem in the principle, since I only use frameworks available on both platforms.
Is it possible to build a cross-platform framework? What settings do I use?
Yes it's commonly done. Create a new Xcode target, targetting tvOS, and add the same source files as the OSX target.
If you need to include/exclude/change code or behaviour at compile time then you need to #import <TargetConditionals.h>.
Is there a way to add google maps or mapbox to osx app built with swift in xcode? Both websites only show api for ios. Is there any option to add maps to osx app without using apple maps?
I recently ported the Mapbox iOS SDK to OS X. It can be used with either Objective-C or Swift on OS X 10.10.0 and above. Until there’s an official release, you’ll need to clone the mapbox/mapbox-gl-native repository on GitHub and build the project from source. Most of the Mapbox iOS SDK documentation applies equally to the OS X port. The project comes with a demo application as well (via make xproj).
Update: You don’t have to build it from source anymore! See https://github.com/mapbox/mapbox-gl-native/releases/ for prebuilt releases of the Mapbox macOS SDK. (Look for releases beginning with “macos-”.) See the SDK’s homepage for more information and an API reference.
There is no google-maps SDK for OS X. Your only way to go to is add a webView into your app and load a html that contains maps api calls linked to your AUTHORIZATION TOKEN.
Technically Mapbox GL runs on OS X, but it's direct C++, which means that you'd have to wrap it in Objective-C in order to use it with Swift, but it is possible.
I have just create a simple project using swift language, then i compile and archive it to generate .ipa file. IPA file is so big, it is about 5 MB.
is it right(no problem) at there? when i create it in Objective-C, it is only about 500kb.
Yes, that's about right. The libraries containing the entire Swift language have to be embedded in the IPA. Those libraries are part of the app, not part of the system - because Swift has to work even with backwards compatibility, in part because it is constantly changing (independently of system updates), and in part in order to work on iOS 7 (where the system has never heard of Swift). And they are about 5MB in size.
To expand on matt's answer, here's a quote from the Swift blog on compatibility:
You can trust that your app will work well into the future. […] This is possible because Xcode embeds a small Swift runtime library within your app’s bundle. Because the library is embedded, your app uses a consistent version of Swift that runs on past, present, and future OS releases.
So if your newest app version was built with Xcode 6.0, and a user of your app is running iOS 8.1, and breaking changes to Swift were introduced to your app in between, your app won't break due to the iOS update. If your app just used system libraries, it could.
This allows the developers of Swift to iterate more quickly without needing to build backwards compatibility between every version.
An additional warning:
While your app’s runtime compatibility is ensured, the Swift language itself will continue to evolve, and the binary interface will also change. To be safe, all components of your app should be built with the same version of Xcode and the Swift compiler to ensure that they work together.
Using Xcode playground I cannot choose platform (iOS or OS X)
It stay for me on OS X
and even I change on Utilities (View>Utilities>Show File Inspector->Playground Settings->Platform) to iOS I cannot use resources and playground is not working.
Please help me.
You are better of creating a new playground in the correct environment. I tend to have at least two playgrounds open, one for ios and one for osx.
Within Xcode 6.2 it also seems like changing the playground type as you suggest does work. At least I'm able to import relevant modules as expected in the different environments.
Mavericks is coming out and for developers that's always a busy time with all these new features and APIs to know about and use. For me, I think it is the perfect time to ask a question that has been bugging me for a very long time.
Here's the thing, in context: I am developing an app that I want to be able to run on 10.8 (so the target system is 10.8+). Right now I am using the 10.8 SDK. However, with the release of 10.9 comes some pretty sweet APIs that I would like to use in my app. I use them in my code, but then, of course, I have to compile my app against the 10.9 SDK. If I do that, can I still run the app on 10.8?
Or, in a more general way, if I compile my app against one SDK, can I still run it on a 'lower' Mac OS? If yes, can you explain how does it work under the hood (what is the compiler doing)? This is a mistery for me.
Generally speaking, Xcode disassociates the issue of the SDK and the Deployment Target of the app.
The SDK is determined by Base SDK, and the deployment target is determined by OS X Deployment Target. These both show up in the Build Settings tab for each target in Xcode.
When programming with different SDK and Target, you are responsible for making sure that you don't call methods or functions on an OS that doesn't have them. This is often facilitated by weak linking (in the case of new frameworks) and/or using -respondsToSelector: in the case of new methods on existing classes and frameworks.
In Xcode, under build settings, there is an option for target OS where you can pick 10.8. 10.8 applications are generally compatible with 10.9 so the compiled application will work with both OSs.
Don't expect the new Apis to work when running on a lower version. It doesn't work that way.