How to make GDATAXML compatible with ARC in XCODE 4.2? - xcode

I tried to convert GDATAXML Lib to ARC automatically with the refractor -> Convert to ARC Objective-C in XCode 4.2.
The ARC converter gives the following error:
result = [NSString stringWithUTF8String:(const char *) chars];
if (cacheDict) {
// save the string in the document's string cache
CFDictionarySetValue(cacheDict, chars, result);
}
error: Impicit conversion of Ojective-C pointer to void.
Has anyone succeeded in converting the GDATAXML Libs to ARC Objective-C?

please follow the instructions on how to make GDataXML work on your code: http://ibombsite.blogspot.com/2012/02/how-to-make-gdataxmlnode-work.html

I found someone who has (apparently successfully) done the refactor for ARC.
see: http://www.michaelbabiy.com/arc-compliant-gdataxml-library/

You need to use bridged cast:CFDictionarySetValue(cacheDict, chars, (__bridge_retained_void*) result);Check out Apple's article "Transitioning to ARC", especially the part about briding.

Related

freeimage 3.17 library build failing on Mac OS X: fails with C++11 narrowing error... any ideas?

With not having any understanding of C++ (I'm teaching myself Swift), I'm struggling a bit to get around this one - but ideally would love to be able to expose some of the functionality in the FreeImage library in my project.
It appears that only one module is generating any errors: dcraw_common.cpp - and the lines in error are those from the following entry list where there is a value of 0x80 or above. From the investigations I've done, it would appear that these values are too large for a signed char (max 128?), yet the list also includes negative numbers, and so it can't use an unsigned char.
Any help would be most gratefully received.
Here's an example of the error message generated by the make process:
Source/LibRawLite/./internal/dcraw_common.cpp:4543:19: error: constant expression evaluates to 136 which cannot be narrowed to type 'signed char'
[-Wc++11-narrowing]
+1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40,
^~~~
And here's the code:
void CLASS vng_interpolate()
{
static const signed char *cp, terms[] = {
-2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01,
-2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01,
-2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03,
-2,+1,-1,+0,0,0x04, -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1, +1,0, +1,-1, 0,-1 };
...
C++11 prevents 'narrowing conversions' like that. Early versions of C++ would accept them. I think this patch to the source of dcraw_common.cpp should fix it.
https://gist.github.com/conchurnavid/ac19c8e882f1835f0310
There's a duplicate question here. Building FreeImage 3.16.0 for Android
The most usable solution I found to this issue was the following GitHub posting: https://github.com/danoli3/FreeImage. Here some kind soul appears to have successfully built the 3.17.0 library and uploaded it. I've found that works just fine.
Please bear in mind however that it's been built with a hard-coded path of /opt/local/lib - which may be an issue when you come to implementation, since your app will be looking for it there, not bundled with the app. I did find this LiveCode post aided my understanding in that regard a lot.
Hope this helps.

Swift 2, convert a String into an Int

I'm using Xcode 7 Beta 3 and reading through Swift 2.2 document. I'm trying to compile this example found in the Basics section of the document:
let possibleNumber = "123"
let convertedNumber = Int(possibleNumber)
It is supposed to convert a string into an optional int. However Xcode gives the error:
Cannot call value of non-function type 'int'
I was working on Xcode 7.2.1, then I knew that Swift 2.2 is packaged with Xcode 7.3 Beta 3, so I downloaded that to try, but the same error happens.
So, is the document wrong? and how to achieve the string into int conversion?
There is nothing wrong with your code, I tested and ran your exact code in Xcode 7.2:
let possibleNumber = "123"
let convertedNumber = Int(possibleNumber)
print("\(convertedNumber)")
It complied, ran within an app of mine, and printed the Int value 123.
Perhaps the error is being thrown from another area of code in your Xcode app, other then the code you think is throwing the error....
Perhaps you are not referencing the version of Swift you think you are...
Note, you should use if let with any conversion attempt:
if let convertedNumber = Int(possibleNumber) {
}
The if let should be used for a conversion no matter how remote the possibility of failure.

XCTest self measureBlock modification?

It appears that XCtest "self measureBlock" is limited to milliseconds and 10 runs of the test code. Are there any ways to modify the behavior of measureBlock for more runs and/or nano or microsecond accuracy?
TL;DR
Apple provides a way to modify the behavior of measureBlock: by providing extra string constants but they don't support any string constants other than the default.
Long explanation
measureBlock calls the following function
- (void)measureMetrics:(NSArray *)metrics automaticallyStartMeasuring:(BOOL)automaticallyStartMeasuring withBlock:(void (^)(void))block;
//The implementation looks something like this (I can't say 100% but i'm pretty sure):
- (void)measureBlock:(void (^)(void))block {
NSArray<NSString *> *metrics = [[self class] defaultPerformanceMetrics];
[self measureMetrics:metrics automaticallyStartMeasure:YES withBlock:block];
}
defaultPerformanceMetrics is a class function that returns an array of strings.
From the Xcode source
"Subclasses can override this to change the behavior of
-measureBlock:"
Lovely, that sounds promising; we have customization behavior right? Well, they don't give you any strings to return. The default is XCTPerformanceMetric_WallClockTime ("com.apple.XCTPerformanceMetric_WallClockTime")
It turns out there aren't any string constants to return besides that one.
See the slides for WWDC 2014 Session 414 Testing in Xcode 6 (link).
I quote from page 158:
Currently supports one metric: XCTPerformanceMetric_WallClockTime
Nothing else has been added in Xcode 7 so it seems you're out of luck trying to modify measureBlock, sorry.
I've never found measureBlock: very useful. Check out Tidbits.xcodeproj/TidbitsTestBase/TBTestHelpers/comparePerformance https://github.com/tipbit/tidbits if you'd like to look at an alternative.

How to force a raw value of 7 into a UIViewAnimationCurve enum?

The key UIKeyboardAnimationCurveUserInfoKey in the userInfo dictionary of a UIKeyboardWillShowNotification contains an Int with the value 7.
Now I need to pass this Int into UIView.setAnimationCurve(<here>). I tried to create the required UIViewAnimationCurve enum like this UIViewAnimationCurve(rawValue: 7). Because the raw value 7 is undocumented, the result is always nil.
It works fine this way in Objective-C. Any idea how to get this animation curve from the notification into a UIView animation using Swift?
Update:
As pointed out by Martin, this is no longer a problem since Xcode 6.3.
From the Xcode 6.3 Release Notes:
Imported NS_ENUM types with undocumented values, such as UIViewAnimationCurve, can now be converted from their raw integer values using the init(rawValue:) initializer without being reset to nil. Code that used unsafeBitCast as a workaround for this issue can be written to use the raw value initializer.
I think I figured it out, but I'm not sure if this is the way it's supposed to be done.
let animationCurve = unsafeBitCast(7, UIViewAnimationCurve.self)
UIView.setAnimationCurve(animationCurve)
Update: The solution contained in this question works as well.
var animationCurve = UIViewAnimationCurve.EaseInOut
NSNumber(integer: 7).getValue(&animationCurve)

xcode 5.1 error implicit conversion loses precision

I updated to Xcode 5.1 and can no longer build several of my projects which use Core Plot 1.4, complaining generally about garbage collection, and proposing that I convert to ARC. I complied, but there were several statements that could not be converted. I quickly came to SO to find a solution, and I found a promising one here:
Core Plot and Xcode 5.1 - How to convert Core Plot to ARC?
I followed this suggestion, and it worked for the conversion to ARC. However, I was now left with 2 errors (not warnings) in CPTTextStylePlatformSpecific.m, which complained: “Implicit conversion loses integer precision: 'NSTextAlignment' (aka 'unsigned long') to 'CPTTextAlignment' (aka 'enum _CPTTextAlignment’)”. This issue had not appeared when building the project before the Xcode update.
The offending code:
// Text alignment and line break mode
NSParagraphStyle *paragraphStyle = [attributes valueForKey:NSParagraphStyleAttributeName];
if ( paragraphStyle ) {
newStyle.textAlignment = paragraphStyle.alignment;
newStyle.lineBreakMode = paragraphStyle.lineBreakMode;
}
return [[newStyle copy] autorelease];
And here:
// Text alignment and line break mode
NSParagraphStyle *paragraphStyle = [attributes valueForKey:NSParagraphStyleAttributeName];
if ( paragraphStyle ) {
newStyle.textAlignment = paragraphStyle.alignment;
newStyle.lineBreakMode = paragraphStyle.lineBreakMode;
}
return newStyle;
In both cases, the error was on the line
newStyle.textAlignment = paragraphStyle.alignment;
I am guessing the enum is an integer, and the integer to long assignment is the issue. Seems like it merits a warning, not an error. Is there a compiler flag I can set to achieve this? Or is there a bigger issue I am missing?
I had exactly this issue and found that in the CorePlot project, that I had imported into my project, I had the "Apple LLVM 5.1 - Warning Policies", "Treat Warnings as Errors" set you "Yes". I still get the warning but at least I can build and submit my project.
This is still not ideal and I would really like a proper solution - I suppose I'll just have to keep checking the CorePlot repository for updates.

Resources