简体   繁体   中英

Xcode Class name in iOS without application name prefix

I'm trying to load UIView from xib with this code

NSString *className = NSStringFromClass([self class]);
_customView = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];

In another project it works fine, but in my new project className returns "myapp.MyClassName" . I don't know why it adds application name "myapp." prefix before class name. I don't have nib named "myapp.MyClassName.xib" so application crashes with

Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/XXXX-XXXX/myapp.app> (loaded)' with name 'myapp.MyClassName''

I have:

  • CustomXibUIView class (Objective C) that initialize _customView
  • MyClassName class (Swift) that inherits CustomXibUIView (for initializer)
  • MyClassName.xib

I'm using XCode6-Beta5, iOS SDK 8.0 , deployment target iOS7+

How can I get clear class name without prefix?

This worked for me.

class var getClassFullName: String { return NSStringFromClass(self)   }

class var getClassName: String {
  return (getClassFullName as NSString).pathExtension
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM