why does this attributed string stmt crash? - nsattributedstring

I'm trying to learn how to use attributed strings. This statement caused a "EXC_BAD_ACCESS":
NSDictionary *attDict = #{ NSForegroundColorAttributeName : [UIColor redColor] };
The way I read the documentation NSForegroundColorAttributeName is an NSString, so I then tried this but got the same crash:
NSLog(#"NSForegroundColorAttributeName: %#", NSForegroundColorAttributeName );
and also this and got the same crash:
NSString *fcan = NSForegroundColorAttributeName;
So it looks like any mention of NSForegroundColorAttributeName causes a crash. I did try other xxxAttributeNames and they do the same thing. I am importing UIKit/UIkit.h. There are no compiler warnings and no run time messages. What am I missing? Is there something else I need to import or assign? Do I have the whole concept wrong? I don't think there are any Apple code samples that cover this.

Using the newer NS* constants compiles because the extern for them is present in a header (if you build with "Latest iOS" SDK, but if you execute this code on a device that has not iOS 6 but lower then you get the crash you describe.

Related

How to know, if running on device or simulator in react native

To distinguish between development mode and production mode in react native there is the __DEV__ constant defined, when Debug = True.
Is there a similar constant defined, that lets me know within the code, if the code is running on the device or in the simulator?
Where else could I get this kind of information from.
You can use this package, then just do :
console.log(DeviceInfo.getModel()); // it returns 'Simulator'
Since G. Hamaide's answer was posted, the DeviceInfo package has added the method isEmulator.
DeviceInfo.isEmulator()
there's a caveat here, DeviceInfo.isEmulator() returns a promise, so if you use if(DeviceInfo.isEmulator()), it'll return true even if running on a real device.
Use DeviceInfo.isEmulatorSync() or if(await DeviceInfo.isEmulator()).

No Way to get the console handle (Dev-Pascal)

I've tried the simple program for my exercise but if i compiled, it turned give a message "No Way to get the console handle" (Dev-Pascal).
Here's my code:
program square;
uses crt;
var
side,circumference,broad:real;
begin
write('Input the side value of the square: ');
readln(side);
circumference := 4 * side;
broad := side * side;
writeln('The circumference value of the square = ', circumference);
writeln('The abroad value of the square = ', broad);
writeln();
write('Press any key...');
readkey();
end.
thank you for helping and teaching me
i would appreciate
Dev-pascal comes with a 10+ years old Free Pascal version. I really have no idea. Try to run the example on the cmdline to see if dev-pascal is the cause or something else. Temporarily disable security software might also be something to try.
I suppose, you've created a Window Skeleton project.
It has it's description: A Windows skeleton application (no window).
In this case you'll get this error though you code compiles (I've got this error too with your code).
Try to create Console Application project which has it's own description: A standard console-based (MS-DOS) application (Your code has compiled and the program worked as well).
P.S. Can't say what exactly happens -- couldn't find any documentation about errors in Dev-Pas (1.9.2).
My assumption is that skeleton program doesn't imply console window for execution program while console application does.
just close the project and then re-open the pascal source file (.pas). And maybe put "readln;" just before "END.".

Error while compiling botan sample example in Qt

I am trying to find out the error for two days but still haven't got this unknown reason figure out.
I have configured and compiled Botan library. Everything goes ok but when try to write this sample code to be run..
S2K* s2k = get_s2k("PBKDF2(SHA-256)");
s2k->set_iterations(4049);
SecureVector<byte> key_and_IV = s2k->derive_key(48, passphrase).bits_of();
SymmetricKey key(key_and_IV, 32);
it says error: 'class Botan::PBKDF' has no member named 'set_iterations'
How can I solve this problem ?
The Botan docs for v1.11.1 report that the function get_s2k() has been deprecated, recommending that you use get_pbkdf() instead.
According to the docs, get_sdk(algospec) just returns the result of a call to get_pbkdf(algo_spec) which will give you a pointer to an instance of the class Botan::PBKDF.
First things first then, your code needs to be something more like:
PBKDF *s2k = getpbkdf("PBKDF2(SHA-256)");
Unfortunately without knowing what you want to do with s2k I can't help any further, as the docs have no reference to a public member function of PBKDF called set_iterations(). You're getting the error you mention because Botan::PBKDF really does have no member named set_iterations. You need to read the docs, work out what the purpose of set_iterations() was in your now deprecated example and hence how to achieve that purpose in the newer version of the library.
Possibly you missed your library header... as your error message says: 'has no member named...'

browseForOpenMultiple - crashing

I am trying to work with browseForOpenMultiple function inside Flex, sdk 3.5, I am trying to figure out a bug. The browseForOpenMultiple does not crash everytime, but it seems as though I can upload a file once, but when I go to upload a second file, it crashes when the browseForOpenMultiple function is called. Anyone have any ideas about possible causes?
Update:
private function browseForFiles():void
{
fileBrowser = new File();
fileBrowser.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
fileBrowser.addEventListener(Event.CANCEL, fileSelectionCancelled);
fileBrowser.browseForOpenMultiple("Select Desired Media File(s)", [(mode == "Media")? MediaTypes.getFileFilter() : MediaTypes.getVideoFilter()]);
}
So the code in our array of file extensions was crashing when there were over 60 items listed in an array that gets converted into a string for the FileFilter. This may not be an Adobe limit, but I wanted to make mention that the crash is fixed, so that others who may be encountering issues with browseForOpenMultiple will know what the issue was for this problem. This is not code that I originally wrote, so I will check into it for more clues, but for the time being, too many array items being joined together into a string for FileFilter object caused the crash.
It could be how it's construct the File, without a real file reference.
Try something like this :
var fileBrowser = File.desktopDirectory

Conditional compilation "else"

In AS3 you can pass a constant to the compiler
-define+=CONFIG::DEBUG,true
And use it for conditional compilation like so:
CONFIG::DEBUG {
trace("This only gets compiled when debug is true.");
}
I'm looking for something like #ifndef so I can negate the value of debug and use it to conditionally add release code. The only solution I've found so far was in the conditional compilation documentation at adobe and since my debug and release configurations are mutually exclusive I don't like the idea of having both DEBUG and RELEASE constants.
Also, this format works, but I'm assuming that it's running the check at runtime which is not what I want:
if (CONFIG::DEBUG) {
//debug stuff
}
else {
//release stuff
}
I also considered doing something like this but it's still not the elegant solution I was hoping for:
-define+=CONFIG::DEBUG,true -define+=CONFIG::RELEASE,!CONFIG::DEBUG
Thanks in advance :)
This works fine and will strip out code that won't run:
if (CONFIG::DEBUG) {
//debug stuff
}
else {
//release stuff
}
BUT this will be evaluated at runtime:
if (!CONFIG::DEBUG) {
//release stuff
}
else {
//debug stuff
}
mxmlc apparently can only evaluate a literal Boolean, and not any kind of expression, including a simple not.
Use the if / else construct : the dead code will be removed by the compiler and it will not be tested at runtime. You will have only one version of your code in your swf.
If you are not sure use a decompiler or a dump tool to see what really happens.
http://apparat.googlecode.com/files/dump.zip
http://www.swftools.org/
...
While Patrick's answer fulfills the question's criteria, it does not cover all use cases. If you are in an area of code that allows you to use an if/else statement then this is a good answer. But if you are in a place where you cannot then you will need a better solution. For example, you may want to do something like this to declare a constant in a class:
private var server:String = "http://localhost/mystagingenvironment";
or for a live release:
private var server:String = "http://productionserver.com";
(this is an example and I'm not advocating this as production code).
I use xml configs and use the loadConfig+="myconfig.xml" to do my configuration instead of passing large numbers of command line params. So in the <compiler> section of your xml config:
<define>
<name>CONFIG::debug</name>
<value>false</value>
</define>
<define>
<name>CONFIG::release</name>
<value>!CONFIG::debug</value>
</define>
This works well for all use cases:
CONFIG::debug
{
private var server:String = "http://localhost/mystagingenvironment";
}
CONFIG::release
{
private var server:String = "http://productionserver.com";
}
This has the additional benefit of working consistently across applications. It also does not rely on the 'optimize' flag being true, like Patrick's answer (although I think we can assume that 99.999999% of all swfs have optimize=true, I only set it to false when the optimizer breaks my AS3).
It does have the drawback that it doesn't compile all code paths, just the ones that are included. So if you're not using a build server to create release builds and tell you when things break, be prepared for surprise errors when you do your release build ("But it compiled in debug! Crap, I need this to launch now!").
Just my two cents about Chris Hill's answer (which is the solution I also use regularly): it seems that using the loadConfig+="myconfig.xml" option makes the compiler searching for the myconfig.xml file in the Flex SDK directory whereas the -load-config+=myconfig.xml option makes it searching for the myconfig.xml file in the project's directory, which is the behavior I strongly prefer as you can then easily distribute this file with your project sources...

Resources