What is the current state of jailbreaking? If you’re lucky, you’ll be able to crack your devices and continue to run your custom apps. With more than 1000 of them, it is probably worthwhile to employ a “security researcher” to help you with this. If that doesn’t work, sell the devices on eBay and replace them with Android - you may even make a profit doing that, though your software redevelopment costs could wipe that out.
It sounds like your business might be large enough to afford a reasonable lawyer, unlike most of those who get terminated without a reason. But of course Apple can afford a better one, so there still isn’t much hope.
Post
Replies
Boosts
Views
Activity
How/where do I declare global variables in the same file as "main" location?
Variables declared outside of any class, struct or function, i.e. at the zero-indentation level, are ”global”.
But what, exactly, do you mean by “main”? The Swift equivalent of the “main function” in the C sense is partly explain by eoonline above, but I don’t think that’s really what you mean. I think you mean something more like “constructor”, or similar.
On a large project, there will be multiple associated files that contain related functions. How do make calls to these functions from the "main" file?
Do you understand concepts like classes, objects and methods?
In C# for example, I can't simply call the function name, it has to be associated the "class" that the function is stored in first.
OK, so you have heard of classes…
Do I have to declare these related functions in the "main" form ahead of usage?
Generally, the Swift compiler finds declarations in other files without any extra work on your part (unlike C).
But looking at your example, I think what you may be doing is creating instances of classes in order to call their methods. In that case, the answer is “yes, of course you need to create objects before you can call their (non-static) methods”.
Eoonline wrote:
Judging from your question, the problem might be less about the Swift language, itself (which I wager that you will quickly grok) than the SwiftUI framework
I agree that you should absolutely learn non-UI Swift first, and then learn SwiftUI, taking care to understand that its body declarative parts are subtly different from other Swift code.
I used "print(hi)" just to ensure that my function call was being called.
Crucially, the calls 1 and 2 are not within a function, they’re within a SwiftUI body declaration.
I’m not sure I agree with eoonline that you will “quickly grok” Swift, though. I have the impression that your first language was probably something without classes - maybe Fortran or Pascal - and you continue to think of everything in terms of those semantics.
Topic:
Programming Languages
SubTopic:
Swift
suppose If there is a case where it fails due to insufficient memory.
To address that point specifically:
(On iOS), When memory is low, apps get memory warnings and should free resources. If that’s not enough, suspended apps will be terminated.
The only situation where you will really run out of memory is if you ask for a ridiculously large allocation, and that indicates a bug in your program.
(The same is also true on other platforms, except embedded systems without virtual memory. Unless you run out of virtual address space, memory allocations will always succeed even when physical RAM is exhausted; the problem is dealt with by other mechanisms, such as Linux’s “OOM Killer”. Personally, in my C++ code I assume that memory allocation cannot fail.)
More generally: if the API has some way of reporting an error, try to handle it; if it doesn’t, assume that it cannot fail for valid parameters.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags:
I can’t really answer your questions, because the don’t make much sense. It sounds to me as if you have tried to learn Swift and SwiftUI by reading random bits of code and trying to work out what they mean by looking for connections with other languages. Sorry, that’s not going to work.
Now in the SwiftUI project, I tried this...
What do you actually want to happen? Presumably you want it to print “hi” at some point. When do you want it to do that?
If you want it to print “hi” when a ContentView struct is created, put it in an init method.
Topic:
Programming Languages
SubTopic:
Swift
I think you'd need to schedule a snapshot refresh if the WatchConnectivity background task updates your UI
Or maybe not, according to the docs at https://developer.apple.com/documentation/watchkit/preparing-to-take-your-watchos-app-s-snapshot
If your app uses the SwiftUI BackgroundTask tasks, the system automatically detects any changes to the user interface and schedules the snapshot task.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
Many thanks! Here is the skeleton of what I have; any comments? In particular, should I be doing anything in the .backgroundTask(.watchConnectivity)?
import Foundation;
import SwiftUI;
import WatchConnectivity;
@Observable
class Stats
{
var data: [String: Any] = [:];
};
struct StatsView: View
{
@Environment(Stats.self) private var stats;
var body: some View {
VStack {
Text(stats.data.description)
}
}
};
class SessionDelegate: NSObject, WCSessionDelegate
{
private var stats: Stats;
init(stats: Stats)
{
self.stats = stats;
}
func session(_ session: WCSession,
activationDidCompleteWith activationState: WCSessionActivationState,
error: (any Error)?) {
// TODO check state, error, etc.
stats.data = session.receivedApplicationContext;
}
func session(_ session: WCSession,
didReceiveApplicationContext application_context: [String: Any])
{
stats.data = session.receivedApplicationContext;
}
};
@main
struct MyWatchApp: App
{
private var stats: Stats = Stats();
private var session_delegate: SessionDelegate;
init()
{
assert(WCSession.isSupported(), "WCSession is not supported, hmm, when does this happen?");
session_delegate = SessionDelegate(stats: stats);
WCSession.default.delegate = session_delegate;
WCSession.default.activate();
}
var body: some Scene {
WindowGroup {
StatsView()
.environment(stats)
}
.backgroundTask(.watchConnectivity) {
}
}
};
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I’m going to mention the Swift Package Manager:
https://www.swift.org/documentation/package-manager/
https://www.swift.org/getting-started/cli-swiftpm/
If you’re looking for something that’s closer to cargo run or make; make install than the full Xcode experience, this may be worth looking at.
Question for the experts: to what extent is the Swift Package Manager “compatible” with Xcode? I.e. can I have a single source tree that’s usable by both?
P.S. I’d be interested to hear your thoughts about C# vs. Rust vs. Swift generally.
Topic:
Programming Languages
SubTopic:
Swift
Is this approach appropriate
No, it’s absolutely horrible.
Topic:
Programming Languages
SubTopic:
General
Tags:
Rust GUI binary that I compiled on Mac
What GUI toolkit is this using? It’s something portable, right, rather than native macOS? That may be more significant than the fact that it’s written in rust.
Topic:
Code Signing
SubTopic:
General
Tags:
But after, the orderings are unstable between individual dictionary instances
They’re still supposed to be stable if you iterate the same object a second time, right?
Topic:
Programming Languages
SubTopic:
Swift
Tags:
At each new for loop we get a random order of element
That surprises me. Please post more code. In particular, are you calling test() on the same object each time, or are you creating a new Test object?
The source for the swift dictionary is here:
https://github.com/swiftlang/swift/blob/main/stdlib/public/core/Dictionary.swift
It start with a lot of comments which you might like to read. In particular, at line 331:
The order of key-value pairs in a dictionary is stable between mutations
but is otherwise unpredictable.
There are data structures that can change order between uses - for example, splay trees reorganise themselves so that recently- or frequently-used elements will be found more quickly. I don’t believe that the Swift dictionary is such a data strucutre.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
The first link I posted suggests this; did you try it?
-mllvm -enable-constraint-elimination=0
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
You haven't told us what goes wrong when you try to run it.
Topic:
Code Signing
SubTopic:
General
Tags:
I talked to the user.
What did he say? Why does he think he wants his "APN Key"?
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
Posts like yours appear here on the forum quite frequently, and I don't recall anyone ever reporting that they managed to save their account from termination. Now that could be because people are rude and lazy and don't bother to post when that happens. Or it could be that once "the algorithm says NO", you really cannot fix it. Or, maybe I just don't remember the stories with the happy outcomes. @MenoM3ayPP, do us all a favour and report back!
Apple reported that they had terminated 428,000 developer accounts "for fraud" in 2022:
https://www.apple.com/uk/newsroom/2023/05/app-store-stopped-more-than-2-billion-in-fraudulent-transactions-in-2022/
Yes, almost half a million accounts. Presumably you are one of those for 2024.
Remember everyone, make sure you have another job that will pay your mortgage when Apple takes away your App Store income. Make sure you still have non-Apple skills on your CV that you can revery to quickly.
Topic:
App Store Distribution & Marketing
SubTopic:
App Review
What is the current state of jailbreaking? If you’re lucky, you’ll be able to crack your devices and continue to run your custom apps. With more than 1000 of them, it is probably worthwhile to employ a “security researcher” to help you with this. If that doesn’t work, sell the devices on eBay and replace them with Android - you may even make a profit doing that, though your software redevelopment costs could wipe that out.
It sounds like your business might be large enough to afford a reasonable lawyer, unlike most of those who get terminated without a reason. But of course Apple can afford a better one, so there still isn’t much hope.
- Replies
- Boosts
- Views
- Activity
How/where do I declare global variables in the same file as "main" location?
Variables declared outside of any class, struct or function, i.e. at the zero-indentation level, are ”global”.
But what, exactly, do you mean by “main”? The Swift equivalent of the “main function” in the C sense is partly explain by eoonline above, but I don’t think that’s really what you mean. I think you mean something more like “constructor”, or similar.
On a large project, there will be multiple associated files that contain related functions. How do make calls to these functions from the "main" file?
Do you understand concepts like classes, objects and methods?
In C# for example, I can't simply call the function name, it has to be associated the "class" that the function is stored in first.
OK, so you have heard of classes…
Do I have to declare these related functions in the "main" form ahead of usage?
Generally, the Swift compiler finds declarations in other files without any extra work on your part (unlike C).
But looking at your example, I think what you may be doing is creating instances of classes in order to call their methods. In that case, the answer is “yes, of course you need to create objects before you can call their (non-static) methods”.
Eoonline wrote:
Judging from your question, the problem might be less about the Swift language, itself (which I wager that you will quickly grok) than the SwiftUI framework
I agree that you should absolutely learn non-UI Swift first, and then learn SwiftUI, taking care to understand that its body declarative parts are subtly different from other Swift code.
I used "print(hi)" just to ensure that my function call was being called.
Crucially, the calls 1 and 2 are not within a function, they’re within a SwiftUI body declaration.
I’m not sure I agree with eoonline that you will “quickly grok” Swift, though. I have the impression that your first language was probably something without classes - maybe Fortran or Pascal - and you continue to think of everything in terms of those semantics.
Topic:
Programming Languages
SubTopic:
Swift
- Replies
- Boosts
- Views
- Activity
suppose If there is a case where it fails due to insufficient memory.
To address that point specifically:
(On iOS), When memory is low, apps get memory warnings and should free resources. If that’s not enough, suspended apps will be terminated.
The only situation where you will really run out of memory is if you ask for a ridiculously large allocation, and that indicates a bug in your program.
(The same is also true on other platforms, except embedded systems without virtual memory. Unless you run out of virtual address space, memory allocations will always succeed even when physical RAM is exhausted; the problem is dealt with by other mechanisms, such as Linux’s “OOM Killer”. Personally, in my C++ code I assume that memory allocation cannot fail.)
More generally: if the API has some way of reporting an error, try to handle it; if it doesn’t, assume that it cannot fail for valid parameters.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags:
- Replies
- Boosts
- Views
- Activity
I can’t really answer your questions, because the don’t make much sense. It sounds to me as if you have tried to learn Swift and SwiftUI by reading random bits of code and trying to work out what they mean by looking for connections with other languages. Sorry, that’s not going to work.
Now in the SwiftUI project, I tried this...
What do you actually want to happen? Presumably you want it to print “hi” at some point. When do you want it to do that?
If you want it to print “hi” when a ContentView struct is created, put it in an init method.
Topic:
Programming Languages
SubTopic:
Swift
- Replies
- Boosts
- Views
- Activity
I think you'd need to schedule a snapshot refresh if the WatchConnectivity background task updates your UI
Or maybe not, according to the docs at https://developer.apple.com/documentation/watchkit/preparing-to-take-your-watchos-app-s-snapshot
If your app uses the SwiftUI BackgroundTask tasks, the system automatically detects any changes to the user interface and schedules the snapshot task.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
- Replies
- Boosts
- Views
- Activity
Many thanks! Here is the skeleton of what I have; any comments? In particular, should I be doing anything in the .backgroundTask(.watchConnectivity)?
import Foundation;
import SwiftUI;
import WatchConnectivity;
@Observable
class Stats
{
var data: [String: Any] = [:];
};
struct StatsView: View
{
@Environment(Stats.self) private var stats;
var body: some View {
VStack {
Text(stats.data.description)
}
}
};
class SessionDelegate: NSObject, WCSessionDelegate
{
private var stats: Stats;
init(stats: Stats)
{
self.stats = stats;
}
func session(_ session: WCSession,
activationDidCompleteWith activationState: WCSessionActivationState,
error: (any Error)?) {
// TODO check state, error, etc.
stats.data = session.receivedApplicationContext;
}
func session(_ session: WCSession,
didReceiveApplicationContext application_context: [String: Any])
{
stats.data = session.receivedApplicationContext;
}
};
@main
struct MyWatchApp: App
{
private var stats: Stats = Stats();
private var session_delegate: SessionDelegate;
init()
{
assert(WCSession.isSupported(), "WCSession is not supported, hmm, when does this happen?");
session_delegate = SessionDelegate(stats: stats);
WCSession.default.delegate = session_delegate;
WCSession.default.activate();
}
var body: some Scene {
WindowGroup {
StatsView()
.environment(stats)
}
.backgroundTask(.watchConnectivity) {
}
}
};
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
- Replies
- Boosts
- Views
- Activity
I’m going to mention the Swift Package Manager:
https://www.swift.org/documentation/package-manager/
https://www.swift.org/getting-started/cli-swiftpm/
If you’re looking for something that’s closer to cargo run or make; make install than the full Xcode experience, this may be worth looking at.
Question for the experts: to what extent is the Swift Package Manager “compatible” with Xcode? I.e. can I have a single source tree that’s usable by both?
P.S. I’d be interested to hear your thoughts about C# vs. Rust vs. Swift generally.
Topic:
Programming Languages
SubTopic:
Swift
- Replies
- Boosts
- Views
- Activity
Is this approach appropriate
No, it’s absolutely horrible.
Topic:
Programming Languages
SubTopic:
General
Tags:
- Replies
- Boosts
- Views
- Activity
Rust GUI binary that I compiled on Mac
What GUI toolkit is this using? It’s something portable, right, rather than native macOS? That may be more significant than the fact that it’s written in rust.
Topic:
Code Signing
SubTopic:
General
Tags:
- Replies
- Boosts
- Views
- Activity
But after, the orderings are unstable between individual dictionary instances
They’re still supposed to be stable if you iterate the same object a second time, right?
Topic:
Programming Languages
SubTopic:
Swift
Tags:
- Replies
- Boosts
- Views
- Activity
At each new for loop we get a random order of element
That surprises me. Please post more code. In particular, are you calling test() on the same object each time, or are you creating a new Test object?
The source for the swift dictionary is here:
https://github.com/swiftlang/swift/blob/main/stdlib/public/core/Dictionary.swift
It start with a lot of comments which you might like to read. In particular, at line 331:
The order of key-value pairs in a dictionary is stable between mutations
but is otherwise unpredictable.
There are data structures that can change order between uses - for example, splay trees reorganise themselves so that recently- or frequently-used elements will be found more quickly. I don’t believe that the Swift dictionary is such a data strucutre.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
- Replies
- Boosts
- Views
- Activity
The first link I posted suggests this; did you try it?
-mllvm -enable-constraint-elimination=0
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
- Replies
- Boosts
- Views
- Activity
You haven't told us what goes wrong when you try to run it.
Topic:
Code Signing
SubTopic:
General
Tags:
- Replies
- Boosts
- Views
- Activity
I talked to the user.
What did he say? Why does he think he wants his "APN Key"?
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
- Replies
- Boosts
- Views
- Activity
Posts like yours appear here on the forum quite frequently, and I don't recall anyone ever reporting that they managed to save their account from termination. Now that could be because people are rude and lazy and don't bother to post when that happens. Or it could be that once "the algorithm says NO", you really cannot fix it. Or, maybe I just don't remember the stories with the happy outcomes. @MenoM3ayPP, do us all a favour and report back!
Apple reported that they had terminated 428,000 developer accounts "for fraud" in 2022:
https://www.apple.com/uk/newsroom/2023/05/app-store-stopped-more-than-2-billion-in-fraudulent-transactions-in-2022/
Yes, almost half a million accounts. Presumably you are one of those for 2024.
Remember everyone, make sure you have another job that will pay your mortgage when Apple takes away your App Store income. Make sure you still have non-Apple skills on your CV that you can revery to quickly.
Topic:
App Store Distribution & Marketing
SubTopic:
App Review
- Replies
- Boosts
- Views
- Activity