Instance variables not available in sub-classes..? - iphone

I've tried removing cache, clean all targets, etc.
Instance variables from my super class are getting highlighted green according to my color scheme, but the compiler then fails saying
"score" (or whatever) undeclared"
If I have two references in one method, only the first one fails. If I leave them out, or use instance variables from my subclasses header, the app compiles and runs fine.
It was working literally just 2 days ago. I wonder if I accidentally hit a shortcut that turned on some weird setting?
It's running in the 3.2 iPad simulator, if that matters.
It's a weird one.. hope someone has run into this before.

Sounds like your instance variables are declared as #private. This means that only that exact class can access them. If you want subclasses to access the ivars directly put #protected above them, eg
#protected
id myiVar;
NSString *myStringIVar;

Related

Two Frameworks use the name for a property

SwifterSwift has a property name cornerRadius.
It's an extension to UIView.
While the DropDown framework has a property name cornerRadius.
DropDown (the class) is a subclass of UIView.
It seems like xCode doesn't know which property I'm referring to.
I only imported one framework to my file but SwifterSwift's extension still takes effect.
I modified the DropDown framework and everything worked fine but then I reverted because it's not allowed and I wouldn't know how to debug any future problems.
I also tried creating a function in an extension to somehow get around this problem.
It turns out that I can't directly access DropDown's table (which is the view that we round).
I cant remove the SwifterSwift framework because it has already been used in the project that I'm working on. Although that might be the best option.
Is there a solution to this problem ?
In Swift, namespaces are implicit and belong to target it is defined. So, for your case, the workaround would be to add the target name in the property call.
SwifterSwift.cornerRadius
DropDown.cornerRadius
Let take example of String. It belongs to Swift target and so I can do this
let str = Swift.String("abc".characters)
Please follow the steps in this issue
Or upvote for adding prefix to all SwifterSwift extensions here

Unknown class in Interface Builder file

Why am I still getting this error when I run my iPhone app? The file is a ViewController that I have been working to delete and replace, but it just won't die. As far as I know, I don't have any reference (string or otherwise) to this file in my project.
I have deleted the related file (I'm trying to get rid of it.)
I have cleaned the project and rebuilt.
I have "Reset Content and Settings" in my simulator.
I have done a grep (grep -i -r "TheClassName" *) and nothing matches except my UserInterfaceState.xcuserstate file.
I have searched the code using XCode's Find/Replace tab.
I have double checked my Build Phases and am pretty sure it isn't in there (its a large project).
Any other ideas? I've spent way too many hours trying to figure this simple thing out; I must be missing something.
Thanks!
Check your nibs or storyboard, and make sure none of your views are set to the class!
I finally fixed the problem after trying it on multiple machines over the course of almost 2 days! I will not be thwarted!
I tracked the problem down to a call to setViewControllers on a UINavigationController which is called on initialization of the application. I was always being passed 3 objects (there are 3 panes in the navigation controller). Even though I had deleted the third object, as previously explained, three objects would always be passed in. The class type of the first two was correct, but the third would just be a UIViewController. Curiously, this view controller had a nibName which corresponded to the object file and Xib file that I had previously deleted. Of course, when view was called on this borked UIViewController, it would crash since the corresponding nib had obviously been deleted. Remember, the textual name of this object or Xib could not be found in my directory with grep, so I have absolutely no idea how in the world it came into existence when I ran my app.
So, I figured the app may not have been cleaned properly. I double and triple checked this. I even validated that my Workspace settings were correct (File->Project Settings->Advanced). The app was indeed being recompiled fresh every time.
Secondly, I started thinking that perhaps the object was being set by some other means. Working backwards, I added some breakpoints and found out that initWithCoder was being called on the parent UINavigationController--this was eventually working down to call the setViewControllers on the object and assigning the three view controllers (one of which was the offending one). I could easily see from the call stack that the Nib file that was being loaded was deserializing something offensive.
So, I started digging into my Xib file. Of course, the object name wasn't in the file (as expected since the grep didn't find anything). I deleted and recreated the portion of the Xib that included my root UINavigationController. This ended up changing the Object ID and ref within the Xib file.
Secondly, I created a new Xib and UIViewController with the same names as the one which I had previously deleted, hoping that Xcode might be happy if I created and then re-deleted them. I then compiled, re-deleted them, updated by Xib file yet again, reverified with grep that yes, indeed, nothing existed with that name.
And it worked. After spending multiple days on this issues, I'm fairly sure that there is a bug here in the interface builder, but do I want to revisit this problem to file a bug report? Absolutely not...
In my case, I solved an issue by name of Custom class name of View instead of Custom class of ViewController. By mistake i added like this for view as shown below.
It Should be for ViewController like this.
This is in my case, for you may be it's related with another component.
This happens when the view class is in a framework. Select the framework's module. Example with a CocoaPod: HSegmentControl.
Make sure when you add or rename or move files around especially in folders, that when you add them you:
A. Create Groups, not references they don't usually read in.
B. Check the boxes for the apporpriate "Product(s) or Target(s)" you want to add the source to.
Another thing to try :
I had to toggle "Inherit from Target" under the "Module" control of "Custom Class."

iOS key logger implementation

