Posts

Post marked as solved
5 Replies
5.2k Views
I am trying to get myself going with swiftUI. I was playing with the code below and trying to get the print() to work to see some variables during runtime in the preview window. Unfortunately it won't run once I add the print(), I get an Expected Declaration flag. Any info on using print() would be great as I have spent a few hours wondering around Google looking for answers with no luck so far.import SwiftUI struct ContentView : View { @State var username: String = "" let word1 = "Username" let word2 = "Password" print() var body: some View { VStack(alignment: .leading) { Text("Login") .font(.title) .multilineTextAlignment(.center) .lineLimit(nil) Text("Please") .font(.subheadline) HStack(alignment: .center, spacing: 10) { Text("Username: ") TextField($username, placeholder: Text("type something here...")) .textFieldStyle(.roundedBorder) } HStack(alignment: .center, spacing: 10) { Text("Password: ") TextField($username, placeholder: Text("type something here...")) .textFieldStyle(.roundedBorder) } }.padding() } }
Posted
by SV3021.
Last updated
.
Post not yet marked as solved
4 Replies
1.4k Views
I am trying to understand why I get "Use of unresolved identifier 'db'" below. The connection works but I can't see db outside the do{}. Can someone please explain this and how to correct it? I think it is the scope of the variable db?func openTheDB2() -> String { do { let db = try Connection("/Users/benniewarren/Desktop/database.sqlite") } catch { print("Failure2") } let users = Table("users") try db.run(users.create { t in // CREATE TABLE "users" ( t.column(id, primaryKey: true) // "id" INTEGER PRIMARY KEY NOT NULL, t.column(email, unique: true) // "email" TEXT UNIQUE NOT NULL, t.column(name) // "name" TEXT }) // ) return "Ok2" }
Posted
by SV3021.
Last updated
.
Post marked as solved
13 Replies
1.8k Views
I need to build an array that has 22 columns in it and 6000 rows. The bottleneck here is it takes about 500 seconds to build it. I have tracked it to this directly. I read a file to get this data. Does anyone have any ideas on speeding this up? More information can be provided on request.ccDataStr_StrArr.append(itemHolder ?? [])
Posted
by SV3021.
Last updated
.
Post marked as solved
6 Replies
696 Views
I have built my first struct and it does what I wanted it to but I am sure this is not the most optimized way to add data to it. If anyone has any opimization ideas as I will be adding more data rows and then eventually move to a db. I am studying this stuff as fast as I can and I am finding it fun and challenging.struct CCdata { var id: Int? var org_nm: String? var org_cd: String? var tms: String? var tec: String? var serno: String? var mcn: String? var jcn: String? var rcvd_dt: Date? var cmp_dt: Date? } var firstTry:[CCdata] = [CCdata]() var firstTrySingle = CCdata() print(firstTry.count) var secondTry = "45 HSM73 Q30 MH-60R AHZS 167043 1V4YSQU Q30113239 4/23/2018 0:00:00 5/2/2018 0:00:00" let secondTry_StrArr = secondTry.components(separatedBy: " ") firstTrySingle.id = Int(secondTry_StrArr[0]) firstTrySingle.org_nm = secondTry_StrArr[1] firstTrySingle.org_cd = secondTry_StrArr[2] firstTrySingle.tms = secondTry_StrArr[3] firstTrySingle.tec = secondTry_StrArr[4] firstTrySingle.serno = secondTry_StrArr[5] firstTrySingle.mcn = secondTry_StrArr[6] firstTrySingle.jcn = secondTry_StrArr[7] let formatter = DateFormatter() formatter.dateFormat = "MM/dd/yyyy HH:mm:ss" firstTrySingle.rcvd_dt = formatter.date(from: secondTry_StrArr[8]) firstTrySingle.cmp_dt = formatter.date(from: secondTry_StrArr[9]) firstTry.append(firstTrySingle) print(firstTry.count) print(firstTry[0].org_nm ?? "Bad Data") firstTry[0].org_nm = "HSM72" print(firstTry[0].rcvd_dt ?? 2999-09-09) print(firstTry[0].cmp_dt ?? 2999-09-09) print(firstTry[0].org_nm ?? "Bad Data") switch firstTry[0].rcvd_dt?.compare(firstTry[0].cmp_dt ?? Date()) { case .orderedAscending : print("rcvd_dt is earlier than cmp_dt") case .orderedDescending : print("rcvd_dt is later than cmp_dt") case .orderedSame : print("The two dates are the same") default : print("No answer") } print(firstTry[0])
Posted
by SV3021.
Last updated
.
Post marked as solved
3 Replies
1.8k Views
I have tried a lot of things with no luck on getting this working. The two date vars won't take my date. I think I need to do something with dateformatter but haven't found the right way yet. Can anyone shed some light on this?struct CCdata { var id: Int var org_nm: String var org_cd: String var tms: String var tec: String var serno: String var mcn: String var jcn: String var rcvd_dt: Date var cmp_dt: Date } var firstTry = CCdata(id: 45, org_nm: "HSM73", org_cd: "Q30", tms: "MH-60R", tec: "AHZS", serno: "167043", mcn: "1V4YSQU", jcn: "Q30113239", rcvd_dt: 4/23/2018 0:00:00, cmp_dt: 5/2/2018 0:00:00)
Posted
by SV3021.
Last updated
.
Post marked as solved
1 Replies
7.3k Views
I put the file in my project. If I don't comment out line 17 nothing compiles. I have tried a few different things but with no luck yet. Any pointers pardon the pun, would be great.import SwiftUI import Foundation // Determine the file name let filename = "OOMA CC Temp.txt" // Read the contents of the specified file let contents = try! String(contentsOfFile: filename) // Split the file into separate lines let lines = contents.split(separator:"\n") // Iterate over each line and print the line func printLine()->String { // var oneLine: String = "Hello to all" var myCounter: Int = 0 myCounter = lines.count myCounter += myCounter + 1 let str1 = String(myCounter) return str1 } struct CCdata : View { var body: some View { Text(printLine()) } }
Posted
by SV3021.
Last updated
.
Post marked as solved
3 Replies
718 Views
I am having trouble wrapping my head around variables. I have read a ton of tutorials but it all seems a little big right now. I made the var myColor and that works just fine. Then when I add line 9 to change the myColor it fails to compile and of course the callout is not much help. I have tried using self.myColor and $myColor and neither seems to work. I think if I could grasp this it would open up a lot of my learning.import SwiftUI struct FigureThisOut : View { @State var myColor = Color.green var body: some View { myColor = Color.red Text("reloadCount2").color(myColor) } } #if DEBUG struct FigureThisOut_Previews : PreviewProvider { static var previews: some View { FigureThisOut() } } #endif
Posted
by SV3021.
Last updated
.
Post marked as solved
2 Replies
490 Views
I am looking for a way to just change the color in an if statement. Is that possible or is the code below the best or the only way to do this? Section(header: Text("Detail Sections Verification")) { if order.specialRequestEnabled { Text("Information Verified") .color(.green) .frame(minWidth: 0, maxWidth: .infinity, alignment: .center) } else { Text("Information Not Verified") .color(.red) .frame(minWidth: 0, maxWidth: .infinity, alignment: .center) } Toggle(isOn: $order.specialRequestEnabled) { Text("Set if all data is verified") } }
Posted
by SV3021.
Last updated
.