Objective C interface declaration - macos

i'm trying a simple academic program where an interface is declared as:
#import <objc/Object.h>
#interface Saludador:Object{
char* saludo;
}
- init;
- (void)setSaludo:(char*)unSaludo;
- (void)setSaludo:(char*)unSaludo y:(char*)unaColetilla;
- (void)saluda;
#end
When I try to compile the .m file i get the error:
error: cannot find interface declaration for 'Object', superclass of 'Saludador'
I really don't know why, i'm compiling on the terminal window in a mac OSX 10.9.
thanks for the help

Object is the OBJC_ROOT_CLASS for ObjC 1.0, for ObjC 2.0 use NSObject and #import <Foundation/Foundation.h>. You'll also have to add the -framework Foundation as a compiler flag if you are compiling using clang or gcc on the command line.
See the header file Object.h:
#if __OBJC__ && !__OBJC2__
__OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_NA)
OBJC_ROOT_CLASS
#interface Object
Note the #if __OBJC__ && !__OBJC2__.
EDIT:
I actually managed to find that: When writing code that is based upon the Foundation framework, that root class is typically NSObject in an old document... The OBJC_ROOT_CLASS got me confused, so even if you're using ObjC 1.0 it's still NSObject.

Related

Platform Migration: Error when compiling project

