I am pretty new to OSX programming, or to the use of ObjC. I've done a fair bit of C en C++ in the past, mainly in combination with VTK.
I am trying to compile a very simple program, where I copied an init method from Apple demo code. I am pretty sure I'm forgetting something. My project is a default Cocoa app, and I made a class MyRoster which for some reason causes linking problems. The output during compilation is the following (if anyone needs more, just say so):
Ld /Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug/Rooster.app/Contents/MacOS/Rooster normal x86_64
cd /Users/mark/Documents/Programming/Rooster
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug -F/Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug -filelist /Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Intermediates/Rooster.build/Debug/Rooster.build/Objects-normal/x86_64/Rooster.LinkFileList -mmacosx-version-min=10.7 -framework Cocoa -o /Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug/Rooster.app/Contents/MacOS/Rooster
Undefined symbols for architecture x86_64:
"_CalEventsChangedNotification", referenced from:
-[MyTasksCalendar init] in MyTasksCalendar.o
"_CalEventsChangedExternallyNotification", referenced from:
-[MyTasksCalendar init] in MyTasksCalendar.o
"_OBJC_CLASS_$_CalCalendarStore", referenced from:
objc-class-ref in MyTasksCalendar.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The base app compiles fine; the problem is this modified init method:
- (id)init
{
self = [super init];
if (self) {
// Add the receiver as an observer of Calendar Store notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(eventsChanged:) name:CalEventsChangedExternallyNotification object:[CalCalendarStore defaultCalendarStore]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(eventsChanged:) name:CalEventsChangedNotification object:[CalCalendarStore defaultCalendarStore]];
// Create a predicate to use to fetch the events
NSInteger year = [[NSCalendarDate date] yearOfCommonEra];
startDate = [[NSCalendarDate dateWithYear:year month:1 day:1 hour:0 minute:0 second:0 timeZone:nil] retain];
endDate = [[NSCalendarDate dateWithYear:year month:12 day:31 hour:23 minute:59 second:59 timeZone:nil] retain];
NSPredicate *eventsForThisYear = [NSPredicate eventPredicateWithStartDate:startDate endDate:endDate calendars:[[CalCalendarStore defaultCalendarStore] calendars]];
// Fetch all events for the current year
events = [[NSMutableArray array] retain];
[self addEventArray:[[CalCalendarStore defaultCalendarStore] eventsWithPredicate:eventsForThisYear]];
}
return self;
}
My question: why would this not link? The called methods are in standard Apple libraries, so what gives?
Many thanks,
Mark
It looks like you're missing the CalendarStore framework from your project - try adding /System/Library/Frameworks/CalendarStore.framework to your project.
Related
Recently I updated my Xcode from 5 to 6.4 version and the simulator does not give any sound but some error messages. The simplest codes don't run well, the app itself starts in simulator but there is no audio, the problem might be in some setting because all the codes and programs I have ran well before. I use a brand new mac mini so I imported these codes from a different, older one.
If anyone came across with problems like this please help me!
The error is this:
2015-08-01 09:03:56.730 Testbutton[496:11659] 09:03:56.730 ERROR: 98: Error '!obj' trying to fetch default input device's sample rate
2015-08-01 09:03:56.731 Testbutton[496:11659] 09:03:56.731 ERROR: 100: Error getting audio input device sample rate: '!obj'
2015-08-01 09:03:56.731 Testbutton[496:11659] 09:03:56.731 WARNING: 230: The input device is 0x0; '(null)'
2015-08-01 09:03:56.731 Testbutton[496:11659] 09:03:56.731 WARNING: 234: The output device is 0x26; 'AppleHDAEngineOutput:1B,0,1,2:0'
2015-08-01 09:03:56.732 Testbutton[496:11659] 09:03:56.732 ERROR: 296: error '!obj'
2015-08-01 09:03:56.732 Testbutton[496:11659] 09:03:56.732 ERROR: 113: * * * NULL AQIONode object
2015-08-01 09:03:56.732 Testbutton[496:11403] 09:03:56.732 ERROR: 296: error -66680
2015-08-01 09:03:56.732 Testbutton[496:11403] 09:03:56.732 ERROR: >aq> 1595: failed (-66680); will stop (11025/0 frames)
2015-08-01 09:03:56.736 Testbutton[496:11659] 09:03:56.736 ERROR: 703: Can't make UISound Renderer
The code is this:
// ViewController.m
// Testbutton
#import "ViewController.h"
#interface ViewController ()
{
AVAudioPlayer *_audioPlayer;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Construct URL to sound file
NSString *path = [NSString stringWithFormat:#"%#/horn.wav", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
// Create audio player object and initialize with URL to sound
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
}
- (IBAction)buttonPressed:(id)sender {
[_audioPlayer play];
}
- (void)dealloc {
[audioPlayerPointer release];
[super dealloc];
}
#end
and there is a header file too with this:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface ViewController : UIViewController
{
AVAudioPlayer* audioPlayerPointer;
}
- (IBAction)buttonPressed:(id)sender;
#end
AVAudioPlayer needs both a valid input and output in order to set itself up. This isn't a problem on a real device (which has these things built in), but it is a problem in the simulator where there's no built-in microphone on the MacMini.
If you have a microphone, try plugging it into the "line in" port on your MacMini (I found this probable solution in the comments of the answer to this very related question). Make sure to select "line-in" as the input in System Preferences, too.
I'm trying to convert the results of a valueForKeyPath into an array of UIImages. When trying to do it I get met with this error
Undefined symbols for architecture i386:
"TToFC9TableView19TableViewControllers6photosGSqGSaCSo7UIImage", referenced from:
__TFC9TableView29JustPostedTableViewController11fetchPhotosfS0_FT_T_ in JustPostedTableViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here's my attempt at the code in swift:
The propertyListResults is an NSDictionary, and the parameter in valueForKeyPath is a String
var photos : AnyObject = (propertyListResults as AnyObject).valueForKeyPath(flickrFetcher.FLICKR_RESULTS_PHOTOS)
self.photos = photos as? UIImage[]
And the working Objective-C version of the code is
NSArray *photos = [propertyListResults valueForKeyPath:FLICKR_RESULTS_PHOTOS];
self.photos = photos
If you run swift-demangle on "__TToFC9TableView19TableViewControllers6photosGSqGSaCSo7UIImage__" you get:
#objc TableView.TableViewController.photos.setter : (ObjectiveC.UIImage[])?
That means that the linker is not finding a setter for photos on TableViewController. It seems that you are using a TableViewController instead of your own subclass that has a photos property.
Also, photos as? UIImage[] returns an Optional because it is possible for it to fail. You should do the following:
if let images : [UIImage] = photos as? [UIImage] {
self.photos = images
}
This checks if photos can be converted to [UIImage]. If it can, it assigns it to self.photos
Edit: Updated UIImage array syntax to the new array syntax in the beta 3
In an ARC project, I'm setting a __weak ivar (declared as id __weak weakLayer;) to a CALayer which is retained by it's superlayer. Most times this works. Sometimes, the weak ivar tests as nil. I wrote some test code to simplify debugging that demonstrates the problem. I expect this to be an infinite loop but it breaks out, usually in less than 20 iterations. The number of iterations required to break out is not consistent.
array = [NSMutableArray array];
while (1) {
CALayer *layer = [CALayer layer];
[array addObject:layer];
weakLayer = layer;
if (!weakLayer) {
NSLog (#"nil");
break;
}
NSLog(#"not nil");
}
If I drop a breakpoint with an action of po weakLayer inside the if, it prints a valid object. I have tested on Xcode 4.3.3 and 4.4 with the Lion and Mountain Lion SDKs.
3 people (including myself) have now confirmed this to work on 10.8, but not on 10.7.4.
I am trying to create an AVCaptureSession. I based my code on the WWDC 2011 video, number 419.
I have the following line which is exactly the same as the code in the WWDC 2011 video and it also identical to code here http://www.bardecode.com/en/knowledge-base/214-detailed-description-of-work-around-for-avcapturevideopreviewlayer-problem-in-ios-41.html
// Create a device input with the device and add it to the session.
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
error:&error];
But Xcode says that the &error is the use of an undeclared identifier.
This is because you've not defined the NSError error variable, that you're providing the address of when you use &error.
If you define the variable via...
NSError *error = nil;
...on the line before, all should be well.
As a bit of an explanation, if you look at the signature for the AVCaptureDeviceInput deviceInputWithDevice:error: method you'll see the following:
+ (id)deviceInputWithDevice:(AVCaptureDevice *)device error:(NSError **)outError
In other words, this method expects the address of an NSError pointer variable to be provided as the ourError parameter.
When I run the app in the iPhone Simulator, everything works just fine .. but with time I'll try to get my iPhone
Thread 1: Application Received
signal:" Sigbart 1"
why?
Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
golfbaner *detailViewController = [[golfbaner alloc] initWithNibName:#"Golfbaner" bundle:nil];
detailViewController.golf = [banenavn objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
XCode says it's HERE:
[self.navigationController pushViewController:detailViewController animated:YES];
it goes wrong
I can admit that I'm quite a beginner.... lol
seems to be u are new bee.so here i assume u would be created the golfbaner with nib file .so it would be same as filename for nibname.
Golfbaner.NIB is not with your project.//check out this
maybe like golfbaner.NIB
so use
golfbaner *detailViewController = [[golfbaner alloc] initWithNibName:#"golfbaner" bundle:nil];
Most likely is that detailViewController is nil. If you look at the console output it will tell you for certain.
The reason its nil on hardware is that the file system is case sensitive on hardware and hence
golfbaner *detailViewController = [[golfbaner alloc] initWithNibName:#"Golfbaner" bundle:nil];
"Golfbaner" != "golfbaner"
Check your nibname for case match. I suspect its "golfbaner.xib".
See iOS Objective-C Image file name/path different behavior betwewen simulator and device
As a style point class names should be capitalised otherwise it makes a class hard to separate from a variable when reading code.
It may be spelling mistake after #"Golfbaner"
just copy nibfile name and paste it.