How to fix the ratingControl class in iOS Xcode app Food Tracker? - ios

ratingControl class error
How do I fix the errors that happen with this line of code? I've tried everything. Thank you.

Your code uses Swift 2.2 syntax, which is available from Xcode 7.3.
See Xcode 7.3 release notes for more details https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
The Objective-C selector of a Swift method can be determined directly with the #selector expression, for example:
let sel = #selector(insertSubview(_:aboveSubview:)) // sel has type Selector
So the answer to your question - you need to update your Xcode from 7.2 to 7.3 version, and the error will go away.
If you don't want to update Xcode - use an old selector syntax, for example:
selector: "ratingButtonTapped"

Related

Xcode 14 beta: How to fix errors in Widget Custom Intents?

I opened the "Emoji Rangers App Xcode project created by Apple [click to download]" for the demo of WidgetKit and wanted to follow up with WWDC22 video.
However, while it worked fine in Xcode 12, when I opened this project in Xcode 13 beta, I got errors like this:
Method 'provideHeroOptionsCollection(for:)' with Objective-C selector 'provideHeroOptionsCollectionForDynamicCharacterSelection:withCompletion:' conflicts with method 'provideHeroOptionsCollection(for:with:)' with the same Objective-C selector; this is an error in Swift 6
Method 'confirm(intent:)' with Objective-C selector 'confirmDynamicCharacterSelection:completion:' conflicts with method 'confirm(intent:completion:)' with the same Objective-C selector; this is an error in Swift 6
Method 'handle(intent:)' with Objective-C selector 'handleDynamicCharacterSelection:completion:' conflicts with method 'handle(intent:completion:)' with the same Objective-C selector; this is an error in Swift 6
Please help me - how can I fix it?
BTW it's in the DynamicCharacterSelectionIntent.swift file, which says:
// This file was automatically generated and should not be edited.
You can use the Adding widgets to the Lock Screen and watch faces example project which extends the project you want.
However, while it worked fine in Xcode 12, when I opened this project in Xcode 13 beta, I got errors like this
You'll need Xcode 14 beta to run it. I don't really understand why would you use Xcode 13 beta these days – it was released a year ago.

xcode 8 beta - Error compiling to the real iOS device

I couldn't find any related topic so I am starting the new one.
I have macOS Sierra and latest xcode 8.
When I attach my iPhone to macbook and try to build even clean project in xcode I get following swift compiler errors:
Attempting to use the forward class 'UIViewController' as superclass of 'UIActivityViewController'
Attempting to use the forward class 'UIViewController' as superclass of 'UIAlertController'
And so on. Error count is 21 and is always same no matter what project I choose.
Someone have same problem? Any solution?
Thanks for any answer.

Xcode 6.2 - Expected type after 'as'

First time seeing this error, can't i put '!' after 'as' in swift?
Or just bug after updating my Xcode to 6.2?
let url = notification.userInfo![CallbackNotification.optionsURLKey] as! NSURL
It shows error :
Expected type after 'as'
P.S: You can try download OAuthSwift from github to test this error.
https://github.com/dongri/OAuthSwift
The as! notation was not introduced until Xcode 6.3. You have Xcode 6.2, so you have to say simple as. Xcode 6.2 does not understand your as!; that is the cause of the compiler error you are getting.
(Note that if you take those ! away, then when you eventually switch to Xcode 6.3 you have will have to bring them all back again! It really is best not to change Xcode versions backwards and forwards like this. If your code was written originally with Xcode 6.3, you should stay with Xcode 6.3. The only problem is that in that case you cannot submit an app to the App Store until it goes final; right now it is still in beta.)
You don't have to add ! to as to unwrap your optional variable in XCode 6.2

Was I supposed to get a warning [duplicate]

This question already has an answer here:
Why is the Xcode compiler not warning me about invalid methods for my Deployment Target?
(1 answer)
Closed 9 years ago.
In my code I use
[[self presentingViewController] dismissViewControllerAnimated:YES
completion:dismissBlock];
The thing is my deployment target is set to: 5.0.
While base SDK is 6.1.
Was I not supposed to get a warning by XCode? (because I think the above method got introduced in iOS6).
Unfortunately no, Xcode doesn't check if you use symbols that are not available in your deployment SDK.
It only checks your code against the base SDK.
But you can use some third-party software for this, like DeployMate.
That being said, as others pointed it out, dismissViewControllerAnimated:completion: is available since iOS 5, so your code is safe.
But it's always a good idea to check for unavailable or deprecated APIs in your app, using something like DeployMate.
EDIT
Here's an answer to your comment:
If you deployment target is 5.0 and your base SDK 6.0, using a symbol available in the 6.0 SDK on an iOS 5 device will crash the application.
But Xcode won't warn about this when compiling, hence the need of some third-party software.
Once you identified the problematic symbol, using respondsToSelector: is the way to go, as it's better than simple version checking.
This way, you can have conditional code that will run with both SDK versions:
if( [ someObject respondsToSelector: #selector( someIOS6Method ) ] )
{ /* iOS 6 code */ }
else
{ /* iOS 5 code */ }
Only do this if you have detected SDK issues. Don't do this for everything.
According to UIVIewController class reference, this method is available from iOS 5.0 and higher.
Availability
Available in iOS 5.0 and later.
It is not ok to warn you. It doesn't have this warnining included in the default bundle of the SDK.

Problems with iAd changes in 4.2

I'm trying to use iAds in my app but I want to support all versions from 4.0 upwards. However the code for setting the current size identifier has changed in the 4.2 sdk, it used to be:
ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
but in 4.2 the code is:
ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
and therefore when if I use the old code in the 4.2 sdk it crashes and if I use the correct code for 4.2 any device running a previous version to 4.2 crashes. Does anyone know how I can support both or will I have to use 4.2 as the deployment target?
There is a workaround to support both 4.2 and earliers versions.
You could check if the constant exists at your ios version using something similar to the code bellow:
NSString *sizeIdentifier = &ADBannerContentSizeIdentifierLandscape != nil ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifier480x32;
and then just use the string to initialize you iAd view
[yourAdBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObject:sizeIdentifier]];
[yourAdBannerView setCurrentContentSizeIdentifier:sizeIdentifier];
There's some other problem in your code — use of ADBannerContentSizeIdentifier480x32 under 4.2 does not cause a crash, indeed it doesn't even trigger a compiler warning. It's deprecated but remains available.

Resources