Getting errors after installing ngx-bootstrap version 5.0.0 in angular v 8.1.3 project. What should I do ? Here are the following errors: - angular8

ERROR in node_modules/ngx-bootstrap/component-loader/component-loader.class.d.ts(26,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/modal/modal-backdrop.component.d.ts(4,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/modal/modal-backdrop.component.d.ts(5,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/modal/modal-backdrop.component.d.ts(6,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/modal/modal-backdrop.component.d.ts(7,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/modal/modal.directive.d.ts(10,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/modal/modal.directive.d.ts(11,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/modal/modal.directive.d.ts(31,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ngx-bootstrap/positioning/positioning.service.d.ts(38,9): error TS1086: An accessor cannot be declared in an ambient context.

Related

Do "atomic" and "nonatomic" attributes on properties have any effect if you use a custom getter/setter?

If I have a property declared in a class:
#interface MyClass : NSObject
#property (atomic) NSString *myString;
#end
And I implement custom getter and setter methods:
#implementation MyClass
- (NSString *)myString
{
// return something
}
- (void)setMyString
{
// do something
}
#end
Does the "atomic" attribute on the property declaration actually do anything? Or is it only used if an automatic getter/setter is actually created by the compiler?
Assuming the "atomic" and "nonatomic" keywords don't do anything for properties with custom getters and setters, is there any convention for what attribute we should use for those properties?
Does the atomic attribute on the property declaration actually do anything? Or is it only used if an automatic getter/setter is actually created by the compiler?
atomic is used only when a getter/setter is synthesized by the compiler. It is also used to check the consistency of accessors for readwrite properties:
Because the internal implementation and synchronization of atomic accessor methods is private, it’s not possible to combine a synthesized accessor with an accessor method that you implement yourself. You’ll get a compiler warning if you try, for example, to provide a custom setter for an atomic, readwrite property but leave the compiler to synthesize the getter.
is there any convention for what attribute we should use for those properties?
Apple does not require you to follow any convention, but you could use atomic and nonatomic attributes to document your own code. This would let readers of your code learn about the behavior of your accessors without looking into their implementation.

Throwing method cannot be a member of an #objc protocol because it returns a value of type 'Bool'

I get following error:
Throwing method cannot be a member of an #objc protocol because it returns a value of type 'Bool'; return 'Void' or a type that bridges to an Objective-C class
When defining Swift protocol which also needs to be bridged to Objective-C:
#objc public protocol Saving {
func save() throws -> Bool
}
Is there an other way to define Swift method which can return Bool, potentially throw an error and be Objetive-C compatible?
As indicated in the comments, the following in Swift:
func save() throws
will be translated into:
(BOOL)saveAndReturnError:(NSError **)error
in Objective-C. Which explains the limitation.
I know that in the save() example, it might not make much sense to return a Bool as well as throwing, but I disagree with the comment about it not making sense at all. There might be other use cases where it makes sense. Fx. the inverse example; loading Bool's by using an identifer. Loading a Bool might return true/false or throw if loading fails, fx. if the identifier was not found when trying to load.
However unfortunately we cannot do this because of how Swift and Objective-C is being bridged.

Mixing objective-c and swift: fatal error: use of unimplemented initializer 'init(target:action:)' for class

my code contains both objective-c and swift classes and so far, everything worked pretty well. however, i added a custom gesture recognizer that inherits from UIGestureRecognizer. My code compiles but when I try to run it I get the following error:
fatal error: use of unimplemented initializer 'init(target:action:)' for class
I assume that this error originates in the mix of objective-c and swift code but I have no clue how to solve it (besides rewriting everything in one of the languages). Your help would be highly appreciated.
That's quite normal, as
init(target target: AnyObject?,
action action: Selector)
is exposed as a designated initializer in the documentation.
However, it's strange that in the UIKit public sources it's declared as follows:
public init(target: AnyObject?, action: Selector) // designated initializer
Conclusion: even though it's not declared with the required keyword, you must implement it for your subclass. It may simply call the super's init(target: AnyObject?, action: Selector).
Good luck.
Extending to what Arthur mentioned, this is how Apple has defined it for init(coder aDecoder: NSCoder) making it required for subclasses to implement.
The NSCoding protocol requires that conforming types implement the
required initializer init(coder:). Classes that adopt NSCoding
directly must implement this method. Subclasses of classes that adopt
NSCoding that have one or more custom initializers or any properties
without initial values must also implement this method. Xcode provides
the following fix-it to serve as a placeholder implementation:
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Is UIColor's CGColor accessor a property or method?

I found a curious bit of code near the bottom of UIColor.h (lines 69-71 in my SDK):
// Access the underlying CGColor or CIColor.
#property(nonatomic,readonly) CGColorRef CGColor;
- (CGColorRef)CGColor NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED;
Why is CGColor defined as both a property and a method? Is it truly a property but just defined as a method so they use the two annotations?
the method is the synthesized getter method of the property, which needs to be declared to be able to assign the return annotations

warning: incompatible Objective-C types assigning superClass to subClass

Assume a valid super class, and a valid subclass ie the classes work.
the following line in a constructor of the subclass
self = [super init] ;
throws the following warning
// warning: incompatible Objective-C types assigning 'struct Animal *', expected 'struct Cat *'
Any ideas on how to fix this and remove the warning ?
Cheers
Do you provide a custom init-Method in your superclass?
Check the return type of this method. Is it (Animal *)? If so, change this to (id).
Init methods should return (id)