I want to understand how to implement a key logger for iOS. And how can I avoid logging keys in my application, if there is iKeyMonitor (for example) installed on device?
After research I found that ikeyMonitor installs the following files on the device:
Library/Caches/.keycache
Library/MobileSubstrate/DynamicLibraries/MobileSafe.dylib
Library/MobileSubstrate/DynamicLibraries/MobileSafe.plist
Library/MobileSubstrate/DynamicLibraries/keychain.dylib
Library/MobileSubstrate/DynamicLibraries/keychain.plist
Of course it requires MobileSubstrate.
In keycache there are some HTML files that I can open in Safari with the URL localhost:8888.
In the plists there is only com.apple.springboard filter, it means that MobileSafe.dylib (and all hooks) will be applied only on
springboard app.
Even if I don't use the default keyboard view in my app for editing a UITextField, the keylogger still works. This means that Hooks are applied on UITextField.
After using class-dump for SpringBoard.app I didn't find any methods that can be related in UITextField's implementation. After using class-dump for MobileSafe.dylib I didn't find any implementation that can be substituted for UITextField either (maybe because it written on C), I think that I should analyze MobileSafe.dylib dynamically with gdb
How can the SpringBoard (that is in plist com.apple.springboard) app have an effect on UITextField class implementation? If I use method swizzling for UITextField in the dylib for com.apple.springboard will it work in other applications too?
What is the general difference between MobileLoader and MobileHooker? At what moment will changes from MobileHooker will be applied to my system?
What should I do to hook a method from UIKit (for example UITextField methods), and change its implementation for all apps on my device?
What method for analyzing iKeyMonitor can you advise me to use?
if it uses springboard in the filter then it can only affect the springboard, to hook all applications you use UIKit as the filter(more on that in 3)
My understanding of the two is that:
MobileLoader loads your code into the running application and when this happens, functions with the constructor attribute "__attribute__((constructor))" are called. In one of these constructors, MobileHooker functions are called to replace pre-existing functions/methods in the application. As for when the changes are applied, since they are changed in constructors they should be changed before any of them are actually called.
You simply use the com.apple.UIKit filter(which btw is what the keychain.dylib in iKeyMonitor uses)
class-dump does not show the hooked classes and methods of a tweak because they are not objective-c methods, instead they are functions...
The best option would be a disassembler like ida hex-rays.com/products/ida/index.shtml

Console won't print, only "...unrecognized selector sent to instance 0x####XX0" Runtime Errors

I'm working on an iPhone app (first real programming project) and I had two views that would go into tabs in separate applications to build them, where they work fine. Then I added them back into the main project; The tableviews bring on a crash with an numberOfRowsInSection] unrecognized selector sent to instance 0xXXXXXX so I isolated the other view to fix any errors there first. I'm using xibs.
But on the other view, when I click a Button that triggers a custom method, I get an *** -[UIViewController methodName]: unrecognized selector sent to instance 0x####XX0 just like the last one.
What also puzzles me is that the console won't print anything else except these errors; I have NSLogs() all over the place and they're not showing up, even in the appDelegate. They do however show up when they're in the main. (Because of the application life-cycle right?: then the error gets there first and I don't see my NSLogs)
The unrecognized selector messages are logged because of methods. I have all my synthesize statements and have searched questions here, but they're not like mine (I think.)
When you say you added the XIB files "back into the main project" it makes me think this is the likely area of concern.
I think it may be the case that these XIB files are still thinking they are classes in the old application (where you originally built them). I suggest:
Opening up each XIB file and removing all the connections
Then check the class name of the "file's owner" and check that this is the class in your new application. If the class names are the same in the old app as the new, change to something else and then back again.
Hopefully this will sort it. If it doesn't, try creating a brand new XIB file and then building it in the same way as you built the others. If this still doesn't work the problem is in the class; if you let us know then we can come back with further ideas in this area.
Hope that helps!
I've since removed the second view from it's xib and instead put it in the main xib, with an added UIViewController object that has it's class set to my subclass. Now it's working, and I'm moving on to the next part. I think it was that I left out UIViewController in one way or another from the xibs
As stated above, almost everything being worked out now. Thanks though and silly me for posting such a question.

Debugging UIViews missing subviews member in variable list of debugger

While searching a bug in my code today I found a strange thing. When inspecting a UIView instance in the debugger the variable view of Xcode does not show the subviews member of the UIView class.
I only see this fields in the debugger (> should indicate the opening triangle):
UIResponder
_layer
_tabInfo
_gestureInfo
_touchData
_charge
_tag
_viewFlags
I'm missing the _subviews member and come to think of it also all the positional members (at least one of them should be there).
Does anybody know what I'm missing or doing wrong (as far as I can tell it is not a problem as a google search for this problem didn't got me any results).
I use Xcode version 3.1.3 with:
XcodeIDE: 1191.0
XcodeCore: 1192.0
XcodeSupport: 1186.0
on a mac with OS 10.5.7 and iPhone SDK 2.2.1 (I also tested with iPhone SDK 3.0).
I hope somebody knows anything about this. It gives me a little strange feeling that I cannot trust the debugger to show me everything I should know for debugging a problem. And it's not good if you need to mistrust you tools :(
The debugger is only going to be able to show you members, not properties. Remember that the two are different in Objective C. A property is just syntactic sugar for a setter and/or a getter. So the read-only "subviews" property of UIView only guarantees that it has an implementation for this method:
- (NSArray *)subviews;
As you've noticed, Apple has implemented many of their properties using undocumented member variables that resemble their corresponding property names, but with leading underscores. This allows you to spy on the internals of some objects to see what's going on in some cases, but many properties aren't implemented in such a transparent manner. In these cases, you'll need to inject some diagnostic code into your app to access the property and output its return value using NSLog, and/or store the value in a temporary variable that you can observe in your debugger.
Don't blame the poor debugger. It's doing exactly what it's designed to do. If it helps, you can blame properties for trying to trick us into thinking they're member variables when they're really methods.