Post not yet marked as solved
I want to make it like this
How to disable the button that open the side bar, I only need the content and the detail view. I don't need the sidebar view.
Below is my code
import SwiftUI
@available(iOS 16.0, *)
struct Screen: View {
@ObservedObject var userData = UserData()
@State private var isIntroShown = true
@State var Itema: Bool = false
@State private var showFoodDetail = false
@State var rb: Bool = false
@State var Setting: Bool = false
@State var Recipe: Bool = false
@Environment(\.defaultMinListRowHeight) var minRowHeight
@Environment(\.colorScheme) var colorScheme
@State private var searchText = ""
private let adaptiveColumns = [
GridItem(.adaptive(minimum: 170))
]
var columns = Array(repeating: GridItem(.flexible(), spacing: 10), count: 2)
var filteredRooms: [Room] {
if searchText.isEmpty {
return userData.rooms
} else {
return userData.rooms.filter { room in
let foodNames = room.food.map { $0.name.lowercased() }
return room.name.lowercased().contains(searchText.lowercased()) ||
foodNames.contains { $0.contains(searchText.lowercased()) }
}
}
}
@State private var columnVisibility = NavigationSplitViewVisibility.doubleColumn
var body: some View {
NavigationSplitView (columnVisibility: $columnVisibility){
} content: {
ScrollView{
GridView()
.padding(.horizontal)
.padding(.bottom, 20)
}.toolbar {
ToolbarItem(placement: .bottomBar){
Button(action:{self.Itema = true}) {
HStack {
Image(systemName: "plus.circle.fill").resizable().frame(width: 20, height: 20).foregroundColor(.white)
Text("New Item").foregroundColor(.white).bold()
}
}
.sheet(isPresented: self.$Itema){
NewItem(userData: self.userData)
}
}
ToolbarItem(placement: .bottomBar){
Button(action:{self.rb = true}) {
HStack {
Text("New Room").foregroundColor(.white)
}
}
.sheet(isPresented: self.$rb){
NewRoom(userData: self.userData)
}
}
ToolbarItem(placement: .navigationBarTrailing){
Button(action:{self.Setting = true}) {
HStack {
Image(systemName: "gear").foregroundColor(.white)
}
}
.sheet(isPresented: self.$Setting){
NavigationView {
NewItem( userData: userData)
.navigationBarItems(trailing:Button(action: {
self.Setting = false
}){
Text("Done")
}
)
}
}
}
}
.background(Color(red: 203/255, green: 237/255, blue: 207/255))
} detail: {
ZStack {
Text("")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(red: 220/255, green: 247/255, blue: 234/255))
}
.searchable(text: $searchText)
}
}
Hi!
I won the Swift Student Challenge this year, and I wonder when the awards arrive (so hyped for that!) as I see some unboxing videos and posts on the Internet.
Any clues ?
Thanks!
Post not yet marked as solved
Picker("Priority", selection: $selectedPriority)
( Cannot find '$selectedPriority' in scope)
Post not yet marked as solved
import SwiftUI
struct Splashscreenview: View {
@State private var isActive = false
@State private var size = 0.8
@State private var opacity = 0.5
var body: some View {
if isActive{
ContentView()
} else{
VStack {
VStack{
Image(systemName: "hare.fill")
.font(.system(size: 100))
.foregroundColor(.blue)
Text("Smartt Bank")
.font(Font.custom("Baskerville-Bold", size: 30))
.foregroundColor(.black.opacity(0.80))
}
.scaleEffect(size)
.opacity(opacity)
.onAppear{
withAnimation(.easeIn(duration: 1.2)){
self.size = 0.9
self.opacity = 1.0
}
}
}
.onAppear{
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.isActive = true
}
}
}
}
}
struct Splashscreenview_Previews: PreviewProvider {
static var previews: some View {
Splashscreenview()
}
}
Post not yet marked as solved
I am relatively new to coding and put together this countdown timer based on code available in various public forums. This countdown timer for my iPhone puts a timer on my screen, allows me to select the time counted down in minutes and seconds, then to start the timer and, if so desired, reset it.While such timers are readily available, I wanted to try and build one myself and learn swift in the process. The program builds and runs fine. However the latter section is intended to play a chime when the countdown timer reaches the 1/2 way point and then when it finishes. This is not working and I'm at a loss to get it to do so. I would appreciate it if someone would modify my code to make this work. Also, I don't know how to compile the program so that I can move it off my MacBook and onto my iPad and would appreciate guidance on that. The code follows: Thank you
//
// Content-ViewModel.swift
// Countdown Timer
//
//
//
import Foundation
import AVFoundation
extension ContentView { //contains the initial user interface
final class ViewModel: ObservableObject {
@Published var isActive = false
@Published var showingAlert = false
@Published var time: String = "1:00"
@Published var minutes: Float = 1.0 {
didSet {
self.time = "\(Int(minutes)):00"
}
}
private var initialTime = 0 // sets the var initialTime to 0
private var endDate = Date() // sets endDate to the current date
// this next func starts timer in minutes
func start(minutes: Float) { // this starts timer in minutes
self.initialTime = Int(minutes)
self.endDate = Date()
self.isActive = true // true means the timer is active
self.endDate = Calendar.current.date(byAdding: .minute, value: Int(minutes), to: endDate)!
}
// this next func updates the var minutes to original time
func reset() {
self.minutes = Float(initialTime)
self.isActive = false
self.time = "\(Int(minutes)):00"
}
// this next func calculates the elapsed time
func updateCountDown() {
guard isActive else { return }
let now = Date()
let diff = endDate.timeIntervalSince1970 - now.timeIntervalSince1970
if diff <= 0 { // means timer is at zero
self.isActive = false
self.time = "0:00"
self.showingAlert = true
return
// coud add code here to signify time is up
}
// This next code allows us to grab minutes and seconds from the calendar
let date = Date(timeIntervalSince1970: diff)
let calendar = Calendar.current
let minutes = calendar.component(.minute, from: date)
let seconds = calendar.component(.second, from: date)
self.minutes = Float(minutes)
self.time = String(format: "%d:%02d", minutes, seconds) // this creates the 2 digit display of minutes and seconds as a string
let halftime = minutes/2 // This shoud create a float variable equal to 1/2 run time
let chimesSoundEffect = "Chimes-sound-effect.mp3"
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
var player: AVAudioPlayer?
func playSound() {
guard let url = Bundle.main.url(forResource: "sound", withExtension: "mp3") else { return }
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
try AVAudioSession.sharedInstance().setActive(true)
player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)
guard let player = player else { return }
player.play()
}
catch let error {
print(error.localizedDescription)
}
let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
/* why doesn't the sound play when the halftime reached minutes/2 or when time reaches 0 */
if minutes == halftime {
playSound()
if minutes == 0 {
timer.invalidate()
playSound()
}
}
}
}
}
}
}
Post not yet marked as solved
I keep trying to insert imageLiteral
since my class uses an older version of Xcode the function ain't the same
so I was told to use #imageLiteral(
then the option of picking an image from assets work
I picked the image but as soon as I do
get this error msg
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
what going on and how can I fix it ?
Post not yet marked as solved
My while loop continues execution after reaching gemsCollected = 3 if I use OR logical operator (||) and stops execution if I use AND logical operator (&&).
IMHO it should be the other way around, right?
var gemsCollected = 0
var switchesToggled = 0
while gemsCollected < 3 || switchesToggled < 4 {
moveForward()
if gemsCollected < 3 && isOnGem {
collectGem()
gemsCollected = gemsCollected + 1
} else if switchesToggled < 4 && isOnClosedSwitch {
toggleSwitch()
switchesToggled = switchesToggled + 1
} else if isBlocked && !isBlockedRight {
turnRight()
} else if isBlocked && !isBlockedLeft {
turnLeft()
}
}
Hello, i am working on my project for the Swift Student Challenge and it came to my attention that the project must be built using Swift Playgrounds. I have run into an issue where I want to add multiple views to my project but it seems i am unable. How am i supposed to do this?
On the swift student challenge page it says "Your app playground must be built with and run on Swift Playgrounds 4.2.1 or later (requires iPadOS 16 or macOS 13) or Xcode 14 on macOS 13." Could I build it with Xcode in a swift.pm file but ask for it to be viewed on iPhone?
Post not yet marked as solved
I just read the announcement of the next Swift Student Challenge and one thing was not super clear to me. It says that applications will start in February and they'll run for 3 weeks. Is the application process just going to verify if I'm eligible to participate or will I already have to have a playground App ready submit with my application?
I was going through the eligibility criteria to participate and it said we had to be part of the Apple Developer Program. Does that mean that we have to pay in order to participate?
The Swift challenge page mentions playgrounds in both Swift Playgrounds and Xcode. Do I have to use an app playground or can I instead use an app project in Xcode? I feel more comfortable working with an Xcode project. Is it possible to convert my project to a .swiftpm file later?
Thanks
Post not yet marked as solved
could you please recommend sever choices of local database I can use or the ways to store data in app playground, like can I use realm or sqlite?
Post not yet marked as solved
I'm an entrepreneur working independently, and I've always had a passion for technology, especially within the Apple ecosystem. I'm interested in participating in the Swift Student Challenge at WWDC24. Although I'm no longer a student, would enrolling in any STEM program still make me eligible to apply?
Post not yet marked as solved
Can i create an app for Vision Pro for the swift student challenge ?
Post not yet marked as solved
Is it possible to receive loaner technology that I currently do not have access to for the Student Challenge? Such as an iPad and Apple Pencil.
Post not yet marked as solved
I don't really understand the exact meaning of "Build your app playground" on the Apple Swift Student Challenge home page. Does it mean to build a game app with a normal Xcode SwiftUI project?
Or is there a platform called "App Playground"?
So we cannot make an app that is not a game or an app that is not made with a platform called "App Playground" ?????????
I'm confused.
If you can use Japanese, it would be helpful to answer in Japanese.
Post not yet marked as solved
Hi,
this is my first Swift Student Challenge and I think I found a pretty interresting and innovative idea but It would require that the app has more than 3 min of content. What I can say without leaking the idea is that you can learn something in the playground and complete a quiz. One topic needs about 15-20 sec to read and 20 sec for the quiz. Than there is the possibility to go on to the next topic. But it is just the same ui and only different content and quiz questions. The playground has a few additional features that are also really interresting so I want to make sure that the judges of the challenge see them. Should I implement a small disclamer in the playground after looking at the first topic or mention this in the description when submitting the playground?
Thanks
Post not yet marked as solved
As a resident of Iran, I want to ensure that I can participate in the upcoming challenge when applications open in February 2024. Given the existing sanctions and political landscape, I'm uncertain about the potential limitations or implications.
I would appreciate insights from anyone who has knowledge about potential restrictions or implications due to sanctions that might affect participation for Iranian residents. Furthermore, if I were to excel and be selected as one of the top 50 distinguished winners, would I face barriers in being invited to Apple Park next summer due to these geopolitical factors?
Looking forward to your valuable insights and advice.
Post not yet marked as solved
Hello, I am new to ARkit.
I have tried to program to display a cube using ARkit and Realitykit in various articles using Xcode, but none of them worked. How can I display a 3Dcube in AR ?????
What I tried, roughly speaking, was to open the xcode iOS, AR progect file and run the program that is included by default.
If you can answer in Japanese, please do so.