Array initialization is causing build to fail - arrayForceCastU - ios

This line of code is preventing my project from building:
var allAttributes: [UICollectionViewLayoutAttributes] = []
I tried var allAttributes = [UICollectionViewLayoutAttributes]() and it too fails to build.
Here are the error details:
Apple Mach-O Linker Error:
Undefined symbols for architecture i386:
"__TFSs15_arrayForceCastU___FGSaQ__GSaQ0__", referenced from: __TFC42com_myname...30ClassWhereCodeIs33layoutAttributesForElementsInRectfS0_FVSC6CGRectGSqGSaPSs9AnyObject___ in ClassWhereCodeIs.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What is the proper way to initialize an array so that I may append objects to fill it?

That first line builds fine for me in a view controller class.
Have you tried deleting the Derived Data?
Window Menu > Organizer -> Projects -> choose Project. There's an button on the right to delete the Derived Data.

Related

Drag and Drop into a `UICollectionView` placeholder in iOS 11 Beta 4

The API for dragging and dropping into a UICollectionView changed in iOS 11 Beta 4. In beta 1-3, the code looked like:
let placeholderContext = coordinator.drop(
item.dragItem,
toPlaceholderInsertedAt: indexPath,
withReuseIdentifier: "reuseID",
cellUpdateHandler: { _ in }
)
In beta 4, the introduced UICollectionViewDropPlaceholder. My code is
let placeholder = UICollectionViewDropPlaceholder(
insertionIndexPath: indexPath,
reuseIdentifier: "reuseID"
)
let placeholderContext = coordinator.drop(item.dragItem, to: placeholder)
I am getting this compile error:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_UICollectionViewDropPlaceholder", referenced from:
objc-class-ref in StickerLibraryViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
note: symbol(s) not found for architecture arm64
error: linker command failed with exit code 1 (use -v to see invocation)
Other than not using a placeholder until beta 5, anyone have any ideas of how to get this working in beta 4?
Thanks!
Until this is fixed in Beta 5, I ended up solving this issue by dropping down into the Objective-C runtime.
In the Obj-C header…
NS_ASSUME_NONNULL_BEGIN
#interface RKNFactory : NSObject
- (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier;
#end
NS_ASSUME_NONNULL_END
In the implementation…
#import ObjectiveC.runtime;
#implementation RKNFactory
- (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier {
SEL initSelector = NSSelectorFromString(#"initWithInsertionIndexPath:reuseIdentifier:");
Class placeholderClass = NSClassFromString(#"UICollectionViewDropPlaceholder");
return [[placeholderClass alloc] performSelector:initSelector withObject:indexPath withObject:reuseIdentifier];
}
#end
And then from the Swift code…
return RKNFactory().placeholder(for: indexPath, resuseIdentifier: reuseIdentifier)
I had a similar problem with local authentication not compiling on on the simulator architecture when it was in beta.
Does it compile if you remove arm64 from valid architectures in build settings (or turn off “build all architectures”)?
If they compiled this symbol for simulator, but left it out for arm64, the only solution might be to prevent it from compiling on arm64 and test it only on the simulator for now.
You can also wrap the code temporarily in a “#if block” that prevents the compiler from looking at it when building arm64.
Finally, if you’re building for any versions of iOS under iOS 11, be sure to try turning those off for now, in case they forgot to mark API availability (which might have let the compiler provide a more helpful message).

.c File via Bridging Header Not Working After Xcode 8 Update

The app I've been working on uses an external library, pdlib, which has it's own externals (.c files) which I've been importing via the bridging header #import "Uzi.c" and calling in my main Swift file via Uzi.c's setup function Uzi_setup() in my ViewController class. I've had no problem with this until after updating to new public Xcode 8 a few days ago (I had no problem with Xcode 8 Beta 1 over the Summer).
Here are the 7 errors I get, listed under a single "Mach-O Linker Error" umbrella:
Undefined symbols for architecture x86_64:
"_Uzi_bang", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_class", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_float", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_new", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_pause", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_resume", referenced from:
_Uzi_setup in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Those undefined symbols are 6 functions and a class declare from Uzi.c. Here's a link to the whole c file: https://github.com/electrickery/pd-miXedSon/blob/master/hammer/Uzi.c
I've tried every solution I've found online for dealing with similar problems, with no solution yet... I tried changing the "Architecture" and "Valid Architecture" settings to only armv7 and armv7s (no arm64) and changed "Build Active Architecture Only" to "No". These step seem to help others in similar situations, but they didn't work for me (and taking away arm64 causes additional errors to appear).
XCode 8 is pretty recent (the public version was released Sept. 13), so there are virtually no other questions about this upgrade causing a similar problem.
Any help would be greatly appreciated!
Solved by #danomatika on GitHub: https://github.com/libpd/libpd/issues/149
"You generally shouldn't include/import an implementation file aka .c, .cpp, .m, etc. This is what is causing the duplicate symbol issue.
This is what the "forward function declaration" in the header file is for: to tell the compiler that a function exists and what data it takes/returns. The compiler then assumes the actual implementation of the function exists in an implementation file. If it can't be found, then you get an "undefined symbol error." If you somehow end up declaring the function twice, aka include both a header with the forward declaration and the implemetaton of the function itself in the .c file, then you get a "duplicate symbol error."
This is all lower-level stuff that is only really an issue since Pd externals are designed around being dynamic libraries, so are not built or provided with headers which include the function declarations. This is why you have to do a little extra work and do it yourself.
Their are two easy fixes for this, both of which involve declaring the required function you want to call from the .c file in a header file.
Simply declare the function in the bridging header:
void uzi_setup();
Create a header, say Externals.h, and declare all of the externals stuff there:
// forward declare setup functions only found in .c implementations
void uzi_setup();
// convenience wrapper function
void externals_setup() {
uzi_setup();
}
Then import the file in your bridging header:
#import "Externals.h"
And in swift, you can now do:
externals_setup()

Admob Conversion Tracking in Swift

I tried to set conversion tracking in my iOS game, but I didn't be able to do that. The tutorial can be found here: https://developers.google.com/app-conversion-tracking/ios/?hl=it#usage_and_disclosure
I integrate the GoogleConversionTrackingSDK to my project, load AdSupport framework and type -ObjC in Other linker flags.
I tried to convert this snippet from Obj-C:
[ACTConversionReporter reportWithConversionID:#"MY_ID" label:#"MY_LABEL" value:#"MY_VALUE" isRepeatable:NO];
to Swift:
ACTConversionReporter.reportWithConversionID("MY_ID", label: "MY_LABEL", value: "MY_VALUE", isRepeatable: false)
and I put that in didFinishLaunchingWithOptions method of AppDelegate.swift, but I get the error:
Use of unresolved identifier 'ACTConversionReporter'
If I type in Obj-C bridging header in Swift Compiler - Code Generation in Build Settings "ACTReporter.h" (without qm), I put the header file in the folder of my game or if I type the whole path of "ACTReporter.h" ending with its name, I fail the build and I get 2 errors:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_ACTConversionReporter", referenced from:
type metadata accessor for __ObjC.ACTConversionReporter in AppDelegate.o
ld: symbol(s) not found for architecture armv7 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
I don't know what to do. I hope there is someone who can fix this.
You need to add to your project "YourProjectName-Bridging-Header.h" file
Here you can see how to add the file
in Bridging Header file add #import "ACTReporter.h"
Then it will work for you!

UITest: Undefined symbols for architecture armv7

I'm trying to call a swift singleton from my UITest target. I'm importing the main module: #testable import Ary but when I try to build it says:
Undefined symbols for architecture armv7:
"Ary.DataModelLayerOperation.getter : Ary.DataModelLayer", referenced from:
AryUITests.AryUITests.setUp (AryUITests.AryUITests)() -> () in AryUITests.o
d: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Syntax highlighting works though (the singleton doesn't have access modifiers, so it's marked as internal which should be perfectly fine for access from the test target)...
The function I'm calling is [in an XCTestCase]:
override func setUp() {
super.setUp()
if !DataModelLayerOperation.isUserLoggedIn() {
//do something
}
}
I'm afraid what you want to achieve is not possible at the moment. I have encountered similar problem and asked my question here. I will soon accept the answer that says:
The UI tests are a separate module from the app, therefore not run
inside your app as a logic test would.
I'm hoping this will be improved in the next Xcode versions.

How to fix linker error " Undefined symbols for architecture i386 from: "_current_task" "?

In kern/task.h, i found the declare:
__BEGIN_DECLS
extern task_t current_task(void);
extern void task_reference(task_t task);
__END_DECLS
But when i call the function current_task() in an iOS application.
I got the linker error like:
Undefined symbols for architecture i386 from:
"_current_task", referenced from:.... in xxx.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
How to fix this problem?
A simple solution:
Use mach_task_self() to replace the function current_task. Still could returns a pointer to the task structure associated with the currently running kernel thread.
But i still want solve the problem above.:(

Resources