Xcode playground platform issue - swift-playground

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.

Related

Can I mix Catalyst with MacOS target?

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

Cocoa GUI done with Interface Builder has correct layout on my machine, incorrect on another

I'm trying to build a rather simple GUI using xCode/Cocoa. I've designed it in Interface Builder using a storyboard and set the corresponding constraints.
I'm using xCode 7.3.1 on 10.11.6 (El Capitan) ... the deployment target is set to 10.9. On my machine, everything looks fine:
When I run the application on another machine 10.10.5 (Yosemite), it looks like this:
I've tried lots of different combinations of vertical and horizontal stack views to organize the elements.. as well as setting some dummy constraints. The result on the Yosemite machine will change slightly, but is never correct/the same.
UPDATE: I've found out that if I don't use neither vertical nor horizontal stack views, the situation gets a lot better. Still doesn't really explain why it can look different on 2 machines
How is this possible? I thought the .storyboard file is fixed at compile-time?
Any hints you can give me will be greatly appreciated.
I was able to solve this (more of a workaround, actually) by removing all stack views from the storyboard.
Also, I took a closer look at the "Automatic preferred width mode" warning:
Solved those by following the steps described here:
https://stackoverflow.com/a/27867875/649700
I'm still puzzled as to how this is even possible. If stack views are not fully supported or don't behave the same way earlier OS versions, there should at least be warning when I choose "deployment target 10.9"! Better yet, Xcode should disable the stack views altogether if that's the case.
Hope this helps someone out there.

Developing app for 10.8+ but using 10.9 SDK

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.

Is Xcode 4 ready for iOS development or still too beta?

I am just starting iOS/iPhone development and I would like to start using XCode 4 instead of XCode 3.2. Is XCode 4 stable/feature complete enough for beginning iPhone development or should I stick with XCode 3.2?
I have run into far too many problems using beta versions of XCode, especially since you can't really have two versions of XCode one the same system. Apple already has a history of releasing things to developers before they are truly ready (just look at iAds for the iPad which were released months ago and have yet to deliver a single ad). So, if even Apple isn't ready to label XCode 4 as ready-to-go then you can rest assured its not really ready to go.
I recommend sticking with 3.2. That's what I'm doing until XCode 4 is officially supported.
Using XCode 4 calls everything you do into question. Having a problem with an API? Maybe it's XCode, maybe its your code, maybe its a bug in the API. You just don't know.
I would say no, it's not ready. I tried using it as my main development environment for about a week, and eventually switched back to 3.2. For one thing it crashed fairly regularly, but I could get passed that.
The big thing that caused me to switch back was a bug where the iOS simulator would think that certain resources existed in my app that didn't. Deleting the app from the simulator didn't work, cleaning the project didn't work, and deleting the derived data folder didn't work. Since it's not officially released, finding help for problems like this is a pain as well.
This is just one instance of the kind of problems you'll run into while using it, so I'd recommend avoiding it for now.
You can use Xcode 4 if you do not plan on using the current version (Preview 6) for submitting apps to the App Store.
iOS Dev Center:
Xcode 4 Developer Preview 6 includes
iOS SDK 4.2, bug fixes, and additional
features. To compile submissions for
the App Store, continue to use Xcode
3.2.5 and iOS SDK 4.2.

Do I have to compile my iPhone app with 4.2?

I have iPhone application in the App Store. Do I have to compile my app with iOS 4.2 SDK in order to allow it run on iOS 4.2 devices? Or compiling using iOS 4.2 is required only to allow using new features of new iOS?
I will appreciate if you can clarify this issue...
Thanks!
Yoash
Do I have to compile my app with iOS
4.2 SDK in order to allow it run on iOS 4.2 devices?
No, it will run on the new firmare just fine. At least if the new firmare does not reveal some bugs in your code (which happens).
You don't need to recompile it to let it run on newer OS versions, but like you already guessed, you need to recompile it when you want to use the newer features (eg. AirPlay, "Multitasking" etc).
The old version should still run.
The app might not play well with new features like multitasking on iPad, so it is worthwhile trying to get some testing and feedback done as soon as you can in case there are issues.
If you download the XCode 4 pre-release from the developer portal, you can use the new static analyser to look for problems in the code: this is not just for SDK issues but also things like memory leaks.
Apple recommends that you always compile with the latest SDK, even if you are targeting older versions.
Unless you run into a specific issue that is causing incompatibilities, it is wise to take this advice. A lot of small bugs and performance issues are fixed with each new iteration of the SDK.
That being said - you can continue to use the older SDK's, and Apple will still accept the apps you build. For mature apps that are only going through minor tweaks, this is probably the safest course to avoid introducing new bugs.

Resources