I resolved my Timezone issue with the following code corrections, marked below the [Commented Code] ::
Best regards,
jim_k
import Foundation
import SwiftUI
import CoreLocation
import WeatherKit
struct TestForecastView: View {
//let dailyForecast: Forecast<DayWeather>
let dayWeatherList: [DayWeather]
let timezone: TimeZone
var body: some View {
Spacer()
.frame(height: 10)
Text("Sunrise Sunset")
.font(.system(size: 24, weight: .bold))
.foregroundStyle(.white)
Text("Ten Day Forecast")
.font(.system(size: 11, weight: .medium))
.foregroundStyle(.white)
Spacer()
.frame(height: 4)
VStack {
//ForEach(dailyForecast, id: \.date) { day in
ForEach(dayWeatherList, id: \.date) { dayWeatherItem in
LabeledContent {
HStack(spacing: 20) {
RoundedRectangle(cornerRadius: 10)
.fill(Color.orange.opacity(0.5))
.frame(width: 120, height: 5)
.padding(.leading, 2)
.padding(.trailing, 0)
VStack {
Image(systemName: "sunrise")
.font(.system(size: 24.0, weight: .bold))
.foregroundColor(.yellow)
//Text(day.sun.sunrise?.formatted(.dateTime.hour().minute()) ?? "?")
Text(dayWeatherItem.sun.sunrise?.localTime(for: timezone) ?? "?")
.font(.system(size: 10.0))
}
.frame(width: 50, height: 20)
VStack {
Image(systemName: "sunset")
.font(.system(size: 24.0, weight: .bold))
.foregroundColor(.yellow)
//Text(day.sun.sunset?.formatted(.dateTime.hour().minute()) ?? "?")
Text(dayWeatherItem.sun.sunset?.localTime(for: timezone) ?? "?"
.font(.system(size: 10.0))
}
.frame(width: 50, height: 20)
Spacer()
.frame(width: 2)
}
} label: {
//Text(day.date.localWeekDayShort(for: timezone))
Text(dayWeatherItem.date.localDate(for: timezone))
.frame(width: 80, alignment: .leading)
.padding(.leading, 30)
.padding(.trailing, 0)
}
.frame(width: 380, height: 52)
.background(RoundedRectangle(cornerRadius: 4).fill(LinearGradient(gradient: Gradient(colors: [Color(.systemBlue), Color(.black)]), startPoint: .topLeading, endPoint: .bottomTrailing)).stroke(.black, lineWidth: 6).multilineTextAlignment(.center))
.shadow(color: Color.white.opacity(0.1), radius: 4, x: -2, y: -2)
.shadow(color: Color.white.opacity(0.1), radius: 4, x: 2, y: 2)
}
}
.padding(.top, 20)
.padding(.bottom, 20)
.padding(.leading, 20)
.padding(.trailing, 20)
.contentMargins(.all, 4, for: .scrollContent)
.background(RoundedRectangle(cornerRadius: 10).fill(Color.black.opacity(0.0)).stroke(.gray, lineWidth: 4))
} // End of [var body: some View]
} // End of [struct TestForecastView: View]
The revised Paris Sunrise and Sunset displays the correct times :
As a side note, changing the [sun.sunrise?] to [moon.moonrise?] and [sun.sunset?] to [moon.moonset?] affects the Moon Phase too ... :]
Paris Sunrise Sunset ::
Paris Moonrise Moonset ::
Post
Replies
Boosts
Views
Activity
Hello ... :]
Thank you for your quick reply ...
For the moment, and forgive my ignorance, but I do not understand how to engage your suggested code,
var dateFormat -> Date.FormatStyle {
let formatStyle = Date.FormatStyle.dateTime.hour().minute()
formatStyle.timeZone = self.timezone
return formatStyle
}
nor as to where I should place the code in the application to allow
Text(day.sun.sunrise?.formatted(dateFormat) ?? "?")
to be exercised ... ?
Placing the raw code anywhere in my application simply generates several warnings, and or error messages. My subsequent question happens to be, should I encase this code in an enum, struct, or class, and then again where ... ?
I do recognize Quinn's code example, where Quinn's function code illustrates a timezone time in the user's location, and then produces the equivalent correct time in the selected remote location, using the remote location's timezone identifier, such as "Europe/Paris".
My application understands the desired requested remote location timezone, where the application wants to update the selected location's time, relative to the selected location's timezone, but for the moment my application does not correctly illustrate the selected location's sunrise or sunset time, as retrieved from .
Addressing my newly discovered and very limited SwiftUI knowledge, I know I cannot introduce a function into a View to generate the desired result.
I do appreciate your initial quick reply and suggestion, but I still struggle to understand the solution, and again thank you.
Best regards,
jim_k
My error calling ForEach a function ... :]
ForEach is really a Struct implementing a View protocol ... :]
Best regards,
jim_k
Issue resolved ... :]
I did not properly update my Xcode > Settings > Accounts > Apple ID after changing my Apple ID password ...
Frustratingly forgot this step ... :]
Best regards,
jim_k
Another update to this issue ... :]
I transferred the PList file application, which creates an initial PList file for my application, to another Mac with 48Gb of RAM, and the file indexed properly without issue. So, I confirmed my Mac Mini with 16Gb of RAM cannot index my file nor build the required PList file. Unfortunately, I must look for another Mac with more RAM to be able to proceed in the future. Not what I wanted, but what I must do ... :]
I guess I shall consider this issue as closed ...
Best regards,
jim_k
The application [ALERT FILES] are here:
// MARK: - [showLocationAutorizationDeniedAlert] (and disable code)
func showLocationAuthorizationDeniedAlert() {
/// Store the [suppression state] in [userDefaults] to [NOT ASK THIS QUESTION AGAIN]
let userDefaultsKey = "dontShowLocationAuthorizationDeniedAlert"
/// Check to see whether the [User] answered the question to not see the following code again
if UserDefaults.standard.bool(forKey: userDefaultsKey) == false {
let alert = NSAlert()
alert.messageText = "Location Authorization Denied"
alert.informativeText = "Parental Controls ... ?"
alert.alertStyle = .critical
alert.showsSuppressionButton = true
alert.suppressionButton?.title = "Do not show this alert again!"
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: "Cancel")
//alert.addButton(withTitle: "Use default values")
let response = alert.runModal()
/// Turn off the [ALERT] with [User Default Preferences] setting.
if let supress = alert.suppressionButton {
let state = supress.state
switch state {
case NSControl.StateValue.on:
UserDefaults.standard.set(true, forKey: userDefaultsKey)
default: break
} // End of [switch state]
} // <=== End of [if let supress = alert.suppressionButton]
if response == .alertFirstButtonReturn {
print("\n alertFirstButtonReturn (OK Button)")
} else {
print("Use default values")
} // End of [if response == .alertFirstButtonReturn]
} // <=== End of [if UserDefaults.standard.bool(forKey: userDefaultsKey) == false]
/// Bail and [Return] gracefully
return
} // <=== End of [func showLocationAuthorizationDeniedAlert()]
// MARK: - [showLocationAutorizationRestrictedAlert] (and disable code)
func showLocationAuthorizationRestrictedAlert() {
/// Store the [suppression state] in [userDefaults] to [NOT ASK THIS QUESTION AGAIN]
let userDefaultsKey = "dontShowLocationAuthorizationRestrictedAlert"
/// Check to see whether the [User] answered the question to not see the following code again
if UserDefaults.standard.bool(forKey: userDefaultsKey) == false {
let alert = NSAlert()
alert.messageText = "Location Authorization Restricted"
alert.informativeText = "Check Parental Control"
alert.alertStyle = .critical
alert.showsSuppressionButton = true
alert.suppressionButton?.title = "Do not show this alert again!"
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: "Cancel")
//alert.addButton(withTitle: "Use default values")
let response = alert.runModal()
/// Turn off the [ALERT] with [User Default Preferences] setting.
if let supress = alert.suppressionButton {
let state = supress.state
switch state {
case NSControl.StateValue.on:
UserDefaults.standard.set(true, forKey: userDefaultsKey)
default: break
} // End of [switch state]
} // <=== End of [if let supress = alert.suppressionButton]
if response == .alertFirstButtonReturn {
print("\n alertFirstButtonReturn (OK Button)")
} else {
print("Use default values")
} // End of [if response == .alertFirstButtonReturn]
} // <=== End of [if UserDefaults.standard.bool(forKey: userDefaultsKey) == false]
/// Bail and [Return] gracefully
return
} // <=== End of [func showLocationAuthorizationRestrictedAlert()]
After scouring the internet to see whether I could discover a solution with better key words, such as [Binding and NSView], I noticed a quote posted more than five years ago, stating the following:
Since KVC and KVO are built on the Objective-C runtime, and since Cocoa Bindings is built on top of KVC and KVO, any properties you want to use Cocoa Bindings with need to be exposed to Objective-C. At the bare minimum, that means adding @objc to the declaration.
So, my original [Date] property was set to: var currentTime: Date?
I changed the [Date] property to: @objc var currentTime: Date?
The application did not crash, but did not show the [Clock and the Calendar] updating.
Further reading stated: However, if the property can be changed at runtime, there's an additional hurdle you need to jump through; you need to make sure that the KVO notifications will fire whenever the property's setter is called. Apple's implementation of KVO will use Objective-C magic to automatically add the needed notifications to the setter, but since Swift property accesses aren't guaranteed to go through the Objective-C runtime, you need to add the dynamic keyword for this to work reliably.
I changed the [Date] property to: @objc dynamic var currentTime: Date?
The application did not crash, and the [Clock and the Calendar] updated properly.
Perfect, I now have that knowledge ... :]
Again, thank you for your time ...
Best regards,
jim_k
London:
Sydney:
It is my understanding, where I am unfortunately guessing here about your card types, but if your cards happen to be a VISA or MASTERCARD gift card, where the cards have an assigned value, or where you can add funds to the gift credit card, these credit card types do not contain the user's credit history to check against. For example in my home country, you cannot use a gift credit card to rent a vehicle, therefore you must use a credit card issued by a banking institution, where a credit history or credit card security check becomes available to the seller before a transaction can be engaged.
Shopping online with an assigned value gift credit card is different. Sellers just take your gift credit card funds.
Using the car rental scenario as an example, if you returned the vehicle to the rental agency after closing hours, where the car rental agency believes you returned the vehicle in a perceived damaged condition, the car rental agency would attempt to use your banking institution credit card to apply incremental funds against your credit card. A car rental company would not be able to assign incremental funds against a gift credit card. Therefore the car rental agency refuses to accept the gift credit card type.
Unfortunately, I do not know the full history behind this issue with gift credit cards nor your credit card types, but the user's missing gift credit card history can be an issue in many locations, and at many institutions, which sell services or products.
Best regards,
jim_k
An update to this issue ... :]
The indexing issue within my PList creation application still exists when my file is very large, where the total dictionaries exceed the ability of the application to process them properly into a single PList file. The application's compilation causes the Mac Mini M1 (16GB) to usurp all the RAM, causing the Mac Mini to crash, especially when another application, such as Safari is active, Xcode is obviously active, and with the OS operating requirements too. I cannot acknowledge the "Force Quit" modal window to deactivate any application. The Mac is completely unresponsive. Therefore I must force the Mac Mini to restart by holding the power button for a few seconds. The issue existed with Xcode 12.5.1, Xcode 13.4.1, and still exists within Xcode 14.1.
The application presents a warning message with a large file after a minute or two, while indexing, which states "An internal error occurred. Source editor functionality is limited. Attempting to restore."
The warning message does not appear when the total dictionaries in the PList are few, and the Mac Mini does not crash. This total is difficult to determine what the actual passing grade total might be without empirical testing, but for the moment it happens to be less than one half of the current total dictionaries the application tries to submit into the PList. My current PList array of dictionaries total happens to be 8060 records.
Still curious as to whether Xcode is limited to the available RAM on my Mac Mini, while processing a file, or could my application be generating a memory leak ... ?
Best regards,
jim_k
Mark ... :]
Thank you for the information, but the [copy_read_only] message is still periodic within my current application, and newer test applications. I do now know how this warning affects any application, just yet, but I am sure I shall find out one day. I am uncertain about removing the [sandbox]. Again, thank you for your response.
Best regards,
jim_k
The code to illustrate better:
/// Keep the cellView.textField [AS THE ORIGINAL (IB) VALUES] when each [GREATER THAN] or [LESS THAN] conditional is met:
cellView.textField?.textColor = NSColor.white
/// Keep the cell font size at [11].
let fontSize = 11
cellView.textField?.font = NSFont.systemFont(ofSize: CGFloat(fontSize))
// Compared to the changed cellView.textField:
// Change the [TEXT FIELD COLOUR TO YELLOW] when the [cellView.textField IS EQUAL TO THE COMMON NUMBER] condition is met:
cellView.textField?.textColor = NSColor.systemYellow
// Change the (TEXTFIELD FONT SIZE) with CGFloat.
let fontSize = 12
cellView.textField?.font = NSFont.boldSystemFont(ofSize: CGFloat(fontSize))
As fate would have it, I managed to solve the issue a few hours after I posted the question :]
I changed my Struct code in the applications (Constants File) to new base values (I probably did not need to make the change.):
struct TheRequestedNumbersToFind {
static var theFirstNumber = 0 // <=== Previous value = (10)
static let theSecondNumber = 0 // <=== Previous value = (13)
static let theThirdNumber = 0 // <=== Previous value = (15)
static let theFourthNumber = 0 // <=== Previous value = (22)
static let theFifthNumber = 0 // <=== Previous value = (29)
static let theSixthNumber = 0 // <=== Previous value = (46)
static let theSeventhNumber = 0 // <=== Previous value = (3)
}
I discovered I could change the (Struct Static Variable) to equal the received variable in the applications (Notification):
/// Identify the received (Notification) information for the tableView textField.
let theTransferredFirstNumberReceived = notification.object
if let theFirstNumberReceived = (theTransferredFirstNumberReceived as AnyObject) as? Int32 {
/// Note: The (USER) entered the number (10).
print("THE FIRST NUMBER RECEIVED :: \(Int32(theFirstNumberReceived)) \n")
// Prints: THE FIRST NUMBER RECEIVED = 10
/// ASSIGN THE REQUESTED NUMBER TO THE (STRUCT VARIABLE) TO CHANGE THE (CONSTANTS FILE STRUCT VARIABLE).
/// The "Int(theFirstNumberReceived)" must remain as "Int".
TheRequestedNumbersToFind.theFirstNumber = Int(theFirstNumberReceived)
print("THE REVISED FIRST STRUCT NUMBER RECEIVED :: \(Int32(TheRequestedNumbersToFind.theFirstNumber)) \n")
// Prints :
// THE REVISED FIRST STRUCT NUMBER RECEIVED :: 10
}
I modified the tableView code for the (first column) to be :
/// Identify the (STRUCT CONSTANT) for the (FIRST NUMBER).
/// This (STRUCT CONSTANT) works because the constant is recognized
/// Change the (STRUCT STATIC VARIABLE) to (EQUAL THE REQUESTED NUMBER).
let someFirstNumber = TheRequestedNumbersToFind.theFirstNumber
print("First Number Struct Variable Received :: \(someFirstNumber) \n")
// Prints :
// First Number Struct Variable Received :: 10
This change also removed the incremental errors with the static number (10), which allowed a few numbers not equal to (10), to be erroneously displayed as equal to (10).
I can now close this issue ... :]
Best regards,
jim_k
Hello deeje,
Thank you with your quick reply and suggestion ... :]
Unfortunately, the error "Value of type "NSManagedObject" has no member "calendarDate" still persists with the suggested change, complete with me deleting the original "Derived Data," cleaning, and rebuilding the application.
Again, thank you with your suggestion ...
jim_k
Core Data and Random NULL Values Solution (210619)
The application code caused NULL values to be saved into stored objects as follows:
The application initializes the mutable array “Items.”
The textFields identify the input values to save.
Four constants are identified, such as managedObjectContext, entity, registerApplicationNumberObject, and component.
The constant “registerApplicationNumberObject” receives textField input values with “setValue.”
The constant “component” does NOT receive values with “setValue.”
The constant “component” inherits missing values.
The mutable array “items” is appended to the stored objects with the “component” missing values.
Core Data and SQLite identify the missing values with NULL.
The application does not exhibit NULL values when the following code is disabled:
“//let component = NSManagedObject(entity: entity!, insertInto: managedObjectContext)”
“//items.append (component)”
As a side note, Xcode indicated that “entity: entity” should be addressed as “entity: entity!”
Now I can store, fetch, find, and delete values from Core Data.
jim_k
Gentlemen, thank you for the updated information ... :]
It was fun trying to navigate with my first attempt, but successful.
I shall generate more questions about Swift in the future, once I understand how to ask the right question, since Swift is new to me, but not coding. Again, thank you.
Best regards,
jim k