Why does Xcode want me to add "#available" checks when the Deployment Target is already at a higher version? - ios

My SwiftUI project has its Deployment Target version set to 15.0. However, when I try to use the new Logger API, I'm still getting warnings about the SDK is only available for iOS 14 or above.
Could it be that an extension to UIImage requires something special? I have a few other files that I used the Logger and the compiler isn't complaining.

As suggested by Kiril, the problem happens because the Test Project was targeting 13.2.
Grep showed that project.pbxproj file has a 13.2 specified. After changing the xml file directly, the problem disappeared.
(I didn't notice this because the test Target doesn't have a place showing the "Deployment Info".

Related

iOS or macOS project: duplicate interface definition for ViewController

I am trying to build a common Xcode project for macOS and iOS. My project directory structure is
MyApp
Common
AAPLAppDelegate.h
AAPLAppDelegate.mm
AAPLRenderer.h
AAPLRenderer.mm
MyApp_iOS
AAPLViewController.h
AAPLViewController.mm
main.m
MyApp_macOS
AAPLViewController.h
AAPLViewController.mm
main.m
build gives Duplicate interface definition for class 'AAPLViewController'.
I have added AAPLViewController.h in Build Phases -> Headers of corresponding macOS and iOS schemes.
I have also assigned corresponding macOS and iOS target membership to all files in MyApp_iOS and MyApp_macOS folders.
I tried comparing my project to an working macOS and iOS project but couldn't find a clue to avoid the error.
here is the git repo of it; macOS code isn't complete yet but iOS target should be built without above error.
You need to correctly setup your headers search paths. First, set ALWAYS_SEARCH_USER_PATHS to YES. If that will not work - add only needed headers to USER_HEADER_SEARCH_PATHS setting.

Error - "Class is unavailable : Cannot find Swift declaration for this class", while building app on iPhone 4s (iOS 9.3)

My App has been created under iOS 10.2, and when I'm trying to create a build of the app to run on iPhone 4s (iOS 9.3).
I'm using two frameworks :-
ViewModelExtensions.framework (github.com/jozsef-vesza/ExpandingTableView/tree/master/ExpandingTest/Carthage/Checkouts/ViewModelExtensions/ViewModelExtensions)
ExpandingTableView.framework (github.com/jozsef-vesza/ExpandingTableView) in my project.
I'm not able to create a built for my project. Its giving me 3 main errors as follows :-
ExpandingTableViewController is unavailable: cannot find Swift declaration for this class
ExpandingTableViewCell is unavailable: an not find Swift declaration for this class
Use of undeclared type ViewModelType
The thing is its perfectly running on all simulators supporting iOS 10.2. What shall I do ?
Here is the screenshot.Screenshot
My Code - Project
Reason your code not running is because one of the framework you have added Expandable tableView has minimum target requirement specified as 10.2 :) So you can not run it on anything less than iOS 10.2 :)
Now you can't change the frameworks minimum target, so change your projects development target :)
Solutions :
Change Development target to 10.2 in your project
Or get rid of the framework and find something that has minimum target as iOS 9 :)
We'll need more detail (code, did you use pods, etc.)
However, this looks like a problem with the referenced frameworks (I assume you've imported UIKit at least). I suspect (without seeing your code) that you're getting errors next to the frameworks above at build time. If so, there are a few things to check:
Make sure if you used cocoapods, you are using the 'workspace' and not the 'project' file.
Check and see if your "target membership" (you can see this in the inspector to the right of your class code) is set to the proper targets (i.e. your app - and probably nothing else at this point)?
If these checks fail, try re-installing the frameworks (again, depends if you used cocoapods or embedded them via Xcode (point 1 above)).

Adding swift to obj-c project causes Generic archive to be generated?

After adding Swift support to an existing Obj-C Xcode 6.4 project it's now generating Generic Xcode Archives instead of iOS App Archives.
The commit that broke it is here: https://github.com/thoughtbot/Tropos/commit/57da8e4
What can I do to have this generate iOS App Archives again?
Looks like my "Installation Directory" was set incorrectly. It was set to $(BUILT_PRODUCTS_DIR) when it should be set to Applications. Manually doing this or removing the custom setting does this.
See https://stackoverflow.com/a/30921685/1720355 for original answer/explanation.

Xcode 6 GM won't compile for iOS device, but is fine in simulator - odd error message

I have a project that compiled just fine in XCode 6 beta, but now, in the GM, it won't compile for an iOS device, giving the error:
myController.m:393:9: No visible #interface for 'UIDevice' declares the selector 'initialize:'
at this line:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
It still compiles absolutely fine for the simulators; I've also tried these fixes:
Cleaned the whole project and re-built.
Deleted all Derived Data from ~/Library/Developer/XCode
Re-installed XCode
Checked XCode preferences and pointed Command Line Tools location to XCode 6 (XCode 5 is still installed on the machine and it was pointing there)
...but with no luck. Same error on compilation.
Help! We're on a tight timescale with iOS8 now approaching, and this is a real headache.
PS: We're also using Cocoapods in the workspace, for what it's worth.
OK, I solved this one after rather a lot of hair-pulling. The app in question is an iOS 8 app, with an embedded Today Extension.
It turned out that, when adding the Today Extension, XCode had added a build setting:
'Enable Modules (C and Objective-C': YES
Neither my project nor my containing app targets used this build setting, but setting it to YES caused issues to do with trying to link Frameworks automatically (and failing) and all sorts of related odd error messages that ultimately related to header files.
The problem was further compounded because there are source files that are members of both the containing app's target and also the Today Extension's target.
Hope this info helps somebody else.
Carl

iOS Xcode: Warn about methods not in minimum target SDK

Is there a way to have Xcode tell me when I'm calling a method that isn't available in the SDK of the minimum supported target?
For example, the method [NSURLConnection sendAsynchronousRequest:queue:completionHandler:]. This method is available on iOS5 and up. But my application's minimum target is iOS4.
If I use that method (sendAsync), I'd like Xcode to tell me that that method isn't available for the minimum target I'm trying to support.
I've tried putting __IPHONE_OS_VERSION_MAX_ALLOWED=40000 in the preprocessor settings, but that just triggers a bunch of Apple SDK errors that aren't helpful. (Probably because my active SDK is iOS5.1)
Is the only solution to get ahold of old SDKs and install them in Xcode?
Are there any easier solutions?
There is unfortunately no standard way of doing this. By setting the target OS to a lower number than the base SDK, Xcode will weakly link the libraries and frameworks. When doing that Xcode will not warn you for using methods that may not be available on the target OS.
You could temporarily set the base SDK lower, but that might not always work. Since you want to ignore most of the errors and warnings produced (because they are only called conditionally in your code path), and many warnings and errors are dependant on other error that you may need to resolve before the compiler will give any meaningful output.
I do not think there exist any static analysis tools for this, neither from Apple nor third party.
After doing some research, reading the Apple Doc about it, and trying a number of things. The solution is downloading an old Xcode DMG from Apple, grab the .pkg file for the same SDK as your deployment target and install it in your version of Xcode. Here's how:
Download older Xcode.dmg from Apple
Open the DMG
In Terminal, go into packages: "cd /Volumes/[DMG]/Packages; open ."
Find the SDK you want, something like iPhoneSDK_4.0.pkg
Install that package, but change the install directory to /Applications/Xcode/Contents/Developer
Restart Xcode if it was open.
Now that you have the same SDK as your deployment target, set your BaseSDK to the same. When you build you'll get warnings about missing methods. Your project may or may not successfully build with an older BaseSDK in a new version of Xcode, but that doesn't matter - you've just found the method calls you need to wrap in a feature check with respondsToSelector:.
As of Xcode 7.3, the compiler can now generate these warnings for you. All you need to do is set the -Wpartial-availability warning flag in the Build Settings, as described in this answer.

Resources