A few weeks ago I started a Firebase course with flutter, and I was programming on a Windows computer, and now I've been using a Mac for a few days, to learn how to make firebase with iOS too. However, I have received these errors, and I do not know if I am missing a file, lines of code or if I have obsolete code. I tried some solutions I found on the internet, like deleting the files pubspec.lock, podfile, podfile.lock, reinstalling using pod init and pod install, but none of these solutions managed to solve the problem. I know very little about Swift / Objective-C, and this project is connected (android) on firebase.
/Users/mobileteam/Desktop/pasta_mary/aikoBot/aiko_bot/ios/Pods/FirebaseCrashlytics/Crashlytics/Shared/FIRCLSFABHost.m100:11: warning: 'UI_USER_INTERFACE_IDIOM' is deprecated: first deprecated in iOS 13.0 - Use -[UIDevice userInterfaceIdiom] directly. [-Wdeprecated-declarations]
switch (UI_USER_INTERFACE_IDIOM()) {
^
In module 'UIKit' imported from /Users/mobileteam/Desktop/pasta_mary/aikoBot/aiko_bot/ios/Pods/FirebaseCrashlytics/Crashlytics/Shared/FIRCLSFABHost.m:20:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIDevice.h:97:36: note: 'UI_USER_INTERFACE_IDIOM' has been explicitly marked deprecated here
static inline UIUserInterfaceIdiom UI_USER_INTERFACE_IDIOM() API_DEPRECATED("Use -[UIDevice userInterfaceIdiom] directly.", ios(2.0, 13.0), tvos(9.0, 11.0)) {
^
1 warning generated.
/Users/mobileteam/Desktop/pasta_mary/aikoBot/aiko_bot/ios/Runner/AppDelegate.swift:14:18: error: cannot override with a stored property 'window'
override var window: UIWindow?
^
Flutter.FlutterAppDelegate:2:14: note: attempt to override property here
open var window: UIWindow! { get set }
^
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description

Xcode compile error with PostgreSQL headers

I am trying to include the following PostgreSQL headers files into my Xcode 7.2 project:
#import "postgres.h"
#import "pg_type.h"
#import "libpq-fe.h"
The app is written in Swift. I have an Objective-C bridging header. If I just import "libpq-fe.h" there are no compile errors.
When I try to import "postgres.h" and "pg_types.h" to get access to certain constants, I get an error with a PostgreSQL file: "c.h"
"Typedef redefinition with different types ('size_t' (aka 'unsigned long') vs 'long')
The previous definition is in OS X 10.11 > user/include > MacTypes.h
So there are two headers with the same definition:
PostgreSQL c.h
typedef size_t Size
OSX MacTypes.h
typedef long Size
If I comment out the definition in the PostgreSQL file then the project compiles. But I would rather not have to do that.
Does anyone know a way around this?
I read somewhere about using a 'backend header' but so far I have not been able to figure this out.
Thanks in advance.

OCMock link error

I'm trying to get a simple OCMock test for OSX up and running, but can't seem to get the install right. I believe I've followed the instructions, but the test build is failing at the link step.
Within fooTests.m:
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#interface fooTests : XCTestCase
#end
#implementation fooTests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testOCMockPass {
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:#"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
STAssertEqualObjects(#"mocktest", returnValue, #"Should have returned the expected string.");
}
#end
But on build, I get the following warnings/errors:
fooTests.m:56:5: Implicit declaration of function 'STAssertEqualObjects' is invalid in C99
Undefined symbols for architecture x86_64:
"_STAssertEqualObjects", referenced from:
-[fooTests testOCMockPass] in fooTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've got "Link Binary with Library" linking with XCTest & OCMock in the test build phase. OCMock.framework is in the base directory, which is also in the search path for frameworks and for headers. Can anyone assist in telling me what I'm doing wrong please?
It looks as though the compiler doesn't know what STAssertEqualObjects() is (i.e. I haven't included something) and hence it doesn't know what to link with, hence the other 2 errors. I just don't know what else I need to include.
This is not an OCMock problem. You are using XCUnit (the Xcode 5 unit testing framework), but you are calling STAssertEqualObjects (from OCUnit, the Xcode 4 unit testing framework). Simply change that to XCTAssertEqualObjects.

Xcode error "Duplicate Symbol" causing Apple Mach-O Linker Error

duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToMeViewController.o
duplicate symbol _showGLobalCompany in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
ld: 3 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am getting the error above in xcode only when I try to build in simulator (on any iOS device I can build without error). I have three classes:
1.LTGlobalResultsViewController
2.LTJumpToMeViewController
3.LTJumpToPositionViewController
All three were created in xcode but both 2 & 3 have been modified outside of xcode and then rebuilt.
The #property bool leagueTableLoaded is defined in the header for all three. it is declared as:
#property bool leagueTableLoaded;
What is it exactly that is causing this error? I have tried the following:
I have tried renaming leagueTableLoaded in different classes but this doesn't fix it.
I have tried deleting my Derived Data files manually in library/developer/xcode folder.
According to other questions I have checked if I am importing a .m file. This is not the case. Apple Mach-O Linker error ("duplicate symbol")
Any other suggestions or advice?
Thanks,
James
ADDITION: As requested please find all the extracts from my .h and .m files that reference leagueTableLoaded or any of the variants I created when trying to get round this error:
LTJumpToMeViewController.h
#property bool leagueTableLoadedMe;
LTJumpToMeViewController.m
#implementation LTJumpToMeViewController
bool leagueTableLoaded = false;
LTGlobalResultsViewController.h
#property bool globalLeagueTableLoaded;
LTGlobalResultsViewController.m
#implementation LTGlobalResultsViewController
bool leagueTableLoaded = false;
LTJumpToPositionViewController.h
#property bool leagueTableLoadedPos;
LTJumpToPositionViewController.m
#implementation LTJumpToPositionViewController
bool leagueTableLoaded = false;
I can provide more information if required!
For me a duplicate symbol error came up when I absent mindedly included a .m file instead of a .h (Why does Xcode's autosuggest even show me .m files?!)
In this end this was being caused by the leagueTableLoaded bool being defined in both LTGlobalResultsViewController.m and LTJumpToPositionViewController.m.
Removing it from one of them fixed the issue. Although I'm not sure why it was there in the first place! Hope this helps anyone else who experiences the same issue! James
Xcode error “Duplicate Symbol” causing Apple Mach-O Linker Error is caused by duplicate symbols in Project. Steps to avoid error
Go to project -> Target ->Build Phases ->Compile sources
Check for the duplicate file (implementation file)
Delete the file and add it again
Clean and run project again
This worked for me. Hope it helps
In second view controller, you mistakenly #import "First.m", check it must be first.h file so replaces this with first.h. It's working for me.

Unknown type name 'namespace' Xcode Boost

I want to use boost in my Xcode project.(Xcode version 4.3.2)
I had build the boost from the MacPorts, and made the environment variables set.
But when I build the prj, there was the error:
Unknown type name 'namespace'
and the error code below:
// This file is automatically generated. Do not edit.
// ['../../libs/compatibility/generate_cpp_c_headers.py']
// Wed Jul 23 12:11:19 2003 ('GMTST', 'GMTST')
#ifndef __CSTDDEF_HEADER
#define __CSTDDEF_HEADER
#include <stddef.h>
namespace std {
using ::ptrdiff_t;
using ::size_t;
}
#endif // CSTDDEF_HEADER
the auto generated code is C++, not Objective-C.
Objective-C compiler rejects the invalid keyword 'namespace'.
To make it work change you project settings as follows:
- go to you Project Settings and choose the Target
- select Build Settings -> Apple LLVM compiler X.X - Language -> Compile Sources As and set it to Objective-C++ which allows mixture of Objective-C and C++.

Resources