I am trying to implement in-app purchases for my app.
import StoreKit
import UIKit
class BuyStoreViewController: UIViewController, SKProductsRequestDelegate, SKPaymentTransactionObserver {
//code
}
However, It keeps giving me the errors "Cannot find type 'SKPaymentTransactionObserver' in scope" and "Cannot find type 'SKProductsRequestDelegate' in scope". I think it has something to do with the implementation of StoreKit, but I am not sure. Additionally, the "SKProductsRequestDelegate" and "SKPaymentTransactionObserver" are greyed out (it does not turn purple like the "UIViewController" does). Does anyone know what to do?
Thanks in advance!
Update: I just had to move all my files to a new project, that worked for me.
Related
I want to change isIdleTimerDisabled when a specific view appears. In SwiftUI I use
.onAppear { UIApplication.shared.isIdleTimerDisabled = true } .onDisappear { UIApplication.shared.isIdleTimerDisabled = false }
but even with import UIKit I get the warning "Cannot find 'UIApplication' in scope". How can I fix that? I didn't find a solution after searching for more than an hour.
You should not need to import UIKit, it should work with SwiftUI.
The problem may be your target. Is the file used only on an iOS or iPadOS application target?
Or is it also used, for instance, in an extension, like ShareExtension, and so on?
If it is, you cannot access UIApplication within your code. If this code is shared between extensions and app, you should use conditional compilation to avoid this problem.
I'm new to swift playground, and I tried to create a instance of Type like Scene or Graphic. But every time I try it keep saying cannot find 'Scene' in scope or cannot find 'Graphic' in scope.
What I am missing here?
Thanks
If you're using Xcode 12.5 beta, try to enable import App types from the right menu (you can open the right menu using the top right corner button). I think that should solve the problem, but i could be wrong.
Also read this answer by Vitali
I have been learning Swift and had a recurring problem throughout. The playground, when run, doesn't finish running the code, even the default MyPlayground file. I get no output whatsoever.
I have searched online and others have the same problem as me but no answer. This happens for the default and built up files I have created previously.
I spoke to Apple on 3 separate occasions and got nothing and referred to the Developer forums and they haven't got an answer either.
Any ideas guys?
For example,
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
print(str)
This is the default and when run, I don't get the output of str or anything in the Utilities view, it just says running MyPlayground at the top.
Thanks
What are you building for? iOS, macOS, or tvOS?
The default file for macOS is as you say:
import Cocoa
var str = "Hello, playground"
Which runs perfectly, with no errors.
But when I run your code built for iOS, Xcode throws an error:
Swift Compiler Warning: No such module `Cocoa`.
Either way, you cannot import Cocoa in playgrounds built for iOS, so don't import Cocoa, import UIKit instead. Besides, import UIKit is the default file when building for iOS. So I suspect you're running the default macOS file in an iOS build of playgrounds.
There is another question here which addresses the issue of importing Cocoa in Playgrounds.
Since you're having what looks like a null pointer exception, based on your comment, likely from the project trying to load a non-existent object, here are some troubleshooting steps:
Erase import Cocoa.
Type in import (Notice the space at the end.)
Type in C
If C doesn't come up with an autocomplete list with Cocoa in it, then it's not part of the build.
And this would explain the null pointer exception (EXC_BAD_ACCESS at 0x0.)
Next, in the same playground:
Erase the import Cocoa line
Type in import (space at the end.)
Type in UI and wait for an autocomplete list
If UI has the autocomplete option for UIKit, then Cocoa isn't part of the playground.
Which is why there is a null pointer error.
After successfully implementing the MFMailComposeViewController in my app, run it in the simulator and my iPhone, where it still works fine, it just crashed.
I get 5 MFMailComposeViewController.h issues: Cannot find protocol declaration, Expected identifier or '(', etc,...
My Controller header includes:
MessageUI/MessageUI.h
MessageUI/MFMailComposeViewController.h
and conforms to protocol:
#interface DetallViewController : UIViewController < UIActionSheetDelegate,
MFMailComposeViewControllerDelegate>
I've tried to:
1) remove and add the framework
2) Restart the device and Xcode as suggested in many posts
3) Create a separate controller to handle MFMailComposeViewController
After 3 days with this issue I'm completely stuck on this. As you can imagine, any help would be appreciate.
I would think this is a kind of reference issue since it appears whether the framework is selected or not.
Thanks in advance
Just to anybody it may help, I finally found the issue:
A missing #end in an imported header.
Thanks to everybody for the efforts.
Can anyone please help me to solve the following error:
Error cannot find interface declaration for 'NSManagedObject', superclass of
Try
#import <CoreData/CoreData.h>
Are you missing an include statement?
Are you subclassing NSManagedObject? If so, go here in Apple's documentation and scroll to Xcode Generated Subclasses. They give you instructions to have Xcode generate class files from your data model.
A suggestion: Core Data is rather difficult, and you should be comfortable with iPhone development before you start working with it.
import CoreData to your xxx-Bridging-Header.h will make sense.