I once posted a question in the forums, but it seems I cannot find the thread now (maybe the thread was before the new forums was born).
I don't know why I am so confused about this directive (or whatever):
It looks like a compiler directive because it has a specific syntax.
But it also looks like it's a runtime check because it is used in if statement (not in #if).
So my question is:
Given the following code:
if (@available(macOS 13.0, *) {
NSLog("Running on macOS Ventura or later")
} else {
NSLog("Running on older version before Ventura")
}
Does this directive check real macOS version during runtime?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am in peril. Can anyone save me. I am desperate!
I am using Xcode Version 14.2 (14C18) to build my 2 dylibs. I had no problems with older versions of Xcode (one and half a year ago). But it's causing code signing problems and Connect fails my submitted binary package complaining I had wrong entitlement on dylibs.
I contact Apple technical support and I got a reply:
Entitlements are only effective on a main executable. When you sign a shared library with entitlement then, at best, the system ignores them. However, in some cases you can run into mysterious problems like this one.
The key problem is that Xcode is autogenerating entitlement file for my dylibs. I have no entitlement files in my projects, I am sure.
codesign -d --ent - libsqlite3s.dylib
Executable=/Users/USERNAME/Library/Developer/Xcode/DerivedData/libsqlite3s-ahztenmeyvsijneqjzdtifjhljlr/Build/Products/Debug/libsqlite3s.dylib
[Dict]
[Key] com.apple.application-identifier
[Value]
[String] TEAMID.net.neolib.libsqlite3s
How can I turn off this 'useful' feature?
I am in peril. Can anyone save me. I am desperate!
I am using Xcode Version 14.2 (14C18). I created a fresh new library project (plain C/C++) and added the well-known SQLite3.h and SQLite3.c.
When I build debug configuration, Xcode correctly produces dylib. But when I do archive build, the generated xcarchive is almost empty - it does not have expected libsqlite3s.dylib!
I even went back to Xcode 7.2.1 on macOS 10.10. Xcode 7.2.1 can correctly produce archived dylib and I can link the dylib with a test app.
I am extremely frustrated!
I am testing with FSEventStreamCreate which returns an FSEventStreamRef, but I cannot find an equivalent toll-free class in Cocoa.
In order to free-up resources used by this Ref, I need to do following:
FSEventStreamStop(stream);
FSEventStreamInvalidate(stream);
FSEventStreamRelease(stream);
That is quite error-prone and tedious. So I want to write a wrapper class, but don't have any idea on when or where to release the Ref. Is it correct to do 'free' in dealloc?
Not sure if it's specific to me only. I tried to build a framework project using Xcode 14.3.1 RC but got a strange error:
File not found: /Users/USERNAME/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_macosx.a
The project was created several years ago and was upgraded all the way to Xcode 14.2.
I remember last time I posted a question about getting an empty xcarchive when doing archive build. The remedy is quite simple - setting SKIP_INSTALL to no.
I wonder if this problem also has a simple remedy.
This is really disgusting. I really hate to say this.
I started Xcode programming many years ago when it's at version 4 (or even 3). It has been fun and pleasure to program in this IDE, with no problem at all. User rating of this app in App Store was 4.5+.
But 2 or 3 years ago, maybe starting from Xcode 11, it started getting too many quirks/gotchas. App Store user rating drops to 3.5+.
With version 14+, user rating drops to 2.9.
The app's key/main features work. But many small bugs/nuisances put developers like me into peril during daily coding work.
Now I almost want to quit Xcode programming, because it is making my life unpleasant.
I remember last time I could download epub book (5.7) of the Swift language from https://www.swift.org. But now I cannot find the link. Where is the link now?
A simple question, but I am not able to find the answer myself.
Note - I tried ProcessInfo.environment but it does not include system env vars.
I am trying to encode/decode JSON data, and I have the following code:
struct SomeOrdinaryClass: Decodable {
// ...
}
struct SomeBox<T>: Decodable {
var data: T?
}
But Xcode gives me the following error:
myfile.swift:16:8 Type 'SomeBox' does not conform to protocol 'Decodable'
Is there anyway to overcome this?
I have a need to wrap several kinds of objects into a dictionary say [String: Any?], but how do I tell that the Any? object is all Encodable?
let params: [String: Any?] = ["num": 123, "text": "abc", "obj": encodableobject]
JSONEncoder().encode(params) // compiler error because Any? is not Encodable
The following code compiles fine in a normal Swift app, but not in the accompanying unit test bundle.
I don't have any idea why.
import Foundation
struct Dummy: NSObject { // Error: Inheritance from non-protocol type 'NSObject'
var name: String?
}
This may sound strange, but I encounter real world need on this.
private var queryItems_: [URLQueryItem]?
private var queryItems: [URLQueryItem]? {
get {
if queryItems_ == nil {
if !queries.isEmpty {
queryItems_ = queries.map { (key: String, value: String?) in
return URLQueryItem(name: key, value: value)
}
}
}
return queryItems_
}
}
/// Query strings
public private(set) lazy var queries = [String: String?]() {
didSet {
queryItems_ = nil
}
}
The queryItems will be (re)created on get if queries property was changed. What I wish is that I could use queryItems as a simple var property but let me do my logic in its getter. Is this supported already?
I want to expand the first only root node when NSOutlineView is finished loading all data.
How to get notified in code (possibly by some delegate function)?
In many cases, I need to get the value from a dictionary given a key (usually a string). I have the following helper class:
public class ObjectCache<T> {
private var cache = [String: T]()
subscript(name: String) -> T? {
get { return cache[name] }
set { cache[name] = newValue }
}
func get(_ name: String, with builder: () -> T?) -> T? {
var obj = cache[name]
if obj == nil {
obj = builder()
cache[name] = obj
}
return obj
}
}
This saves much keyboard typing and avoid common errors of oversight. Like below:
let serviceURL = self.urlCache.get(name) { return comp.url }!
Now my question is - Does Swift provide some builtin functionality like this? I just hope I did not re-event the wheel.
I came across an article about extension of Optional (https://useyourloaf.com/blog/empty-strings-in-swift/), but I cannot get it to work for the Optional extension.
extension Optional where Wrapped == String {
var isBlank: Bool {
return self?.isBlank ?? true
}
}
func testIsBlank() {
for s in [nil, "", " ", "\t", "abc"] {
print(s?.isBlank)
}
}
For nil value, the output is still nil. I see the article is quite old dated back in 2019. There must be some changes in the language specs. What's going on here?