I am trying to send an update to an application built in Xcode 7, Swift 2.3. The application builds and runs fine with no issues, however, when I attempt to Archive I receive "Use of undeclared type 'MFMailComposeViewControllerDelegate'".
I figured it was just my old project giving me grief so I created a new project which had one class:
import UIKit
import MessageUI
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {}
Again, it works when building and gives me the same error when archiving. I am currently using Xcode 8.0, any ideas??
Related
I was trying to use the UIDocumentPickerViewController to import some pdf files in my Swift UIKit App. I'm not able to properly use the UIDocumentPickerViewController to display the files app and import the files from there.
The initialiser UIDocumentPickerViewController(documentTypes: [String], in: UIDocumentPickerMode) was deprecated in iOS 14.0. I can still use it but is there a better way to do the same thing which is not deprecated and is used in the latest version of iOS?
Importing "UniformTypeIdentifiers" seems to enable the "init(forOpeningContentTypes: [UTType])" initializer.
I need help understanding when to use #main vs #uiapplicationmain.
From what I know, #uiapplicationmain is an easier way of calling the uiapplicationmain(:::) where the class that is made after #uiapplicationmain is used as the App Delegate. I also know that it also creates an UIApplication.
I also know that app delegate becomes the entry point for the project.
From what I have read I was told that #main is also a entry point but it requires an main function.
What I want to know is what do they mean by the main entry point. Like what is Xcode doing to make it the "entry" point. And how does the whole #main thing work, as in how does it differ from #uiapplicationmain and what is it doing to the way Xcode runs the code.
All code has an entry point: the place where whoever calls that code actually calls. How does the whole program, comprising many Swift files, actually get started? We need an entry point for the whole program, which the runtime will call to launch us.
In Swift, this is the main.swift file. Its job is to call UIApplicationMain, which creates some instances including the app and the app delegate and gets the event loop running (and stays running for the rest of the time the app runs). A minimal main.swift file would have to look like this:
import UIKit
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv, nil,
NSStringFromClass(AppDelegate.self)
)
However, no one ever uses a main.swift file! It's boilerplate, so why bother? Instead, you say #main, and a main.swift file is generated for you behind the scenes. In particular, you put the attribute #main on your AppDelegate class, so the main.swift generator knows which class to instantiate as your application delegate.
Two more things to know:
Before Swift 5.3, #main was called #UIApplicationMain instead. From that point of view, they are identical, two names for the same thing.
New in Swift 5.3 and Xcode 12, you can designate one of your own types as #main and give it a static main function, where you do whatever you would have done in the main.swift file. That is something #UIApplicationMain cannot do:
#main
struct MyMain {
static func main() -> Void {
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self)
)
}
}
#main is part of the new SwiftUI lifecycle, introduced in iOS 14.
#uiapplicationmain is the older version that's part of UISceneDelegate and UIApplicationDelegate, but is still in use. Both represent your app's lifecycle.
I'm getting an module error in two of my controllers who tries to import the NotificationCenter framework. I have added the framework in "linked frameworks and libraries" but I'm still getting the error.
I even tried cmd + shift + k, but it did not do any good for me.
I also tried to set the framework search path to $(SRCROOT), but still same error.
I have two controllers with the import.
Linked frameworks and libraries
Added notificationCenter
TimeController
import WatchKit
import Foundation
import NotificationCenter error: "No such module 'NotificationCenter'"
SwipeController
import WatchKit
import Foundation
import NotificationCenter error: "No such module 'NotificationCenter'"
Any help would be much appreciated!
I agree with #David's comment, There are three targets for a single watchOS project.
You need to try these steps for each Target:
Select each target and go to -> Build Phases
Click on the right arrow. and click on the +
Finally, search for NotificationCenter and add the framework.
You need to try these steps for each target.
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.
I'm new to IOS programming and now experimenting with Swift. Everything was working fine until I tried to use facebook SDK. I added a new bridging header to import facebooksdk, and in my view controller I have
var fbl: FBLoginView = FBLoginView()
But this line gives me an error when deploying the app to my phone, and it crashes with app launch. The error code I get is:
dyld: Symbol not found: _OBJC_CLASS_$_NSHTTPCookieStorage
When using the simulator tho, everything works fine. What would be the reason for this error?
Did you import foundation?
import Foundation