Xcode 'Organization Identifier'

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

If it is within your application, [[NSBundle mainBundle] bundleIdentifier].

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.

maybe an xcode setting that it retains from run to run ?
not sure where it stores its per user data

that is exactly what I think it isā€¦ the question is either where is it? or is there an API call to get it.

I have an app the is building a ā€˜project.pbxprojā€™ file and this is one of the key elements that needs to be in that file

possibly ~/Library/Preferences/com.apple.dt.Xcode.plist ?

	<key>IDEProvisioningTeamManagerLastSelectedTeamID</key>
	<string>9E96X6RPU7</string>

???

and there is ~/Library/Preferences/com.apple.Xcode.plist

could be something in either one

<IDETemplateOptions>
<key>bundleIdentifierPrefix></key>
<string>sisemore</string>

Right plist, wrong entry, but it gave me a place to look :slight_smile:

Thanks

Ah that key makes WAY more sense too !

And so now you know the plist & key you can grab it with the user defaults APIā€™s :+1:

1 Like

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

but as a plist dict wouldnt it be a dict that contains arrays & other dicts as well as simple key value pairs etc ?

maybe Apple Developer Documentation and the domain is ā€œcom.apple.dt.Xcode.plistā€ ?

sighā€¦ no ideaā€¦

such helpful Apple documentation :slight_smile:

Follow Normanā€™s advice, as his is the recommend method since macOS 10.7.

LOLā€¦ and exactly what ā€œadviceā€ was that?

Use the user defaults classes for the domain ā€œcom.apple.dt.Xcode.plistā€

1 Like

Hello folks newbie here.

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
    }

Hope that helps.

Regards Mark

Here is a much shorter methodā€¦ Thanks to guideance from Norman :slight_smile:

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")
}

welcome to our little world :stuck_out_tongue:

Thanks Norman.

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.

We have all kinds here
Xojo
Java
Swift
PHP
and Iā€™m sure there are others

INN, while largely populated by a lot of Xojo users, is more about x-platform than just a single tool set