Hello,
For the past month, I've been learning to use UIKit on Xcode to prepare for the Swift Student Challenge. However, I can't find a way to use my newly acquired skills in App Playgrounds. Do they strictly require SwiftUI? Is there a way to use UIKit and Storyboards?
Post
Replies
Boosts
Views
Activity
Hello,
My App Playground uses a text file to work properly. I've had no issues running the app on Simulator, but it fails to find the file when being run on my physical iPhone. Has anyone had the same issue? Any idea what the problem is?
Thanks for the help!
Hello,
Very recently, the following code has automatically appeared at the bottom of three of my SwiftUI View files:
@available(iOS 17.0, macOS 14.0, tvOS 17.0, visionOS 1.0, watchOS 10.0, *)
struct $s10Accent_Ace33_0BADA584A03144EFDAB57154E6FD3FBALl7PreviewfMf_15PreviewRegistryfMu_: DeveloperToolsSupport.PreviewRegistry {
static let fileID: String = "Accent_Ace/HistoryView.swift"
static let line: Int = 47
static let column: Int = 1
static func makePreview() throws -> DeveloperToolsSupport.Preview {
DeveloperToolsSupport.Preview {
let randomWord1 = FetchWord.getRandomWord()
let randomWord2 = FetchWord.getRandomWord()
@State var randomWords = [Word(word: randomWord1.0, IPA: randomWord1.1, lineNumber: randomWord1.2), Word(word: randomWord2.0, IPA: randomWord2.1, lineNumber: randomWord2.2)]
HistoryView(words: $randomWords)
}
}
}
This is from one of my files but it's very similar in the other two. It seems to have something to do with my previews.
The problem is that this code generates an error: Ambiguous use of 'init(_:traits:body:)'. My previews worked just fine before the auto-generated code appeared, so I tried deleting it. However, it automatically comes back no matter how many times I get rid of it. It's preventing me from building my App Playground, so I can't run the app or even see the previews. Does anyone know how to get rid of it or fix the error?
Thanks for the help!
Hello,
The appearance of one of my buttons is not updating after being tapped. I have had no trouble doing the exact same thing in my other views, but here it simply doesn't work. The "heart" button will keep its original appearance (in this case an unfilled heart) no matter what, despite my print statements indicating that the value has changed. The other actions performed when tapping the heart work perfectly. I've been at it for hours.
Any help would be appreciated. Thanks!
import SwiftUI
struct SearchView: View {
@State private var searchText = ""
@StateObject var save = SaveWords()
@State var heart: String?
@State var disappear = false
@State var done = true
var body: some View {
NavigationView {
VStack {
if !disappear {
SearchBarView(text: $searchText)
Spacer()
}
if searchText != "" {
List(.constant(Array(FetchWord.getWordFromStart(start: searchText)).prefix(10).map {Word(word: $0.1)})) { suggestion in
NavigationLink(destination: suggestion.IPA.wrappedValue == "error" ? AnyView(EmptyView()) : AnyView(PracticeView(wordSheet: suggestion)
.onAppear {
disappear = true
if done {
SaveWords.file = "Favorites"
DispatchQueue.main.async {
Task {
try? await save.load()
heart = save.words.contains(suggestion.wrappedValue) ? ".fill" : ""
}
}
}
}
.onDisappear {
disappear = false
Task {
SaveWords.file = "History"
try? await save.load()
if save.words.first != suggestion.wrappedValue {
save.words.insert(suggestion.wrappedValue, at: 0)
try? await save.save()
}
}
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
SaveWords.file = "Favorites"
done = false
if heart == "" {
heart = ".fill"
DispatchQueue.main.async {
Task {
try? await save.load()
if !save.words.contains(suggestion.wrappedValue) {
save.words.insert(suggestion.wrappedValue, at: 0)
try? await save.save()
}
}
}
} else {
heart = ""
DispatchQueue.main.async {
Task {
try? await save.load()
try? await save.delete(wordToDelete: suggestion.wrappedValue)
try? await save.save()
}
}
}
done = true
}, label: {
Image(systemName: "heart" + (heart ?? ""))
})
}
})
) {
if suggestion.IPA.wrappedValue != "error" {
CardView(wordSheet: suggestion)
}
}
}
}
}
Spacer()
}
}
}
#Preview {
SearchView()
}
Hello,
Does anyone know how to restrict my app playground to run on iPhones only (not even iPads) and to always be presented in portrait mode? I'm using Xcode.
Thanks for any help!
Hello,
For the Swift Student Challenge, do I need to worry about submitting a clean source code with comments? Or does Apple judge submissions solely based on their user experience with the app?
Thanks!
Hello,
I am new to app development. I am trying to make an iMessage app. I created it and then added a SwiftUI view. It builds just fine and the view is visible on the storyboard, but the app is not present in iMessage on Simulator or on an actual device. What's wrong?
Thanks for any help.
import UIKit
import Messages
import SwiftUI
class MessagesViewController: MSMessagesAppViewController {
var hostingController: UIHostingController<CalendarView>?
override func viewDidLoad() {
super.viewDidLoad()
}
override func willBecomeActive(with conversation: MSConversation) {
super.willBecomeActive(with: conversation)
let swiftUIView = CalendarView()
let hostingController = UIHostingController(rootView: swiftUIView)
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), hostingController.view.topAnchor.constraint(equalTo: view.topAnchor), hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)])
hostingController.didMove(toParent: self)
self.hostingController = hostingController
}
override func didResignActive(with conversation: MSConversation) {}
override func didReceive(_ message: MSMessage, conversation: MSConversation) {}
override func didStartSending(_ message: MSMessage, conversation: MSConversation) {}
override func didCancelSending(_ message: MSMessage, conversation: MSConversation) {}
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {}
override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {}
}