Heres是我得到的错误.
libobjc.A.dylib`_objc_trap():
0x14c13f4: pushl %ebp
0x14c13f5: movl %esp, %ebp
0x14c13f7: ud2
Run Code Online (Sandbox Code Playgroud)
所以基本上我试图理解如何NSString工作并试图找到一种方法来改变指向"真(char*)字符串"的指针,这被称为常量.
所以,我发现有一个名为isa的指针指向(__NSCFConstantString *).它让我想到,如果我改变那个指针,那么我可以改变字符串.
我试过的代码是这样的:
NSString *st3 = [[NSString alloc] initWithString:@"hihi"];
[st3 setValue:@"change" forKey:@"isa"];
Run Code Online (Sandbox Code Playgroud)
并且,结果表明
之前:

后:

它似乎改变了,但它改变了每个NSString具有@"hihi"字符串的对象.
然后我做的是[st3 class]希望它会给出isa指针然后我在顶部发布了错误消息.
你能解释一下发生了什么以及为什么会这样吗?而且,有没有办法实习(我不太确定这个术语)就像在Java中一样?
请避免说只使用"NSMutableString"我只是想弄清楚是否可能有某种方法可以做到这一点.
我一直在以同步和异步的方式研究很多多线程,回调,调度队列...我研究的越多,我就越感到困惑和沮丧,我觉得我似乎无法理解它..请有人可以引导我向正确的方向开始..到目前为止我发现的大部分信息都是关于什么是有用的和有利的东西..我真正希望知道的是当函数与回调异步时该函数如何立即返回并在一个线程上.[这里]的(http://nathansjslessons.appspot.com/lesson?id=1085)我从中得到了这些信息
The function **returns immediately** before the file is read and schedules the read to happen
sometime in the future. Once the data is ready, the callback function is called on the
data.
Run Code Online (Sandbox Code Playgroud)
下面是一个如何使用常规阻塞读取函数来获取文件内容的示例 var readFile = function(){
var data;
data = read('file.txt');
dosomething('contect' + data);
}
Run Code Online (Sandbox Code Playgroud)
这是使用异步readAsync函数的相同示例.
var readFileAsynch = function () {
var func = function (x) {
// i can do something with data
dosomthing('content'+data);
}
**readAsynch('file.txt',func);**
dosomemorestuff();
};
Run Code Online (Sandbox Code Playgroud)
从我所知道的是,如果你使用另一个线程而不是主线程比我认为这是异步的方式那么如果你只有一个 …
javascript multithreading operating-system asynchronous objective-c-blocks
我仍然在努力解决@implementation部分中的语法错误.
所以,我想了解使用@property与否之间的区别.
第一种情况是一个@interface,我在{}中声明了一些变量.
//ViewController.h
#import <UIKit/UIKit.h>
#import "Student.h" // just class i made
@interface ViewController : UIViewController
{
Student *stObj;
}
Run Code Online (Sandbox Code Playgroud)
而且,我正在尝试使用几个标识符(_(下划线),self.,self->,没有)引用stObj指针
// ViewController.m
#import "ViewController.h"
@interface ViewController () // just leaving this code cuz i haven't study what it is :)
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
stObj = [[Student alloc]init ]; //no error
//self->stObj = [[Student alloc]init]; //no error
//self.stObj = [[Student alloc]init]; //error!
//_stObj = [[Student alloc]init]; //error!
}
Run Code Online (Sandbox Code Playgroud)
第二种情况是@interface,我使用@property
@interface ViewController : …Run Code Online (Sandbox Code Playgroud) 我的代码相当简单,只是输出彼此不同.而且,我想知道为什么结果显示如下..
#!/bin/bash
fileList=`ls`
echo $fileList # without doubleQuote
Run Code Online (Sandbox Code Playgroud)
输出:
f1 f2 f3
Run Code Online (Sandbox Code Playgroud)
#!/bin/bash
fileList=`ls`
echo "$fileList" # with doubleQuote
Run Code Online (Sandbox Code Playgroud)
输出:
f1
f2
f3
Run Code Online (Sandbox Code Playgroud)