realm swift: how could I trap on object being invalidated? - swift

I'm attempting to add a watcher for isInvalidated on an object of interest like so:
cancellable = images.publisher(for: \.isInvalidated, options: [.new])
.sink { newValue in
print("property changed")
}
which yields
Undefined symbols for architecture x86_64:
"property descriptor for (extension in RealmSwift):__C.RealmSwiftEmbeddedObject.isInvalidated : Swift.Bool", referenced from:
l_keypath in ContentCardView.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
at link time.
How would I add a [programmatic] watchpoint for invalidation of an object in realm?
PS a simpler way out via lldb does not work either
(lldb) watch images.isInvalidated
error: command 'watchpoint' did not recognize 'images .isInvalidated' as valid (subcommand might be invalid).
(lldb) watch images.invalidated
error: command 'watchpoint' did not recognize 'images .invalidated' as valid (subcommand might be invalid).
(lldb) wa s v images.invalidated
error: "invalidated" is not a member of "(Foo) images"
(lldb) wa s v images.isInvalidated
error: "isInvalidated" is not a member of "(Foo) images"

Related

Swift: Type cast results in 'Symbol not found'

In a Swift test bundle, I use the following line to get a class object of a class, which is defined in a dynamically loaded bundle (MyPlugin). The bundle contains Swift and Objective-C code and is loaded successfully before the following command is executed:
let aClass = NSClassFromString("MyPlugin.BackendAPIManager") as! BackendAPIManager.Type
When the test tries to execute the line, I get the following runtime error:
dyld: lazy symbol binding failed: Symbol not found: __TMaC16MyPlugin17BackendAPIManager
When changing the line to
let aClass = NSClassFromString("MyPlugin.BackendAPIManager") as! NSObject.Type
I can use
let apiURL = aClass.perform(#selector(BackendAPIManager.apiUrl(path:)), with: "/something")
which means that the class is correctly loaded through the bundle, but somehow I cannot access the class through its name. The corresponding symbol is not found and I have no clue what could cause this. Any ideas?

Accessing SBElementArray content from Scripting-Bridge in swift

I've been trying to use, in a swift code, the various SBElementArray generators defined in the iTunes.h ScriptingBridge header, for example:
List of playlists: (SBElementArray<iTunesPlaylist *> *) playlists;
List of artworks associated to a track: (SBElementArray<iTunesArtwork *> *) artworks;
But when i try to use a method associated to the type contained in those array:
let playlists: SBElementArray = iTunes.playlists()
if let playlist = playlists[0] as? iTunesPlaylist {
print(playlist.name)
}
I get a compile error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_iTunesPlaylist", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This seems to be limited to the SBElementArray as I have no problem accessing current track name with the following :
let track: iTunesTrack = iTunes.currentTrack;
print(track.name)
I'm also guessing that it has something to do with the type casting I'm trying to do from 'anyObject' to 'iTunesPlaylist' in my code (which i think i need to be bale to access the playlist content or whatever artwork i would like to display), because the following code:
let playlists: SBElementArray = iTunes.playlists()
print(playlists[0])
print(type(of: playlists[0]))
corectly returns:
<ITunesPlaylist #0x6080000402d0: ITunesPlaylist 0 of application "iTunes" (93931)>
ITunesPlaylist
The downcasting is trying to create an optional and initialize an iTunesPlaylist that is not allowed and not present in the linker. Force it as you always know it to be a iTunesPlaylist or check the type.
if playlists.count > 0 {
let playlist : = playlists[0]
if playlist is iTunesPlaylist {
print(playlist.name)
}
}

HTHorizontalSelectionList unexpectedly found nil while unwrapping an Optional value

..and I'll tell you why:
I'm using the following pod: HTHorizontalSelectionList
If I declare it like this:
class RightViewController: UIViewController, HTHorizontalSelectionListDelegate, HTHorizontalSelectionListDataSource {
var selectionList: HTHorizontalSelectionList!
}
I get the following error on compilation:
ld: warning: directory not found for option '-FTest'
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_HTHorizontalSelectionList", referenced from:
__TMaCSo25HTHorizontalSelectionList in RightViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Huh!? What!?
If I instead implement it like this it compiles fine!
override func viewDidLoad() {
super.viewDidLoad()
var selectionList: HTHorizontalSelectionList!
selectionList?.frame = CGRectMake(0, 0, self.view.frame.size.width, 40)
selectionList?.delegate = self
selectionList?.dataSource = self
self.view.addSubview(selectionList)
}
...except of course, I get an error on the addSubview line:
fatal error: unexpectedly found nil while unwrapping an Optional value
I'm finding it incredibly difficult to understand how Swift works when I get stuff like this happening quite often.
I'm finding it incredibly difficult to understand how Swift works when I get stuff like this happening quite often
There is nothing difficult about this. You are starting out with your Optional variable set to nil. It stays nil. Eventually you try to unwrap nil and then you crash, because you can't do that:
var selectionList: HTHorizontalSelectionList! // it is nil
selectionList?.frame = CGRectMake(0, 0, self.view.frame.size.width, 40) // still nil, nothing happens
selectionList?.delegate = self // still nil, nothing happens
selectionList?.dataSource = self // still nil, nothing happens
self.view.addSubview(selectionList) // unwrap, crash
If you don't want to crash, assign selectionList an actual value other than nil, like maybe an actual HTHorizontalSelectionList.

LLDB swift print object

Im a little dumfounded with how to use LLDB to inspect an object in a swift project. In this particular case I'm using NSJSONSerializer to serialize a small chunk of JSON and I'd like to inspect the value. In Xcode 5.1 this was super simple, just type "po json" at the lldb prompt and I'd get what I wanted. Now the commands po and print fail me by printing out mostly garbage. I even tried calling the description property because that works with some swift types but that still doesn't work. As a last resort I used an expression with a println statement and finally that works. Surely there must be a better simpler way? Here is the output of LLDB:
(lldb) print json
(AnyObject?) $R4 = (instance_type = Builtin.RawPointer = 0x00007ff05c0c49d0 -> 0x0000000107ef32c8 (void *)0x0000000107ef32f0: __NSCFDictionary)
(lldb) po json
(instance_type = Builtin.RawPointer = 0x00007ff05c0c49d0 -> 0x0000000107ef32c8 (void *)0x0000000107ef32f0: __NSCFDictionary)
{
instance_type = 0x00007ff05c0c49d0 -> 0x0000000107ef32c8 (void *)0x0000000107ef32f0: __NSCFDictionary
}
(lldb) print json.description?
error: <EXPR>:1:1: error: 'Optional<AnyObject>' does not have a member named 'description'
json.description?
^ ~~~~~~~~~~~
(lldb) po json.description?
error: <EXPR>:1:1: error: 'Optional<AnyObject>' does not have a member named 'description'
json.description?
^ ~~~~~~~~~~~
(lldb) expression
Enter expressions, then terminate with an empty line to evaluate:
1 println(json)
2
Optional({
errors = {
"authorizations.provider_user_id" = (
"has already been taken"
);
};
})
(lldb)
you could try
(lldb) expr -O -d run -- json!
The fact that "po" does not exactly work in the same way it does in ObjC is a known limitation. Explicitly unwrapping the optional, and allowing dynamic type resolution on the unwrapped value should work

iPhone - isKindOfClass generates a linker error

I have a class defined like this :
#interface ServerCall : NSObject {
// vars
}
// properties
// functions (init)
#end
and
#interface ServerNotification : ServerCall {
// just vars
}
#end
I have a call in another class :
if ([call isKindOfClass:[ServerNotification class]])
// do things
When building I have this error :
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ServerNotification", referenced from:
objc-class-ref in ServerCommunication.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
"_OBJC_CLASS_$_ServerNotification", referenced from:
objc-class-ref in ServerCommunication.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
I also have in build settings "Symbols hidden by default" = NO
What did I miss ?
The linker doesn't find implementations for your ServerNotification class. Do you have the matching implementation file added to your target?