When you create a NEW Xcode project you are presented with a screen to fill in basic project information. One is Organization Identifier, which is filled in with the value from the last project you created.
Where is that stored? I need to be able to read that value, and use it when creating an external file
No, that is NOT what I am looking forā¦
I need to read the ORG ID (not bundle id), and I need the one that Xcode would assign to a new app, not the one assigned to the app being executed.
Somewhere in the system that value is stored.
If I were to give you an app, and you ran it, I want it to display the Org ID, that is on YOUR computer, not the one that is on mine.
kicked in the teeth again by lack of proper docs.
I found this that I thought could be alteredā¦
public var acceptedXcodeVersion: String {
var acceptedXcodeVersion = ""
let licensePlistPath = "/Library/Preferences/com.apple.dt.Xcode.plist"
if FileManager.default.fileExists(atPath: licensePlistPath) {
if let licenseInfo = NSDictionary(contentsOfFile: licensePlistPath) {
print(licenseInfo) // I expected the ENTIRE Plist here?
if let version = licenseInfo["IDEXcodeVersionForAgreedToGMLicense"] as? String {
acceptedXcodeVersion = version
}
}
}
return acceptedXcodeVersion
}
but for some reason it only read a tiny tiny part of the whole Plist file
Found the site when google searching for āgetting line numbers from an NSTextViewā.
And found a posting here by DaveS, so returning the favour for that code Dave.
As has been pointed out by others, āUserDefaultsā is best for writing and reading preferences for your own appās.
But I tend to use the āPropertyListSerializationā swift class for reading and writing plist files of others, and non preference xml type storage solutions.
Something like this.
public var xcodeAcceptedVersion: String {
var xcodeAcceptedVersion = String()
let xcodePlistFileURL = URL(fileURLWithPath: "/Library/Preferences/com.apple.dt.Xcode.plist")
do {
let xcodePlistFileData = try Data(contentsOf: xcodePlistFileURL, options: .mappedIfSafe)
let xcodePlistDictionary = try PropertyListSerialization.propertyList(from: xcodePlistFileData,
options: .mutableContainersAndLeaves,
format: nil) as! [String: Any]
if let plistXcodeVersion = xcodePlistDictionary["IDEXcodeVersionForAgreedToGMLicense"] as? String {
xcodeAcceptedVersion = plistXcodeVersion
}
} catch {
// Error reading file URL Data or creating property list Dictionary
xcodeAcceptedVersion = ""
}
return xcodeAcceptedVersion
}
Here is a much shorter methodā¦ Thanks to guideance from Norman
let xcodePlist = UserDefaults(suiteName: "com.apple.dt.Xcode.plist")
if let retValue:AnyObject = xcodePlist!.object(forKey: "IDETemplateOptions") as AnyObject? {
// print("Value : \(retValue)") // if you want to see other "keys"
let bundleIDPrefix : String = retValue["bundleIdentifierPrefix"] as! String
print(bundleIDPrefix)
} else {
print("error")
}
I havenāt used RS / Xojo for over a decade, so I canāt contribute much on that front.
But I see some other fellow Swift coders here, who I guess I can swap ideas with.