Apple开发_NSString 使用 strong 与 copy 进行修饰的区别

发布时间 2023-11-14 10:46:44作者: CH520
  • 测试代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    NSMutableString *m_notiion = [[NSMutableString alloc] init];
    m_notiion.string = @"房号密码的功能";
    self.m_notiion = m_notiion;
    [m_notiion appendString:@"加点文字"];

    CHLog(@"UIApplication == %@", self.m_notiion);
}
  • 使用 strong 修饰

    @interface GC_AppDelegate ()
    
    @property(nonatomic, strong) NSString *m_notiion;
    
    @end
    
    • 结果
  • 使用 copy 修饰

    @interface GC_AppDelegate ()
    
    @property(nonatomic, copy) NSString *m_notiion;
    
    @end
    
    • 结果