Accessing a method from other target to Today Extension? - ios

I have an iOS app with two targets: the main (the app), and a today extension widget. In the main target I have a class called "TimetablesInformation", and if I call a method of that class from the own target everything goes right. But if I tried to access to that class from the other target (the widget) with this:
TimetablesInformation *info = [[TimetablesInformation alloc] init];
[info getTimes:#"1" forLine:lineName];
it crashes with this code error:
2015-12-26 01:48:04.420 Closer Times[15689:307103] __extensionContextClass != nil -
/BuildRoot/Library/Caches/com.apple.xbs/Sources/libextension/libextension
82/libextension/Common/NSExtensionContext.m:164: Unable to find
NSExtensionContextClass (_NCWidgetExtensionContext) in extension bundle -
did you link the framework that declares the extension point?
TimetablesInformation is targeted to both targets on the right inspector of Xcode... So I have no clue about what can I be doing wrong... Could you help me, please?
EDIT:
The getTimes method:
-(NSArray *)getTimes:(NSString *)actualView forLine:(NSString *)lineName {
if ([actualView isEqual: #(1)]){
if ([lineName isEqual: #"Point A - Point B"]) {
self.workingDayTimesArray = #[#"07:00",#"07:30",#"08:00",#"08:30",#"09:00",#"09:30",#"10:00", #"10:30",#"11:00",#"11:30",#"12:00",#"12:30",#"13:00",#"13:30", #"14:00",#"14:30",#"15:00",#"15:30",#"16:00",#"16:30",#"17:00", #"17:30",#"18:00",#"18:30",#"19:00",#"19:30",#"20:00",#"20:30", #"21:00",#"21:30",#"22:00",#"22:30"];
}
}
I have tried with a void method, but I have the same error. If I call a method from the other target (main app) I haven't crashes, but if I do from my widget, yes I do. Have you an idea of the cause?

It means that you or somebody accidentally removed a framework or library from the target you're running.
In my case, I was getting this crash error when somebody removed NotificationCenter.framework from "Linked Frameworks and Libraries" in General tab or "Link Binary With Libraries" in Build Phases tab. Thus, to fix it, you just need to add it again and everything will work.
So when you re-created TodayExtension target it linked NotificationCenter.framework by default. That's why everything worked for you after this.

Related

Use of unresolved identifier false warning Swift 3 xcode

So I edited my post to be more clear. I am new in xcode and Swift 3 and I am facing to a strange problem. My project contains several swift files. I put all my simple common methods to Utils.swift, for instance simple string functions, etc. For many days I had no problems but after a point xcode is all the time complaining with red exclamation marks in all the files where I use my method if I am calling my methods from Utils.swift file: "Use of unresolved identifier 'xxx'".
// debug is a bool variable declared before
Utils.swift:
func log(_ message: String) {
if debug {
print(message)
}
}
ViewController.swift:
log("Error happened")
This gives an error "Use of unresolved identifier 'Log' ". Obviously the function is there so I don't understand why I get this red warning with exclamation mark during coding however when I click on Build, it is successful, and it runs perfectly and the warning is gone. As soon as I start typing again in the code area, the red error comes back. If I build it once more it is successful again. It doesn't make any sense to me.
I thought it is maybe a cache problem, xcode live issues function doesn't recognise my Utils.swift or something like this... so I cleaned the build folder (cmd + shift + option + K), I cleaned the project (Product > Clean), restarted xcode, restarted Mac, removed Utils.swift, re-added Utils.swift to the project but can not get rid of these false warnings during coding but if build the project it is OK. I don't have this problem in my other projects. Any idea?
Okay I found the answer myself. Clicking on the swift file (now Utils.swift) I had to select "Location Relative to Group" in file inspector and set the appropriate target memberships as well.
It is weird that despite the previous 'wrong' settings the build completes with success however it gives an error in the code area.

ObjC class method is not called. GDB playing games?

I have a custom UITableViewController that I am trying to use to manage a UITableView. The flow of my code in the main UIViewController that contains the UITableView goes like below:
_messagesTableVC = [[AllMessagesTableViewController alloc] init];
_allMessageTableView.dataSource = _messagesTableVC;
_allMessageTableView.delegate = _messagesTableVC;
[_allMessageTableView reloadData];
The AllMessagesTableViewController custom UITableViewController class is initialized, it does any processing needed and I set the _allMessageTableView (the UITableView)'s delegates to my custom class.
When I run this code, the program acts as if the custom class is not there but no errors occur. It seems as that NO methods in the custom class are called, no init, no initWithCoder, nothing (I have set breakpoints and checked ;)).
As you can see in the screenshot below, I have set a breakpoint after a custom method refreshData in the custom class that I set to return YES. I assign the return value of refreshData to a local variable test.
In the debugger:
_messagesTableVC custom class does not appear to be nil.
test does not appear to exist.
Not shown here, but when I try to run [_messagesTableVC refreshData] in the debugger it says error: Execution was interrupted, reason: Attempted to dereference an invalid ObjC Object or send it an unrecognized selector.
The process has been returned to the state before expression evaluation.. So is _messagesTableVC actually nil??
What could be causing these problems or is GDB playing games? This is a Messages app extension in case that makes any difference. Thanks.
Update: Here is the code for the custom class init and refreshData
- (instancetype)init {
self = [super init];
if (!self)
return nil;
return self;
}
- (BOOL)refreshData {
return YES;
}
Update2: I created a blank working project and copy pasted the exact files into my original project (because it is an iMessage extension to a big iOS app). It turns out the Xcode is running the older build of the app even after I cleaned the project and changed the UITableView delegate to supply a different text.
I created a Messages Extension for the same project in the past and deleted the target while keeping the files in the project. When I re-added the Messages Extension to the project, Xcode kept running the older build of the app.
I fixed the issue with Xcode running an older version of the app by:
Clean All
Delete Messages Extension target from project
Backup existing Message Extension code to a directory outside the project. Then delete the Messages app group and directory from the project.
Delete the Messages Extension build scheme from project.
Delete project Derived Data directory.
Restart Xcode, create new Messages Extension target in project, and import saved code.

Xcode 6.0.1 Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

I am getting this error on archive:
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
How to solve it?
Please see the screenshot.
This problem occurs when the Swift optimization level is not set to None for Release. Set the value to None and the issue goes away.
Open up your project and click on the projects root directory.
Click the build settings tab.
Search for Swift Compiler - Code Generation and under Optimization Level make sure Release is set to None.
EDIT
After upgrading to Xcode 6.1 these instructions caused other issues when archiving (building for debug/device worked fine). Setting the optimization to Fastest allowed me to archive again. There are apparent issues with Swift compiling still (archiving specifically).
Can't archive working 6.0.1 Swift project in Xcode 6.1 / Segmentation fault: 11
EDIT
I was not able to fund the Build Settings tab, until I read this answer.
how to find the build settings tab
This occurred for me when I had two of the exact same files, and also when I was missing I file I didn't know I had deleted. I clicked on the error message, and just above the error, it shows you what file you have more than 1 of or are missing.
You can click the Product in the navigation and choose the "Clean" button; it will clean all compile error in your project. Then, you can debug for the latest error.
Deleted files reference keep in Build Phase and that's why it gives this error. Remove reference from there as well.
Project> Target > Build Phase
Under this section you will find your deleted files in red colour. Remove these files error will resolve.
I am not sure if it has one solution.
I recommend you to check the differences between your last git commit, and comment on/off the changes.
In my case, my code was
let anArray = ResultDict["ResultSet"] as [[NSDictionary : AnyObject]]
for aDict : NSDictionary in anArray {
let anObject = ObjectType(ObjectDict: aDict)
objectList.addObject(aDict)
}
no warning on the line, i got the same exit 1 compile error
then i changed it to the below it has compiled.
let anArray = ResultDict["ResultSet"] as [[NSDictionary : AnyObject]]
for aDict in anArray {
let anObject = ObjectType(ObjectDict: aDict)
objectList.addObject(aDict)
}
I don't know if this is really an answer, but...
I had the same issue. App worked when building/running, but archiving failed with "...swiftc failed with exit code 1", with no other helpful message at all. Luckily, when I tried to build my app with Nomad's ipa build, I got:
The following build commands failed:
CompileSwift normal arm64 /path/to/erroneous/TableViewController.swift
So I started commenting out sections of that file and tracked the problem down to a tuple assignment.
// MARK: - Table Data
private var tableData: [(sectionName: String, item:ListItem)] = []
private func refreshTableData() {
// let labor = ("Labor", laborListItem) // DOESN'T ARCHIVE
let labor = (sectionName: "Labor", item: laborListItem) // ARCHIVES
tableData = [labor]
tableView.reloadData()
}
So apparently the compiler wanted the elements in thast tuple named (as defined by the type of tableData).. but only for archiving? The Dumb thing is, I use this same pattern in other view controllers, and the compiler seems to be fine with those.
For the record my Code Generation -> Optimization Level was set to None for debug and release.
Hope this helps someone! It took hours to figure this out.
It happened to me when I didn't put the parenthesis at the end of a call of a function:
let var = self.getNextPrimeNumber
solved it by:
let var = self.getNextPrimeNumber()
In my case, it was caused by duplicate files, using the same name, in my project directory. As soon as I removed them, the error was gone.
This happened to me when I used static inline function from swift file
The function looks like this
static inline void openURLInSafari(NSString * _Nonnull urlString) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];}
I just had the same thing occur. I hunted down the cause to one file that caused the error even when empty. Examining the file, I discovered it had the wrong character set. When I set it to UTF-8, the error vanished. I think that it was decoding it with the wrong character set.
From this I surmise that the error simply indicates that something has happened that the compiler was unprepared for. Sorry that isn't very helpful to most people, but it may help to check your characters sets.
one more case that can lead to this error which just took me hours to track down: a failable initializer that always returns nil.
i had an initializer that looked like this:
init?(object: MyObject) {
if object.importantProperty {
// initialize
}
return nil
}
when what i meant was:
init?(object: MyObject) {
if object.importantProperty {
// initialize
}
else {
return nil
}
}
fixing the initializer made the error go away.
If using Core Data:
I had a Core Data entity for which I created the NSManagedObject subclasses (with Xcode's help). In addition, the entity was configured to generate code automatically (see screenshot), so basically 2 classes existed during runtime. Just switch the option to Manual/None and it won't generate it.
This error occurred for me after I noticed that a few of my .swift files were inexplicably in the wrong directory -- one level above my Xcode project directory. When I noticed this, I moved them into the main project directory and cleaned the project, thinking everything would be fine. However, upon building the project I got the above-mentioned "failed with exit code 1" error. Just above the error message it listed the files I had just moved, indicating that it couldn't find them in the directory where they used to be. In addition to the error message, the files I moved were now showing up as red in the file navigation pane.
For each of the files in question what I did to resolve this was:
- Select the file from the list of files in the Xcode file navigation pane,
- Click on the little page icon in the rightmost pane of Xcode, which opens a file attributes pane,
- Click on the little folder icon underneath where it says "Location" in the file attributes pane,
- Choose the new location for the file,
- RESTART Xcode for the above changes to really do anything.
this error comes from missing files so the compiler couldn't find the files and keep alerting.
Follow these steps to rebuild your app:
Look up for the red and invisible files within workspace
Remove their reference
Re-add files
Re-compile
I experienced this error after performing a git merge. I solved new Xcode warnings and the project can be compiled.
Xcode 7.2.1 is used in my case.
In my way the error was due to UIDevice.currentDevice() in ((UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0)
After commenting this all starts work fine.
XCode 7.2
in my case , at your project target Build Setttings, in Other Swift Flags,jsut delete the String "-serialize-debuggin-options"
enter image description here
I had a resolution very similar to RyanM, where with an excess of hubris I tried to assign a variable to the default value of an inner function:
Fails to compile (though does not crash SourceKit):
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
func itemCell(_ indexPath: IndexPath = indexPath) -> UITableViewCell {//...}
Succeeds:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
func itemCell(_ indexPath: IndexPath) -> UITableViewCell {//...}
One possible reason that this can happen is perhaps because you have deleted a file but not removed references to it. This will mess up the pbxproj file. I would check to see if that is the case.
check "Development Pods" Folder all listed Frameworks path.
In my case swift development snapshot was selected instead of xcode 9.2. here are the steps and image.
keep xcode on screen and click on xcode top menu bar.
Than go to toolchains option and check on xcode 9.2. thats it.
Happy Coding!!!
So, I had the above and narrowed it down to a TFS issue with locking the file but only when I pasted or did any other edits besides small copies or manual typing. I noticed the original file would compile, but my edits wouldn't, even though they were syntactic OK. Also related is unable to save document: xcode The document "..." could not be saved
The fix for both was:
Duplicate working version.
Paste fully-merged new code into duplicate.
Copy and paste old file over new one. (I personally just renamed the old one to something else, then pasted duplicate and renamed it, too. Guessing both work since I pasted directly earlier for reverts during tests to see).
Voila. Lazy way to bypass merge-locking issue. Apparently full file-pastes are just fine, while edits aren't. Shared since the other answers don't seem to be as lazy as this. ;)
Note: I am suspecting a non-UTF-8 character made its way somewhere, but pastes worked in older versions so I don't know where, or if relevant.
In my case, the error was the result of missing files that were generated by Xcode. I tried the regular clean Opt+Shift+K and it didn't clean up all the errors. I found a post on the Apple Developer site that recomended going to the Product Menu in Xcode, holding down the opt key, and selecting Clean Build Folder. This appears to be a more comprehensive build as it pops up a modal dialog for you to confirm.
Just go to the "project setting" and click on the "build phaces" after that you will find targets in that u have to delete the test file like my project name "WER" so its showing like this WER&TEST so just delete that and clean ur project and run .........

Xcode 5 error: "Malformed or corrupted AST file: mismatched umbrella header in submodule"

After adding StoreKit to my Xcode 5 project, I now see...
"Malformed or corrupted AST file: mismatched umbrella header in submodule"
...whenever I've imported any header from StoreKit. I haven't changed those system headers, and clearing derived data and the usual Clean Build Folder fix doesn't work either, nor does restarting Xcode change anything.
I see in the Clang sources where the error is being reported, but I can't tell why. Here's the relevant Clang code from http://clang.llvm.org/doxygen/ASTReader_8cpp_source.html:
case SUBMODULE_UMBRELLA_HEADER: {
03728 if (First) {
03729 Error("missing submodule metadata record at beginning of block");
03730 return true;
03731 }
03732
03733 if (!CurrentModule)
03734 break;
03735
03736 if (const FileEntry *Umbrella = PP.getFileManager().getFile(Blob)) {
03737 if (!CurrentModule->getUmbrellaHeader())
03738 ModMap.setUmbrellaHeader(CurrentModule, Umbrella);
03739 else if (CurrentModule->getUmbrellaHeader() != Umbrella) {
03740 Error("mismatched umbrella headers in submodule");
03741 return true;
03742 }
03743 }
03744 break;
03745 }
It evidently compares my imported umbrella header
#import <StoreKit/StoreKit.h>
to something else, but I can't determine what that something else is.
Has anyone else encountered this, and hopefully found a way to resolve it?
I was able to encounter this problem, following the direction mentioned by John above doesn't work for me. I was able to solve this problem by doing the following:
close all open XCode projects.
Delete all the folders inside Derived Data folder.
How to go to Derived Data folder? just right click on your Product build and show finder, browse through the hierarchy of folders and look for Derived Data.
Hope this helps. This seems to be a bug in Xcode? but not sure.
This solved it for me:
go to project build settings
scroll down to LLVM 5.1 Language Modules
set Enable Modules (C and Obj C) to NO
In Xcode go to Window->Organizer->Projects select your project and press delete button next to Derived data. Just did it (and it worked) with information the following question:
fatal error: malformed or corrupted AST file - Xcode
In your Project folder there would be couple of folders named Derived Data and build. Just remove those folders and the problem would be resolved. These folders get created automatically once you open your XCode.

iOS CoreData: Linker Error even after adding it to target's build phases [duplicate]

I am trying to implement the SVProgressHUD activity indicator. I copied the classes to my project and added the following code to my appDelegate but can't figure out why it crashes.
I get they following error and am not sure where to look to fix it:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_SVProgressHUD", referenced from:
objc-class-ref in QuotesAppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is the code:
#import "SVProgressHUD.h"
#implementation QuotesAppDelegate
- (void)startLoading
{
//call this in your app delegate instead of setting window.rootViewController to your main view controller
//you can show a UIActivityIndiocatorView here or something if you like
[SVProgressHUD show];
[self performSelectorInBackground:#selector(loadInBackground) withObject:nil];
}
- (void)loadInBackground
{
//do your loading here
//this is in the background, so don't try to access any UI elements
[self populateFromDatabase];
[SVProgressHUD dismiss];
[self performSelectorOnMainThread:#selector(finishedLoading) withObject:nil waitUntilDone:NO];
}
- (void)finishedLoading
{
//back on the main thread now, it's safe to show your view controller
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[self copyDatabaseIfNeeded];
[self startLoading];
}
Edit
The answer I provided (see My original answer) only fixes the problem, but it's not the correct solution. For correct solutions see Jim answer
It sounds like SVProgressHUD.m isn't enabled for your target. Click on
it in the project navigator in the left-hand pane, then look in the
file inspector in the right-hand pane to make sure there's a tick next
to the target you are building.
or Parth Bhatt link.
For the sake of completeness
Experimenting a little bit, I found that when you drag and drop file or directory within your project, Xcode (4.3.1) asks you to select the right option to add those files or dir to your project. Make sure that that "Add to targets" option is checked.
If you have missed to check that option, you need to following these steps:
Select YourProjectName
Select TARGETS
Select Build Phases
Add .m classes in Compile Sources section
My original answer
If you dragged those classes in your project, it could be the problem.
To avoid that compiling error, use "Add Files to YourProjectName" instead.
Suppose you have a directory that contains .h and .m files called "SVProgressHUD" in your desktop.
Now you have to:
Remove previous files (both .h and .m)
Click with right click in your project
Select "SVProgressHUD" dir with "Add Files to YourProjectName" (select the following check box options: Destination Copy items... and Folders Create groups for any...)
Hope it helps.
It sounds like SVProgressHUD.m isn't enabled for your target. Click on it in the project navigator in the left-hand pane, then look in the file inspector in the right-hand pane to make sure there's a tick next to the target you are building.
Checkout this link. Refer to accepted answer in this link:
Undefined symbols for architecture i386: _OBJC_CLASS_$_SKPSMTPMessage", referenced from: error
If it still doesnt help then refer to Allen Pike's answer in the above link. try removing and adding back QuartzCore framework in your app.
Hope this helps you.
check if you have any objects that you could previously delete without knowing it
check if your all objects are connected , for example if you have a MapView but without a connection, it crashes down
if this doesn't work, try with cleaning the app, or just restarting your iPhone and Xcode
I resolved this issue by changing in Player Settings in the Unity Editor.
menu path:
PlayerSettings > OtherSettings > Scripting Backend change to IL2CPP from Mono2x.
Second change was to change the Architecture to universal.

Resources