I have an issue where the emulator behaves differently then the actual iPhone when running my Xcode app, (it has nothing to do with email). What could be the issue?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have an alert that I want to go to a specific site but after the user presses okay and for it to show only once. I can't figure out the part where the site is delayed because the user did not press okay.
var justOnce: Bool = true
@IBAction func playStats(_ sender: Any) {
//show alert only once
if justOnce {
let alert = UIAlertController(title: "Stats Important", message: "You can copy and paste the name here when you see the searchbar", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
justOnce = false
gotoSite()
}
}
So I have an app and it relies on Core Data to save and load favourite players. The issue I have is the data being loaded in my viewwillappear method is the max number of all the players regardless whether or not I save the data. When I access my favouritesVC I can't go back and add more players because they take up the max amount of storage. I need my app to retrieve the favourites I saved not all the players.
class FavouritesVC {
//this is a button I save my favourite players
//the print statements are accurate
@IBAction func save(_ sender: UIBarButtonItem) {
let entity = NSEntityDescription.entity(forEntityName: "CurrentPlayers", in: context)!
let saveFav = CurrentPlayers(entity: entity, insertInto: context)
for o in prefArr {
saveFav.yahooName = o.yahooName
saveFav.team = o.team
saveFav.position = o.position
saveFav.photoUrl = o.photoUrl
do {
try context.save()
print("These are my saved objects: \(saveFav)")
print("how many saved objects: \(prefArr.count)")
} catch {
print("error is: \(error)")
}
}
}
}
//what I use to load the data
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let fetchRequest = NSFetchRequest<CurrentPlayers>(entityName: "CurrentPlayers")
do {
prefArr = try context.fetch(fetchRequest)
for p in prefArr {
if p.yahooName == "Jordan Gross" {
print("Jordan added")
}
}
print("There are this many saved favourites \(prefArr.count)")
} catch let error {
print("Could not fetch. \(error)")
}
}
}
//core data class file
import Foundation
import CoreData
enum DecoderConfigurationError: Error {
case missingManagedObjectContext
}
extension CodingUserInfoKey {
static let managedObjectContext = CodingUserInfoKey(rawValue: "managedObjectContext")!
}
@objc(CurrentPlayers)
public class CurrentPlayers: NSManagedObject, Decodable {
enum CodingKeys: String, CodingKey {
case photoUrl = "PhotoUrl"
case firstName = "FirstName"
case lastName = "LastName"
case position = "Position"
case team = "Team"
case yahooName = "YahooName"
case status = "Status"
case jerseyNumber = "Jersey"
}
public static var managedObjectContext: NSManagedObjectContext?
required public convenience init(from decoder: Decoder) throws {
guard let context = decoder.userInfo[.managedObjectContext] as? NSManagedObjectContext else {
throw DecoderConfigurationError.missingManagedObjectContext
}
self.init(context: context)
//...
let values = try decoder.container(keyedBy: CodingKeys.self)
photoUrl = try values.decode(String.self, forKey: CodingKeys.photoUrl)
firstName = try values.decode(String.self, forKey: CodingKeys.firstName)
lastName = try values.decode(String.self, forKey: CodingKeys.lastName)
position = try values.decode(String.self, forKey: CodingKeys.position)
team = try values.decode(String.self, forKey: CodingKeys.team)
yahooName = try values.decodeIfPresent(String.self, forKey: CodingKeys.yahooName)
status = try values.decode(String.self, forKey: CodingKeys.status)
jerseyNumber = try values.decodeIfPresent(Int64.self, forKey: CodingKeys.jerseyNumber) ?? 0
}
}
I have an issue with my SearchBar with scope working on my emulator but not on my iPhone properly. When I type the name of a specific player the iPhone shows me duplicates of the player but my emulator does not. What causes this issue? (I made the scoped bar programmatically but I don't see how that could cause an issue).
I am trying to get previews to work with swiftUI and my issue is
Library not loaded: /System/Library/Frameworks/AddressBook.framework/AddressBook
and it just loops my previews continually. I am using an older version of Xcode it is 13.1 but it is one of the latest ones my os supports. What can I do to fix this issue?