"defaults read com.apple.dock" as Objective C method - objective-c

I try to read the plist / xml file which is behind the terminal commando:
defaults read com.apple.dock
I tried NSUserDefaults without success. Maybe you can help me. Thanks.

You can use CFPreferences, for example
CFStringRef orient = (CFStringRef) CFPreferencesCopyAppValue( CFSTR("orientation"), CFSTR("com.apple.dock") );
Boolean hidesIsValid = false;
Boolean hides = CFPreferencesGetAppBooleanValue( CFSTR("autohide"), CFSTR("com.apple.dock"), &hidesIsValid );

While JWWalker's answer that uses CoreFoundation APIs works fine, a more modern way is to use Foundation APIs, like so:
if let defaults = UserDefaults(suiteName: "com.apple.dock") {
let orientation = defaults.string(forKey: "orientation")
let autohide = defaults.bool(forKey: "autohide")
...
}

Related

problem posting embeds in discord.net 2.0

So I have been trying to figure this out but I can't find any sources on discord.net 2.0.0-beta which I am currently using.
My question is how to post an embed in the chat, I know how to build one and what the different things do but when I do the method I used in 1.0 it comes up with an error regarding not being able to convert Discord.EmbedBuilder to Discord.Embed
Any help would be appreciated.
My Code:
var eb = new EmbedBuilder();
EmbedFooterBuilder efb = new EmbedFooterBuilder();
EmbedFieldBuilder ef = new EmbedFieldBuilder();
SocketGuild server = ((SocketGuildChannel)msg.Channel).Guild;
//Incorrect use
if (parameters.Length > 0)
{
await msg.Channel.SendMessageAsync($"**Correct Usage**: `{Syntax}`");
return;
}
eb.Title = server.Name;
eb.Description = "this is a really fancy description";
await msg.Channel.SendMessageAsync("", false, embed: eb);
Just call the Build() method on the EmbedBuilder instance.
There was an implicit conversion from EmbedBuilder -> Embed that was removed in the 2.0 development cycle.
You also can
var embed = new EmbedBuilder();
embed.WithTitle("Normal title");
embed.WithDescription("So cute description");
embed.WithFooter("Wawwww i love stanley");
Context.Channel.SendMessageAsync("", false, embed);

Searching PDF using PDFKIT in Swift

I am extremely new to swift so bear with me. I am trying to figure out how to search the PDF document for a particular string. I am assuming I need to use the findString function. I just do not know exactly how the parameters should be implemented. I am using Apple Docs. and couldn't see a description of this.
Thanks!=]
private func loadPDF(){
guard
let url = Bundle.main.url(forResource: pdfTitle, withExtension: "pdf"),
let document = PDFDocument(url:url)
else {fatalError()}
pdfView.document = document
}
func findString(_ string: String,
withOptions options: NSString.CompareOptions = []) -> [PDFSelection]
To get a list of matches you do something like this:
let matches = document.findString("foo", withOptions: .caseInsensitive)

How i retrieve data in iOS xCode SDK?

I am using Titanium. and I want to make Titanium Module (for iOS).
every thing is working fine. But, how i retrieve data in xCode whose i send through .js file.
in .js file
var data = "Mritunjay";
var oldData = "Singh";
var data = module_tset.findData({"newData":data,"oldData":oldData});
in xCode
-(id)findData:(NSMutableArray *)args
{
NSMutableArray *ary = [[NSMutableArray alloc]initWithArray:args];
// How i retrieve "newData" Value in xCode?
}
please help me..! thanks
First you should check the documentation for this.
Also, check the example moddevguide projects on GitHub, they have very simple and straightforward examples of how to do this.
In a nutshell heres the code to extract those arguments (assuming you setup this correctly).
-(id)findData:(id)args
{
ENSURE_SINGLE_ARG(args,NSDictionary); // Standard practice
NSString *newData_Pass = [TiUtils stringValue:[args objectForKey:#"newData"]];
// Now do something with newData!
}
Thats it!

How to create WritebleBitmap from a resource image with C++ for Windows Metro app?

I can easily create a BitmapImage from a resource JPG image file using the following code...
Windows::Foundation::Uri^ uri = ref new Windows::Foundation::Uri(L"ms-appx:///Hippo.JPG");
Imaging::BitmapImage^ image = ref new Imaging::BitmapImage(uri);
But WritableBitmap does not take an Uri. I see a SetSource method, but that needs a IRandomaccessStream and not an Uri. And I have no clue how to create one from a JPG file. I searched the net over and over again, but could not find a straight forward answer. Any help would be greatly appreciated.
I want something like this...
Windows::UI::Xaml::Media::Imaging::WriteableBitmap image = ref new Windows::UI::Xaml::Media::Imaging::WriteableBitmap();
image->SetSource(somehowGetRandomAccessStreamFromUri);
But, how do I get the IRandomaccessStream instance from a uri? I started working on C++ Metro app only today, so might be wrong, but I find it to be overly complicated with too much of onion peeling.
In C# you would do something like
var storageFile = await Package.Current.InstalledLocation.GetFileAsync(relativePath.Replace('/', '\\'));
var stream = await storageFile.OpenReadAsync();
var wb = new WriteableBitmap(1, 1);
wb.SetSource(stream);
I think in C++/CX you would do something like this:
#include <ppl.h>
#include <ppltasks.h>
...
Concurrency::task<Windows::Storage::StorageFile^> getFileTask
(Package::Current->InstalledLocation->GetFileAsync(L"Assets\\MyImage.jpg"));
auto getStreamTask = getFileTask.then(
[] (Windows::Storage::StorageFile ^storageFile)
{
return storageFile->OpenReadAsync();
});
getStreamTask.then(
[] (Windows::Storage::Streams::IRandomAccessStreamWithContentType^ stream)
{
auto wb = ref new Windows::UI::Xaml::Media::Imaging::WriteableBitmap(1, 1);
wb->SetSource(stream);
});

How to use foreach in c++ cli in managed code

Hi how to use foreach loop in managed code c++ using vs2003.
I've never used it, but this MSDN article indicates the general syntax is just:
for each(Type t in IEnumerable)
{
}
Matthew is mostly correct, but here's a working block of code;
///////
array<Type^>^ iterate_me = gcnew array<Type^>(2);
iterate_me[0] = Type::GetType("Type");
iterate_me[1] = Type::GetType("System.Int32");
///////
for each(Type^ t in iterate_me)
Console::WriteLine(t);
The changes were Type is a reference class, so you use "Type^" not "Type" and you need an actual object reference (iterate_me)...
Something like:
String ^ MyString = gcnew String("abcd");
for each ( Char c in MyString )
Console::Write(c);
As of VS2022 for each apparently no longer works. Instead you can do something like this:
IEnumerator^ enumerator = myList->GetEnumerator();
while (enumerator->MoveNext())
{
// Do stuff
}
I don't think that VC++ has foreach