I want to pass the variable TeamOne2 (right file) from the file which is created with UIKit to the file which is created with SwiftUI (left file). How can I do that? Struct.Variable does not work.
The reason is that I created my app with Storyboard and UIKit and want to use the Widget which comes with iOS 14. But I cannot rewrite my code to SwiftUI because I just want to use the Widget.
Xcode Screenshot
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 have just installed Xcode 11 and when I try to create new fresh project with the SwiftUI check mark selected it returns an error.
Not able to build and run successfully.
File 'ContentView.swift' is part of module 'SwiftUI'; ignoring import
ContentView.swift
Use of undeclared type 'View'
SceneDelegate.swift
Use of unresolved identifier 'UIHostingController'
I have tried removing all derived data and also set command-line tools to 11
Your project is named SwiftUI - please try using a different name.
Detailed Answer
Each project you create has a module with the same name as the project. So there are two SwifUI modules here:
The actual SwiftUI
The project itself
Xcode always takes the nearest definition as the default. So your SwiftUI is closer than the system's SwiftUI. But you are in the project's module already! So Xcode ignores the import.
A very common mistake is to name the project same as one of the using frameworks! (e.g. CoreData, SwiftUI, SceneKit, Metal)
Solution
As Matteo mentioned in his answer, Don't name your project same with another module. Change it to anything else.
Note that It could appear as an error too. For example, if you name your project CoreData and using SwiftUI, the error appears as Circular dependency error:
Circular dependency between modules 'CoreData' and 'SwiftUI'
Because Xcode gets confused about modules and can not detect what the real issue is.
How can we access our module's classes instead of the system's module?
Imagine you have a class named Section in a custom framework called MyProject and you imported it alongside the SwiftUI.
import SwiftUI
import MyProject
Section // <- This could be either SwiftUI's section or MyProject's Section
To make it clear for the compiler (and anyone else), you should call the module before the class name:
SwiftUI.Section // <- This returns the SwiftUI's Section
MyProject.Section // <- This returns the MyProject's Section
Try with different project name. With SwiftUI, it will always show compilation error. Just change the name and enjoy coding with SwiftUI
I'm using Xcode 7 and I'm trying to pass a value from the picker to another function when a button is pressed. Is it possible to get the value of the row that is currently selected in the picker? Or do I have to use the picker as the button somehow? I tried implementing didSelectRow but when I try setting it up, I get an error: Use of undeclared type 'UIPicker View.' I'm guess I have to retrieve the index of the source array somehow.
UIKit is not available for Apple Watch, and it is specially designed for iOS. Else you must use WatchKit.
In order to use user interface (UI) elements in your WatchKit App (watchOS1 or 2), you must use WatchKit (WK) elements instead, such as WKInterfaceButton.
So in order to have your app running successfully, replace UIPicker (which is an UIKit element) with WKInterfacePicker (which is a WatchKit element).
Note that WKInterfacePicker will only work in watchOS 2 (or later).
You are trying to use a UIKit class.
Use Watchkit classes with watch os 2:
WKInterfacePicker
Since Swift files are visible for each others, why my import within Appelegate is not visible for one of my controllers? I get an error there.
This is called Access level for Swift Modules. Default access level for Swift modules is internal, that is to that file itself.
Have a look here in Apple documentation Access level in Swift module
You need to import frameworks/modules in which ever class you are using.
Put import MessageUI at the top of the file where you declare your PBOUserViewController class (which I hope is contained in a separate .swift file than your AppDelegate).
I need to add a new viewController (new file h. and m.) using xCode 6 beta. After I go to File > New > File I do not get the option to add an "Object-C class" as I used to do in xCode 5. Doing that I normally got a new h. and m. file appearing in the Navigation area.
Any one can help pls?
PS - I am a beginner trying to learn basics of "storyboard" :)
thanks
If you choose objective-c File in your screenshot , you will get a .m file and a .h file written in Objective-C
If you choose Cocoa Touch File , you will have a option of Objective-C and Swift File which can be subclasses of other cocoa touch classes such as UIViewController or UITableViewCell.
IF you choose Swift File , you will get a single empty Swift file.
Since you are a beginner writing code with Objective-C , you'd better choose Objective-c File directly
Right click on the group (folder) in the navigation area in which you want to add the new viewController. Select New File, and then select Cocoa Touch Class.